select
is a POSIX syscall which allows you to wait on several different filedescriptors (including sockets) for the event that they won’t block on write; won’t block or read or are in error. This syscall is very convenient when you’re writing a server.
When I want to shutdown an instance of the server, I have to interrupt the select
. I have yet to find a satisfying way of doing this. At the moment I create a pair of linked sockets with socketpair
. I include one of them to the sockets on which to block until there is data to read in the select
call. To interrupt, I simply write some data to the other socket which will cause data to be available on the socket which in turn will interrupt the select
.
There must be a more elegant solution.
The good book, aka select(2), says:
[EINTR] A signal was delivered before the time limit expired
and before any of the selected events occurred.
Did you try sending SIGALRM to yourself? (didn’t test it)
Forgot to mention it’s concerning Python. Python has got a select module which obviously works on unices and on Windows for sockets. Windows doesn’t really seem to do signals. [ On unices, however, using signals will work briliantly ]