Git Product home page Git Product logo

Comments (7)

zieckey avatar zieckey commented on July 17, 2024

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.

zieckey avatar zieckey commented on July 17, 2024

Any updates?

from evpp.

jvalenciag avatar jvalenciag commented on July 17, 2024

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.

zieckey avatar zieckey commented on July 17, 2024

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.

jvalenciag avatar jvalenciag commented on July 17, 2024

So Stop has to be called inside the loop with a RunAfter necessarily?

from evpp.

zieckey avatar zieckey commented on July 17, 2024

No, that's not necessary. You can read more examples.

  1. 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
  2. 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.

jvalenciag avatar jvalenciag commented on July 17, 2024

Thank you for the help.

from evpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.