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.