Re: Recv(), determining connection closed or broken

From: Umpa (
Date: 05/18/04

  • Next message: Andrei Voropaev: "Re: Recv(), determining connection closed or broken"
    Date: Tue, 18 May 2004 10:25:12 +0200

    > If your side knows that the other side closed the connection normally,
    > 'recv' will return zero. If your side knows that an error has occured
    > (either locally or on the other side), 'recv' will return '-1' and 'errno'
    > will tell you want happened.
    Here are errnos matched to recv():

    The argument s is an invalid descriptor.

    A remote host refused to allow the network connection
    (typically because it is not running the requested service).

    The socket is associated with a connection-oriented protocol
    and has not been connected (see connect(2) and accept(2)).

    The argument s does not refer to a socket.

    The socket is marked non-blocking and the receive operation would
    block, or a receive timeout had been set and the timeout expired before
    data was received.

    The receive was interrupted by delivery of a signal before any
    data were available.

    The receive buffer pointer(s) point outside the process's address space.

    Invalid argument passed.

    Please, do tell me what errno is set to when connection
    is broken during receiving ? Personally, I can`t see any.

    How about this:


  • Next message: Andrei Voropaev: "Re: Recv(), determining connection closed or broken"

    Relevant Pages

    • Re: closing ASyncSocket
      ... I reread the help for the ShutDown() call. ... not close the socket, and resources attached to the socket will not be freed ... What if I want to Closethe connection to return resources. ... receiving side after I received the last data. ...
    • Re: Handling multiple connections
      ... each time select says the socket has more data. ... All data being sent by clients are prepended with a header that indicates ... received and thus delays receiving on the other readable sockets. ... When the client closes the connection, ...
    • Re: How can I tell when a remote TCP connection is closed?
      ... Recv only returns zero if the peer has ... to write to the socket and I get an broken pipe error. ... >I have a client with a TCP connection to a server. ... >need the code to be portable), is there a way that I can tell if the remote ...
    • Re: Non-blocking sockets
      ... the request and receiving the response. ... but reador recv() returns before any data is read, ... closing a connection ... temporarily unavailable) and not receiving any data. ...
    • Re: RAS connection and Socket status
      ... You don't need a timer to check the current RAS status. ... recv) to ensure that status messages can be processed. ... RasGetConnectStatus to check it during the connection process ...