Boost logo

Boost Users :

From: Richard Dingwall (rdingwall_at_[hidden])
Date: 2007-06-28 23:51:37


On 6/29/07, Cliff Green <cliffg_at_[hidden]> wrote:
>
> Andrej van der Zee <mavdzee_at_[hidden]> wrote:
> > I was wondering how I can find out with ASIO whether a
> > connection is broken. I have a client connected to the
> > server that continuously streams data.
>
> The canonical way to consistently detect broken TCP
> connections is to always have a read on the socket - it
> will return 0 on broken connection (in usual BSD sockets
> type reads - I would expect an appropriate error parameter
> set in ASIO). Since you're doing async operations this is
> pretty easy.
>
> Many times a write will only buffer the data (at the OS /
> TCP driver level), and an error is not detected until a
> later write (and if the client socket is in a "half
> shutdown" mode, it might be quite a while before the TCP
> keepalive timer pops and the socket is fully destroyed).
>
> This is absent special ASIO capabilities - if ASIO is
> doing a read "on your behalf", then the problem is the
> "not completely destroyed connection", which is an OS /
> TCP "feature" and nothing that ASIO can help with. I
> haven't found specific details relating to this in ASIO,
> but that may only be because I haven't read enough of the
> ASIO documentation.
>
> Chris K (or others), clarifications, corrections, or
> comments?

You test for a disconnection with Asio the same way you would with BSD
sockets - you need to leave a long-running read operating going.

Check out this post from the Asio-users mailing list:
http://osdir.com/ml/lib.boost.asio.user/2006-11/msg00035.html

Richard

Cliff
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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