-
June 25th, 2009, 03:08 PM
#1
Elegant shutdown of server when signal is received
Hi all,
I have built a TCP server which i need to shutdown nicely when some signals are received. My problem is this:
As a first approach i though of setting a global variable which would then cause the server to exit. But most of the times the server is blocked in the accept() call when the signal arrives so it is needed for one additional client to connect in order for the close to take effect. So now i throw an exception from the signal handler which is then causing the server to shutdown. Using exceptions however from within a signal handler is strongly discouraged as it may cause undefined behavior. Is there some more elegant solution for shutting down the server?
Thanks in advance,
verbal
-
June 25th, 2009, 09:26 PM
#2
Re: Elegant shutdown of server when signal is received
Call select() on the listening socket (read set). Then you can specify a timeout so that you can check for other conditions periodically - like time to quit.
gg
-
June 26th, 2009, 12:52 PM
#3
Re: Elegant shutdown of server when signal is received
or close the listening socket and accept() should return an error.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|