Checking peer connection is lost or not - Unix

This is a discussion on Checking peer connection is lost or not - Unix ; Hi All, I am using a select system call with 15 minutes of time out. If select does not receive data within 15 minutes, I want to check whether peer socket is closed or not. How can I ping the ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Checking peer connection is lost or not

  1. Checking peer connection is lost or not

    Hi All,
    I am using a select system call with 15 minutes of time out. If
    select does not receive data within 15 minutes, I want to check
    whether peer socket is closed or not.

    How can I ping the peer socket?
    I read somewhere that "read" can be used to do the same. If read
    returns -1 it means peer socket is closed but somewhere other I read
    that in that case read could return 0 also. So I am not sure on the
    behavior of the read system call.

    Thanks in advance,
    -Mukesh

    "The finest steel has to go through the hottest fire."


  2. Re: Checking peer connection is lost or not

    On 2007-10-12, Mukesh wrote:
    > I am using a select system call with 15 minutes of time out. If
    > select does not receive data within 15 minutes, I want to check
    > whether peer socket is closed or not.


    Well. If the peer has closed connection, then select will return and no
    time-out shall happen. The "read" in this case shall return 0. If
    time-out has happened, then either the peer didn't send anything, or the
    network connection was lost. In the latter case you may try to send
    something and keep waiting. If the network is still down, then after
    long delay, during which the system tries to deliver your data, you may
    get your socket read ready or exception ready and after appropriate
    operation you'll receive an error. In the last events I'm not sure,
    since I've never specifically checked what happens. I just act on all
    errors and when the timeout has happened then close connection
    (depending on protocol).

    --
    Minds, like parachutes, function best when open

  3. Re: Checking peer connection is lost or not

    On Oct 11, 10:40 pm, Mukesh wrote:
    > Hi All,
    > I am using a select system call with 15 minutes of time out. If
    > select does not receive data within 15 minutes, I want to check
    > whether peer socket is closed or not.
    >
    > How can I ping the peer socket?


    It depends on the protocol. Follow the specification for the protocol
    you are implementing.

    > I read somewhere that "read" can be used to do the same. If read
    > returns -1 it means peer socket is closed but somewhere other I read
    > that in that case read could return 0 also. So I am not sure on the
    > behavior of the read system call.


    The read system call will return 0 if the other end closes the
    connection normally (or you closed the connection normally) and -1 if
    it detects an error. But if you are not sending data, there is no
    guarantee an error will be detected. That's why every protocol that
    uses TCP has to address this issue, and they do so in many different
    ways.

    Follow the protocol.

    DS


+ Reply to Thread