You can synchronously interrogate any timeout in the socket. If Poll()
returns true
, you can be sure that you can make a Receive()
call that will not block.
Socket s; // ... // Poll the socket for reception with a 10 ms timeout. if (s.Poll(10000, SelectMode.SelectRead)) { s.Receive(); // This call will not block } else { // Timed out }
I recommend that you read Chapters 6 and 16 of Stevens' UNIX Network Programming for more information on non-blocking socket usage. Although the book has UNIX in its title, the general socket architecture is essentially the same on UNIX and Windows (and .net)
source share