Boost Users :
Subject: Re: [Boost-users] [asio] Socket closed notification?
From: Scott Gifford (sgifford_at_[hidden])
Date: 2009-12-15 00:07:51
Jonathan Franklin <franklin.jonathan_at_[hidden]> writes:
> On Mon, Dec 14, 2009 at 9:17 PM, Scott Gifford
> <sgifford_at_[hidden]> wrote:
>> Andrew Maclean <andrew.amaclean_at_[hidden]> writes:
>>> On Tue, Dec 15, 2009 at 2:50 PM, Scott Gifford
>>> <sgifford_at_[hidden]> wrote:
>>>> Jonathan Franklin <franklin.jonathan_at_[hidden]> writes:
>> Sure, just use any of the read functions and see if they return an
>> error. In my application, I use read_until(), but any function that
>> reads should do.
> If the remote app closes unexpectedly, you read will return EOF.
>From when I tested this a while back, my notes indicate I got one of
these errors for an unclean shutdown (timeout or a TCP RST packet):
but it's been awhile and I don't rememberly clearly under exactly what
>>> Unfortunately, write isn't reliable since it will always succeed until
>>> you fill up your send buffer.
>> Well, OK, maybe a write and a flush. Certainly there are othe
>> buffers, but typically a TCP implementation will time out at some
>> point if it has some pending data which is not acknowledged, and
>> typically once data is flushed to the TCP layer it will try to write
>> it and begin waiting for its timeout.
> Yeah, it's not reliable, and can take *many* writes.
The TCP stack may have to do many writes, but the app should only have
to write once and do a flush to detect an unresponsive other side.
At the very least, this is a technique I have consistently seen
recommended, and has always worked for me.
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