0

I have a UDP socket server application.I am running a worker thread to receive data from Client and send reply.

Inside worker thread I am using Select() to check whether any data arrives and the timeout for the select() function is 12 milliseconds.When closing the worker thread, the select() function is not returning immediately, after the timeout only it returns.

How to stop select() immediately when terminating the worker thread?

I need to implement this in Windows.

user369287
  • 692
  • 8
  • 28
  • there are a couple of ways. A common idiom is to wait on a socket plus a pipe. You can send control events to the pipe. another is simply to shutdown/close the socket, causing select to detect an error condition. http://stackoverflow.com/questions/2486335/wake-up-thread-blocked-on-accept-call – Richard Hodges Aug 23 '16 at 10:07
  • Here is another related post: [How do I wake select() on a socket close?](http://stackoverflow.com/q/1329453/514235). I would recommend you to enroll n + 1 sockets for a given `select()` statement. "n" ( = 1 or more) as main sockets and the other "1" as a dummy socket for this exit purpose. Whenever, you want to wake up the `select()`, simply post some dummy data on this dummy socket. The `select()` will wake up and using socket FDs, you will find that the data was posted on the dummy socket. That's a good indication for you that the `select()` thing has to wind up. – iammilind Aug 23 '16 at 10:08

0 Answers0