Boost logo

Boost Users :

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


"Nicola Michael Gutberlet" <nicola.gutberlet_at_[hidden]> writes:

> At first: Thanks to all the fast responses - this mailing list seems to work
> properly ;-)
>
> Scott Gifford:
>> [...] or else use TCP keepalives.
>
> Can you shortly explain how to use "keepalives" and how they work / react in
> case of a closed other side?

See this example:

    http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/reference/socket_base/keep_alive.html

Basically, with this option set your TCP implementation will
periodically send a packet that effectively has zero length but
requires acknowledgement from the other side, triggering the timeout
counter to start. How frequently keepalive packets are sent is
determined by your TCP implementation, and is typically set on a
system-wide basis and defaults to about an hour.

The effect of this is the same as you writing to the stream
periodically, except that the other side doesn't see any writes at the
application layer. That is, you still have to read from the socket to
detect an error.

If the application protocol you are using on top of TCP supports it,
sending some kind of no-op command periodically will give you a bit
more control over timing.

Hope this helps!

----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