Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Socket closed notification?
From: Scott Gifford (sgifford_at_[hidden])
Date: 2009-12-15 12:25:59


Jonathan Franklin <franklin.jonathan_at_[hidden]> writes:

[...]

>> At the very least, this is a technique I have consistently seen
>> recommended, and has always worked for me.
>
> The only reliable way to detect the remote host dropping off, is to
> attempt a read. This is the consistent recommendation by socket
> programming experts. Please refer to _Effective TCP/IP Programming_,
> Tip 19; and Stevens.

Sure, I agree completely that attempting a read is necessary, but IME
it is not sufficient. You must additionally send data, either with an
OS write or TCP keepalive, to detect a completely unresponsive peer
(i.e. one which has fallen off the network). The only way to detect
an unresponsive peer is via a timeout, and with no data to send, there
is nothing to time out.

I also agree that write() won't always return an error, but it should
attempt to send data, which will cause the TCP layer to wait for an
acknowledgement of that data. If that times out, the TCP layer should
detect an error on the socket, and a subsequent call to read() should
return an error.

----Scott.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net