The basic code sequence I’m interesting for is (pseudocode)
sendto(some host); // host may be unreachable for now which is normal
...
if(select(readfs, timeout)) // there are some data to read
recvfrom();
Since Win2000, ICMP packet, which is sent back after sending UDP datagram to unreachable port, triggers select, after that recvfrom fails with WSAECONNRESET. Such behaviour isn’t desirable for me, because I want select to finish with timeout in this case (there are no data to read). On Windows this can be solved with WSAIoctl SIO_UDP_CONNRESET ( http://support.microsoft.com/kb/263823 ).
My questions are:
- Is SIO_UDP_CONNRESET the best way in this situation?
- Are there some other methods to ignore ICMP for “select” or to filter it for recvfrom (maybe, ignoring WSAECONNRESET error on Windows treating it like timeout, can this error be triggered in some other case)?
- Are there similar issues on Linux and Unix (Solaris, OpenBSD)?
select()‘sreadfdsset really just reports that aread()on the socket won’t block — it doesn’t promise anything about whether or not there is actual data available to read.I don’t know what specifically you’re trying to accomplish with the two-second timeout rather than just sleeping forever — nor why you can’t just add an
ifblock to check forWSAECONNRESETfromrecvfrom()— but it feels like you’ve got an overly-complicated design if it doesn’t handle this case well.The
select_tut(2)manpage on many Linux systems has some guidelines for properly usingselect(). Here’s several rules that seem most apropos to your situation: