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 iostream.read() I get a syntax error.

e.g.

int bytes_read;
boost::asio::ip::tcp::iostream dataServerStream;
while ( bytes_read = dataServerStream.read((char*)&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 object.read() 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 hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net