Search code examples
timeoutblockingrecv

When is recv() method returning 0?


Could someone explain when is recv() method returning 0? Of course buffer longer than 0 bytes is provided. Method is blocking, so it should wait until it recieves something or throw an error and return -1. I have flag - 0 set. It is not indicating non-blocking mode.


Solution

  • MSDN recv Function:

    ... If the connection has been gracefully closed, the return value is zero.

    recv(2) - Linux man page:

    ... The return value will be 0 when the peer has performed an orderly shutdown.