Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-10-18 18:12:35


Christian Rössel wrote:
> Dear all,
>
> I want to receive a boost::archive::text_iarchive using the
> boost::asio::read_until () function.
>
> boost::asio::streambuf response;
> boost::asio::read_until(socket, response, boost::regex("\r\n"));
> std::istream responseStream(&response);
> boost::archive::text_iarchive responseArchive (responseStream);
> responseArchive >> retVal;
>
> The data is sent using code linke this:
>
> boost::asio::streambuf response;
> std::ostream commandStream (&response);
> boost::archive::text_oarchive responseArchive (commandStream);
> const ReturnValue retVal (42);
> responseArchive << retVal;
> boost::asio::write(socket, response);
>
> If I use boost::regex("\r\n") or a character that does not occur in
> the sent archive, read_until throws an eof exception. If I use a
> delimiter that is contained in the archive, read_until succeeds and
> the streambuf does contain the entire archive, not only up to the
> delimiter.
>
> What is the correct way to read the entire archive without throwing an
> exception?

I think the "correct way is to be sure the archive is destroyed before
sending.
This should append a /n at the end - (at least in 1.34 - this might be a
problem
with previous versions - or maybe not.) So the above would look like:

boost::asio::streambuf response;
std::ostream commandStream (&response);
{
    boost::archive::text_oarchive responseArchive (commandStream);
    const ReturnValue retVal (42);
    responseArchive << retVal;
} // archive closed appends /n at this point.
boost::asio::write(socket, response);

or you could just append a \n to commandStream

>
> Thanks and regards,
> Christian


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