1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Interpreting return code of recv() socket api

Discussion in 'C++' started by yaniv135, Aug 4, 2012.

  1. yaniv135

    yaniv135 New Member

    Aug 4, 2012
    Likes Received:
    Trophy Points:

    I have a situation where client waits on recv() on a socket in one thread. And , I am monitoring the same socket for timeout on another thread. When the timeout occurs , the second thread drops the socket.
    As a result the first thread waiting on recv() gets a return code 0 (no bytes received ) with no error number set.
    Now there is another case where recv() at client returns with 0 before the timeout , which is , when there is an issue with the server and it terminates the connection without sending any data.

    Is the above behaviour of recv() in both cases correct ? If yes , is there a way at the client to differentiate between the two cases ? In both cases recv() returns with 0 and no error number.

    Please let me know.

Share This Page