Boost logo

Boost Users :

Subject: [Boost-users] Boost::Asio read_until and streambuf usage
From: Gonzalo Garramuno (ggarra13_at_[hidden])
Date: 2012-11-21 12:11:35


I have a server that sends three lines, each of which have to be parsed
independently.
I am using read_until but have a problem with its usage. When
read_until reads once, the streambuf seems to contain the three lines
but not in the istream and only when I call read_until several times, I
get the lines.
I am wondering how can I safely read_until the buffer is empty (the 3 or
more lines are read) and then exit the loop.

       boost::asio::streambuf buf;

       while( 1 )

       {
          size_t reply_length = boost::asio::read_until( socket_,
                                                                buf, '\n' );

         std::istream is(&buf);
         std::string reply;
         std::getline(is, reply); // only 1 line obtained

       }


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