Reputation: 771
I have a listening thread that waiting for reading on few socket using select and FD_SET. The story is. At some point I will add another socket to the pool and need to abort select and re-initialize FD_SET array fo select. I have an Event to signal pool changes. But how select can react to my Event? select() at this point of time use timeval with waiting interval of 20 sec and I don't want to changed time to lower value. I don't want frequently re-start select() by timeout...
Is there any way to abort select? What would be the right approach to inform/restart select and force using of new list of socket(at least one socket will be added to pool)
And another question - Msdn says "The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O." Does that mean that select is not designed to work with sockets that turned to use using async operation?
Upvotes: 1
Views: 1530
Reputation: 596287
Use WSAEventSelect()
and WSAWaitForMultipleEvents()
instead of select()
. That way, your pool can create a separate event with WSACreateEvent()
and signal it with WSASetEvent()
to wake up WSAWaitForMultipleEvents()
when needed.
Upvotes: 5
Reputation: 73081
If you want select() to wake up, the easiest way is to send a byte to one of the sockets that select() is waiting on for read access. One way to implement that without affecting functionality of the existing sockets is to create a pair of sockets specifically for that purpose and connect() one to the other.
Upvotes: 0