Boost logo

Boost Users :

From: Cliff Green (cliffg_at_[hidden])
Date: 2007-06-28 20:08:48


  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?

Cliff


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