Home » U++ Library support » U++ MT-multithreading and servers » How to break the server loop ?
Re: How to break the server loop ? [message #44655 is a reply to message #44654] |
Wed, 06 May 2015 20:15   |
|
Hi akabee
akebee wrote on Wed, 06 May 2015 14:25 for(;;) {
TcpSocket s;
if(s.Accept(server)) {
}
In the server loop, the s.Accept will blocked the thread, So how to exit thread when program-quit ?
On POSIX systems, the easiest way is probably using signals. You can terminate your program by calling kill(pid, signal). Everything your server is doing, including Accept will be interupted. If you need to perform clean-up tasks etc. on shutdown, you can install signal-handler function, that will be called. To register the handler, signal(sig, function) is used.
You can look at Skylark package, how it is done there. The kill function is called here, The signal handler is installed just a few lines below.
Alternatively, you can use non-blocking Accept(), if I am not mistaken, it should be enough to just call TcpSocket::Timeout(0). I never used it personally, so you should probably check the documentation first, there are some additional hints 
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Mon May 12 06:10:50 CEST 2025
Total time taken to generate the page: 0.03236 seconds
|