Discussion:
[asio-users] Clarification needed about async_read
Guido Winkelmann
2011-10-07 13:53:32 UTC
Permalink
Hi,

I'm in need of some clarification regarding the documentation to the fourth
overload of async_read - this one:

template<
typename AsyncReadStream,
typename Allocator,
typename CompletionCondition,
typename ReadHandler>
void async_read(
AsyncReadStream & s,
basic_streambuf< Allocator > & b,
CompletionCondition completion_condition,
ReadHandler handler);

The documentation gives the required signature of CompletionCondition as this:

std::size_t completion_condition(
// Result of latest async_read_some operation.
const boost::system::error_code& error,

// Number of bytes transferred so far.
std::size_t bytes_transferred
);

Question: When async_read calls completion_condition, will bytes_transferred
include the number of bytes that were already in the read buffer b before the
call to async_read, or will it only include the number of bytes actually
transferred from the socket to buffer since the last call to async_read?

If it's the latter, that would at least explain the problems I've been having
that I described in the earlier thread "Weird effect when reading more than
1000 bytes with async_read".

Regards,

Guido
Rutger ter Borg
2011-10-10 06:43:34 UTC
Permalink
Post by Guido Winkelmann
Question: When async_read calls completion_condition, will bytes_transferred
include the number of bytes that were already in the read buffer b before the
call to async_read, or will it only include the number of bytes actually
transferred from the socket to buffer since the last call to async_read?
The latter; it's the number of bytes transferred.

Rutger

Loading...