Discussion:
Expected behavior of read with a streambuf and a completion routine
(too old to reply)
Philippe Leuba
2016-05-13 13:27:06 UTC
Permalink
Hi,

I have encountered a strange behavior when reading on a TCP stream with a streambuf and a completion routine.

Imagine that I'm receiving in a single chunk: "Welcome\n".

Then the following code:
streambuf buf;
read(sock, buf, at_least(2));
buf.consume(2);
read(sock, buf, at_least(2)); // Blocks

The documentation says that read() results in zero or n call to read_some. In this case, the data are already in the buf, but the completion routine is called with total_transferred = 0, resulting in a new call to read_some that blocks even if the data are already present.
Same behavior for async_read, but async/read_until returns directly with the data already in the buffer.

I was expecting that the data already in the streambuf was counted in the total_transferred parameter of the completion routine.

Is it a bug ?

Philippe Leuba

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
asio-users mailing list
asio-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio

Loading...