Boost logo

Boost :

Subject: [boost] boost::asio::streambuf problem
From: rod haxton (rehaxton_at_[hidden])
Date: 2008-10-18 14:19:50


"Long time listener, first time caller..."

I'm struggling with the "boost::asio::streambuf," and the

I'm trying to wait on the async_read_until, which I can do after the first
message is sent, but subsequent messages received cause the streambuf to
continuously grow. I am trying to use the streambuf via the .data() member.

void TAsioSession::Start()
    boost::asio::async_read_until(m_Socket, m_szAsioData,

void TAsioSession::HandleRead(const boost::system::error_code& error,
size_t bytes_transferred)
        boost::asio::streambuf::const_buffers_type bufs =;

        std::string szBuffer(
            boost::asio::buffers_begin(bufs) + bytes_transferred);

        LP_ICPACKET lpICPacket =

     // reset streambuf for reading (how?)


 Once I grab the data that is in the buffer, I want to reset the streambuf
and go back to "async_read_until," and wait for another message to come in.

I try to do the following to reset the streambuf pointers...

        // set the current put/get ptrs of streambuf to beginning of stream

        // clear the streambuff
        char szClear[512];
        ZeroMemory(szClear, 512);
        m_szAsioData.sputn(szClear, sizeof(szClear));
        m_szAsioData.sgetn(szClear, sizeof(szClear));

        // set the current ptrs of streambuf back to beginning

 but the new message isn't at the head of the buffer, it is coming in at
position 512 of the streambuf, and the streambuf grows.

Any help would be appreciated.


Boost list run by bdawes at, gregod at, cpdaniel at, john at