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

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.

It's possible, but only in a situation where you have multiple threads/processes trying to read from the same socket.

Tags:

C++

C

Sockets