Boost logo

Boost Users :

Subject: Re: [Boost-users] async_read_some
From: Lars Viklund (zao_at_[hidden])
Date: 2012-05-01 08:09:29


On Sat, Apr 28, 2012 at 10:56:49AM +0200, Christer Borgqvist wrote:
> Hi,
> Im playing around with the /boost_asio/example/http/server3
> and using POST method.
> The bytes_transferred is 231, but thats only the header and ends with
> \r\n\r\n, need to read the rest.
> Sometimes i get bytes_transferred to 1032, the right amount of data,
> sometimes i get bytes_transferred = 231, but if i print the buffer_ i have
> all the 1032 bytes.
> Is it right that the bytes in the buffer_ and the bytes_transferred is not
> the same?

Only the first 'bytes_transferred' octets are the ones you asked for,
the rest are indeterminate (or well, likely whatever they were before
you made the read).

The language doesn't know how many of the elements you consider "valid"
or "real", it just knows about the size of the storage. If you've got a
container that fits 1032 bytes, it stays so after the call, as the
read/read_some functions only work with existing dumb storage.

read_some is a low-level function that doesn't give that many promises
in number of bytes read. The reason it's used here is because the length
of a HTTP message or header is unknown and it's happy enough just
reading repeatedly in arbitrary chunks until it has enough to parse the
request.

Last, but not least, TCP is a stream protocol. The chunks you write data
to the connection are not preserved in any way across the stream. When
the data arrives at the recieving end, it's just a boundary-less
sequence of bytes, which your underlying platform tends to give you in
chunks of uncorrelated size.

-- 
Lars Viklund | zao_at_[hidden]

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