C++ – select(), recv() and EWOULDBLOCK on non-blocking sockets

csockets

I would like to know if the following scenario is real?!

  1. select() (RD) on non-blocking TCP socket says that the socket is ready
  2. following recv() would return EWOULDBLOCK despite the call to select()

Best Answer

For recv() you would get EAGAIN rather than EWOULDBLOCK, and yes it is possible. Since you have just checked with select() then one of two things happened:

  • Something else (another thread) has drained the input buffer between select() and recv().
  • A receive timeout was set on the socket and it expired without data being received.