[asio]Does the function of async_read can find the tcp connection has closed?
hi all: I want to know async_read or async_write can detect the tcp connection has closed, or not? thank you
On 15/04/2014 16:04, quoth lx:
I want to know async_read or async_write can detect the tcp connection has closed, or not?
Try it and see. Generally you should get an error callback for write if the connection has closed. You may or may not get one for read, depending on how the connection was closed. (Graceful shutdown or local connections typically will, unexpected remote disconnection typically won't.) This is not unique to ASIO; it's how pretty much all TCP sockets work.
hi all:
2014-04-15 15:37 GMT+08:00 Gavin Lambert
On 15/04/2014 16:04, quoth lx:
I want to know async_read or async_write can detect the tcp
connection has closed, or not?
Try it and see.
Generally you should get an error callback for write if the connection has closed. You may or may not get one for read, depending on how the connection was closed. (Graceful shutdown or local connections typically will, unexpected remote disconnection typically won't.)
This is not unique to ASIO; it's how pretty much all TCP sockets work.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
hi all:
I try it. The async_read in client can't detect the connection of tcp
close immediately when I kill the process of server, but It can find it
after almost 3 minutes.
2014-04-18 15:45 GMT+08:00 lx
hi all:
2014-04-15 15:37 GMT+08:00 Gavin Lambert
: On 15/04/2014 16:04, quoth lx:
I want to know async_read or async_write can detect the tcp
connection has closed, or not?
Try it and see.
Generally you should get an error callback for write if the connection has closed. You may or may not get one for read, depending on how the connection was closed. (Graceful shutdown or local connections typically will, unexpected remote disconnection typically won't.)
This is not unique to ASIO; it's how pretty much all TCP sockets work.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
hi all: I try it. The async_read in client can't detect the connection of tcp close immediately when I kill the process of server, but It can find it after almost 3 minutes.
The only reliable and portable way to detect peer socket disconnection is to implement application-layer ping/heartbeat.
participants (3)
-
Gavin Lambert
-
Igor R
-
lx