Boost logo

Boost Users :

Subject: [Boost-users] [ASIO] Streambuf not containing full line
From: Gonzalo Garramuno (ggarra13_at_[hidden])
Date: 2014-02-26 14:55:13

I am using asio asynchronically. I have:

void tcp_session::start_read()
    // Set a deadline for the read operation.

    // input_deadline_.expires_from_now(boost::posix_time::seconds(30));
    // input_deadline_.expires_at(boost::posix_time::pos_infin);

    // Start an asynchronous operation to read a newline-delimited message.
    boost::asio::async_read_until(socket(), input_buffer_, '\n',

void tcp_session::handle_read(const boost::system::error_code& ec)
    if (stopped())

    if (!ec)
       // Extract the newline-delimited message from the buffer.
       std::string msg;
       std::istream is(&input_buffer_);
        is.exceptions( std::ifstream::failbit | std::ifstream::badbit |
                   std::ifstream::eofbit );

       try {
      while ( std::getline(is, msg) )
         // parse msg here (gets truncated to last 256 chars or so)
         std::cerr << msg << std::endl;
       catch ( const std::ios_base::failure& e )
         std::cerr << "getline failure " << e.what() << std::endl;

My problem is that I am seeing messages that are not a full line, but a
truncation of the line, as if a buffer gets full with 256 characters. I
am unsure what I am doing wrong. I get a getline failure saying

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