Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Detecting tcp peer disconnection
From: Jonathan Franklin (franklin.jonathan_at_[hidden])
Date: 2010-01-28 11:17:12


On Thu, Jan 28, 2010 at 8:30 AM, Igor R <boost.lists_at_[hidden]> wrote:
> This issue has previously been discussed in details, and IIRC, the
> conclusion was that the reliable method to detect peer disconnection
> is to try reading from the socket.

Not quite. IIRC, the conclusion was that you are hosed in this exact scenario.

Basically, if you absolutely must detect this, and aren't otherwise
sending data, then you need to be able to build a "heartbeat" into
your protocol. You essentially must periodically send a packet (e.g.
a heartbeat message). The write call will always succeed until you
fill up your socket send buffer (which won't happen w/ heartbeat
messages). However, the failure to write will ultimately trigger a
timeout, and it will be the read call that fails.

See the previous thread for the details as to what is happening at the
TCP level.

Jon


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