select on UDP socket doesn't end when socket is closed - what am I doing wrong? select on UDP socket doesn't end when socket is closed - what am I doing wrong? unix unix

select on UDP socket doesn't end when socket is closed - what am I doing wrong?


UDP is a connectionless protocol. Since there is no connection, none can be broken, so the consumer doesn't know that the producer will never send again.

You could make the producer send an "end of stream" message, and have the consumer terminate upon receiving it.


Maybe you should use something else to wake up the select. Maybe a pipe or something like that.


Could you not send a signal (e.g. USR2) to the thread which would cause select() to return with EINTR?Then in the signal handler set a flag telling it not to restart the select()?

That would remove the need for waiting on multiple file descriptors, and seems a lot cleaner than using a pipe to kill it.