Does recv(...) operate this way?

Viewed 411

I'm setting a timeout for the socket using SO_RCVTIMEO to 10 seconds. This question is specific to a stream socket (TCP). When I call recv(...) from what I can gather from the man pages, here is what I'm expecting:

  1. If remote closes the connection, it returns 0 immediately regardless of the timeout.
  2. If the timeout expires and no data was received, then we get a -1 returned and an errno of EAGAIN or EWOULDBLOCK.
  3. If an error occurs on the socket, it returns immediately with a -1 and then errno is set properly.
  4. If data becomes available, the socket waits until the timeout occurs before returning. This time it'll return in 10 seconds with the total bytes received.

Is this the correct behavior? I just want to make sure I'm properly understanding the docs.

Thanks! Brett

2 Answers
Related