From: Christian Hammerl <info@ch...> - 2013-08-14 13:19:12
I am currently using asio from boost 1.54 and recently discovered the
following (in my opinion) unexpected behaviour.
The code in question is:
size_t bytes_transferred = read_until(socket, buffer, "foo", error);
bytes_transferred = read(socket, buffer, transfer_all(), error);
The call to read_until results in "foobar" being written to the buffer
and bytes_transferred is set to "3". Everything as expected so far.
However, the following call to read returns "0" for bytes_transferred
and the error_code is set to "eof".
This is just logical because the read function tries to read data from
the socket without checking the buffer first.
Because there is no more data, "0" is returned and "eof" is set for the
This forces me to manually check the buffer if there is additional data
that is not being processed by the read_until function and I cannot
just rely on the bytes_transferred returned by the functions.
I would expect that the read function does this for me and checks the
buffer content first before attempting to read from the socket just
like a subsequent call to read_until would do.
Then I could just sum up all of the bytes_transferred returned by the
functions and would get the total bytes transferred without the need to
manually inspect the buffer for additional bytes after each call to
I would like to know if this is expected behaviour.