|
Boost Users : |
Subject: Re: [Boost-users] [Asio] null_buffers problem
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-11-24 01:57:46
On 20/11/2014 14:16, lin li wrote:
> Hi, guys. I have some problem with null_buffers in Asio. According to
> the document, 'A |null_buffers| operation doesn't return until the I/O
> object is "ready" to perform the operation'. However, when I tried to
> use it in a asynchronous read, it keeps returning after all data has
> been received and the other end has closed the socket! So here is my
> questions:
> 1. what is "ready" exactly?
I'm not 100% certain of this, but I believe it just means "becomes
readable". It doesn't actually read anything though so you have to do a
"real" read in your handler before doing a null_buffers read again, or
it will just stay ready forever.
Usually there's not a lot of point in doing a null_buffers +
not-null_buffers read -- just combine them into one real read. The
exception is when you're trying to wrap external code that does a
synchronous read internally; null_buffers provides a way to make it
asynchronous.
> 2. If we use null_buffers with async_read_some, will it detect some
> errors like disconnection and pass the error code to the completion handler?
With sockets at least it is not guaranteed that you will *ever* get a
disconnection event from a read operation. You have to send something
to detect ungraceful disconnects (such as remote device abruptly lost
network connection or power cycled).
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