Boost logo

Boost Users :

Subject: Re: [Boost-users] asio::ip::tcp iostream wrong byte count read for last packet
From: Steve Coleman (Steve.Coleman_at_[hidden])
Date: 2014-08-11 10:00:08

On 08/10/14 18:50, Gavin Lambert wrote:
> On 9/08/2014 04:58, Steve Coleman wrote:
>> My problem is in getting the correct byte count read in the final packet
>> received. My last frame always returns the size of the buffer, not the
>> number of bytes read into the buffer. Isn't iostream::gcount(() meant
>> for this? If not, what is the correct 'Boost' way of doing this?
> "read" returns the number of bytes actually read. Use that.

I must be missing something here from your explanation. If I try to
receive a return from this I get a syntax error.


int bytes_read;
boost::asio::ip::tcp::iostream dataServerStream;
while ( bytes_read =*)&buffer, nbytes) )

pmms_server.cpp:379:21: error: invalid user-defined conversion from
'std::basic_istream<char>::__istream_type {aka
std::basic_istream<char>}' to 'int' [-fpermissive]

Is there a different function you are talking about? Or a
specific data type to declare for the return value type?

> (If you later switch to doing an async read, then it is one of the
> parameters that can be passed to the callback function.)
> Depending on what you're reading, you may also want to use one of the
> read* free functions to guarantee reading exactly or at least a
> specified number of bytes, or up to a specified delimiter.

btw - I want a synchronous read of a binary data stream.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at