CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2007
    Posts
    36

    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

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    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

  3. #3
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    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
  •  





Click Here to Expand Forum to Full Width

Featured