logo       

Re: Testing socket for disconnect: msg#00035

lib.boost.asio.user

Subject: Re: Testing socket for disconnect


Stas Khirman wrote:
> What is 'ASIO-approved' way to check if TCP socket had been disconnected
> by remote peer while no outstanding read/write operation.

Actually maintaining an outstanding read operation is usually the best
way, since you will be notified of the disconnection as soon as it
occurs. You could probably also call the remote_endpoint() function and
check if it fails, but that function is not really intended for that
usage.

However, as Richard suggested, you would want to investigate
higher-level mechanisms for detecting connection loss if you want to be
able to detect all network failures, etc.

> Related question - Did I understand correctly that if I have an
> outstanding read/write it will be completed with asio::error::
> connection_aborted error on remote peer disconnect ? .

No. If the peer closes the connection cleanly, the read will get
error::eof. If the connection is closed due to error, you may get
something like error::connection_reset, error::network_reset etc.
Typically you should just distinguish between graceful closure (i.e.
error::eof) and something else.

Cheers,
Chris

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise