On Thursday, 7 May 2015 at 16:15:29 UTC, Dmitri wrote:
My questions are,
  * is it legit to want to terminate not from the main thread?
  * if not, what is the recommended simpler way of doing it?

Not the simplest, but I think the best way for an event-driven network application to exit is, upon receiving SIGTERM, to close its listening sockets and long-lived connections, allowing the event loop to exit naturally as it runs out of event sources to listen on.

Since the signal may be received by an arbitrary thread, you may need to notify the event loop thread. How you do this depends on your event loop, but a simple way is to write to one end of a socket pair. As an example, I have this approach implemented here:

https://github.com/CyberShadow/ae/blob/master/net/shutdown.d

Reply via email to