|
Boost Users : |
Subject: Re: [Boost-users] [asio] socket::read_some() splits data into two parts.
From: Igor R (boost.lists_at_[hidden])
Date: 2011-05-11 10:39:17
> I sent 8004 bytes to server through TCP connection and successfully read it
> like this:
>
> Â Â Â int readBytes;
> Â Â Â const int BUFFER_SIZE = 128;
> Â Â Â char charBuf[BUFFER_SIZE];
> Â Â Â do
> Â Â Â {
> Â Â Â Â Â Â readBytes = socket.read_some(boost::asio::buffer(charBuf,
> BUFFER_SIZE));
> Â Â Â }
> Â Â Â while(readBytes >= BUFFER_SIZE);
>
> But sometimes this code reads just 3752 (precisely) bytes and returns. After
> that it handles another async_read and reads 4525 bytes (which in sum gives
> 8004 bytes).
> Do I use "read_some()" function in the right way?
This is exactly what "read_some" does -- it reads SOME data. It may
read even 1 byte.
If you know exactly how many bytes you expect to get, use read() free
function with the appropriate completion condition:
http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/reference/read.html
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