Alex
Alex

Reputation: 99

How to interrupt select call on windows?

I know it's probably a basic question, but I'd like to hear the best way to realize it.

So to the problem. I have a driver thread using a call to select, and I have a GUI thread that needs sometimes to interrupt select by writing to some file descriptor within the same process (GUI FD or something). I used pipe in UNIX, but I'm not experienced in sockets for Windows, so I'm not sure what kind of FD I should use. Example is greatly appreciated but not required ).

Thanks.

Upvotes: 4

Views: 1717

Answers (2)

Adrien Plisson
Adrien Plisson

Reputation: 23293

select() is not the best to implement asynchronous I/O under Windows. unfortunately, the select() call on windows only works with socket handles and not with pipe or fie handles.

you should have a look at overlapped I/O.

by using an event in your overlapped structure, you can have a behaviour close to select(). any event on a socket will trigger an event, which you can wait on by using WaitForMultipleObjects(). now, your GUI thread can signal the I/O thread by setting a specific (separate) event, which you create using the CreateEvent() call.

Upvotes: 2

Goz
Goz

Reputation: 62323

You could set the timeout shorter on the select and then loop round if it was a timeout. Or you could send a simple packet to the socket being selected causing it to wake up.

Upvotes: 0

Related Questions