Comments (7)
Thank you for using evpp
.
Please paste the sample code that can produce the your problem.
And we suggest that you can read the unit test code testTCPServerSilenceShutdown
at here https://github.com/Qihoo360/evpp/blob/master/test/tcp_server_test.cc#L72-L82. This tests the TCPServer
to stop silently.
from evpp.
Any updates?
from evpp.
I was trying to stop the server when SIGINT or SIGTERM were recieved with the next function.
evpp::EventLoop* loop;
evpp::TCPServer* server_ptr;
static void s_signal_handler(int signal_value) {
loop->Stop(); //using only this: error on server destructor
server_ptr->Stop(); //using only this: program hangs
}
Finally I arrived to a solution by calling Stop in both loop and server in that order.
In the test unit the Reset method is called in both loop and server to stop, what is the difference between Stop and Reset? I guess Reset makes possible to reuse the objects, is only that?
from evpp.
We should stop TCPServer and after then, we can stop EventLoop, and lastly we call Reset to release the memory of the objects.
Please try the following code. See https://github.com/Qihoo360/evpp/blob/master/test/tcp_server_test.cc#L87-L97
std::unique_ptr<evpp::EventLoop> loop(new evpp::EventLoop);
std::unique_ptr<evpp::TCPServer> tsrv(new evpp::TCPServer(loop.get(), addr, "tcp_server", 2));
bool rc = tsrv->Init();
rc = tsrv->Start();
loop->RunAfter(evpp::Duration(1.0), [&tsrv, &loop]() { tsrv->Stop(); loop->Stop(); });
loop->Run();
loop.reset();
tsrv.reset();
from evpp.
So Stop has to be called inside the loop with a RunAfter necessarily?
from evpp.
No, that's not necessary. You can read more examples.
- We can stop the EventLoop in it's own thread immediately : https://github.com/Qihoo360/evpp/blob/master/benchmark/post_task/post_task2.cc#L60
- We also can stop the EventLoop in another thread : https://github.com/Qihoo360/evpp/blob/master/benchmark/post_task/post_task6.cc#L59
from evpp.
Thank you for the help.
from evpp.
Related Issues (20)
- Bug in example UDP echo server
- whether evpp::TCPConnPtr is thread safe or not?
- MFC程序下 eventloop直接报错
- 有实现SSL TCP通信的吗
- EventLoop.Run函数底层会创建很多线程嘛 HOT 1
- Evpp failed to build with error LNK1181 on MSVC
- is this project still active? HOT 1
- example_evpphttp_server, server not init HOT 1
- The echo UDP server example does not compile against package installed by vcpkg. HOT 3
- evpp支持同时监听ipv6和ipv4吗?支持的话如何开启?
- Potential memory leak in benchmark/throughput/libevent/client.c
- Potential memory leak in benchmark/throughput/libevent/server.c
- Potential memory leak in benchmark/http/libevent/libevent_http_bench.c
- Potential memory leak in benchmark/throughput/libevent/client.c
- Potential memory leak in benchmark/throughput/libevent/server.c
- Potential memory leak in benchmark/http/libevent/libevent_http_bench.c
- Potential memory leak in apps/evmc/extract_vbucket_conf.cc HOT 1
- Potential memory leak in test/evhttp_client_test.cc HOT 1
- ASan heap-use-after-free in tcpserver tests
- TCPServer 的 thread_num 有什么作用 ? ,为什么要建立多个 EventLoopThreadPool ? 1 和 4 有什么区别吗? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from evpp.