title: boost::asio::streambuf - how to reuse buffer?
body: <p>I'm implementing TCP server that uses both asio socket.async_read() and boost::asio::async_read_until() methods for asynchronous reading data from socket. Both use the same handler for reading data from boost::asio::streambuf.</p>
  
  <p>The handler that perfectly works invoked via async_read() :</p>
  
  <pre><code>void handle_read(const boost::system::error_code&amp; ec, std::size_t ytes_transferred) )
  {
      m_request_buffer.commit(bytes_transferred);
      boost::asio::streambuf::const_buffers_type rq_buf_data = m_request_buffer.data();
      std::vector&lt;uint8_t&gt; dataBytes(boost::asio::buffers_begin(rq_buf_data), boost::asio::buffers_begin(rq_buf_data) + bytes_transferred);
  
      //process data here
  
      m_request_buffer.consume(bytes_transferred);
      bytes_transferred = 0;
  }
  </code></pre>
  
  <p>My server depending on processing of data may shutdown connection or continue reading via the same socket.</p>
  
  <p>But, if handle_read() is called from the 2-nd boost::asi::async_read_until() call, I'm getting a number of zero's in dataBytes and then valid data goes. </p>
  
  <p>I tried a simple test-case and found out that after writing data to streambuf, and commit() + consume() the data in streambuf still keeps previous buffer.</p>
  
  <p>So, is there any way to clear data in boost::asio::streambuf and reuse it in boost::asio::async_read_until() ? </p>
  
  <p><a href="http://coliru.stacked-crooked.com/a/aab889f4789d1c71" rel="noreferrer">Live Coliru</a></p>
  
  <p>If compiled with USE_STREAM=1, the live example works fine. But what std::istream does different comparing with buffer consume() ?</p>