
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
}
Do you expect std::getline to give you more than 1 line?