Boost logo

Boost Users :

Subject: [Boost-users] [asio] Get less bytes then expected with with boost::asio::transfer_at_least within async_read call.
From: Sakharuk, Vladimir (vladimir.sakharuk_at_[hidden])
Date: 2010-02-08 12:49:32


Trying to limit number of bytes transferred to at least 15 bytes before
async_read call back
I have got callbacks with sizes:
0,1,2,3,4 and 5 (so total indeed 15)
But I was expecting only single callback with size 15.

How I can fix the issue?

Thanks Vlad.

linux suse 2.6.16 boost 1.39 gcc 4.1.2

//boost asio stripped part.

BufferSize=1000;
class test{

vector<char> read_buffer_;
boost::asio::ip::tcp::socket socket_; //socket was inited correctly.

test() {
        read_buffer_.reserve(BufferSize);
}

void handle_connect( const boost::system::error_code& err,
boost::asio::ip::tcp::resolver::iterator endpoint_iterator )
  {
    if (!err) {
      boost::asio::async_read(socket_,boost::asio::buffer(read_buffer_,
BufferSize),
//requested at least 15 bytes!!
        boost::asio::transfer_at_least(15),
              boost::bind(&test::handle_read, this,
boost::asio::placeholders::error));
    }
    else {
        cerr<<err.message()<<endl;
    }
  }

void handle_read( const boost::system::error_code& err)
{
 if (!err) {
//+++++++++++++++++++++++++++
//expecting to get at least 15!
//But have not get those.
//+++++++++++++++++++++++++++
        cerr<<"Got:"<<read_buffer_.size()<<endl;
      boost::asio::async_read(socket_,boost::asio::buffer(read_buffer_,
MaxResponce),
//requested at least 15 bytes!!
                              boost::asio::transfer_at_least(15),
                              boost::bind(&test::handle_read, this,
boost::asio::placeholders::error) );
    }
 else {
        cerr<<err.message()<<endl;
 }
}

};

===============================================================================
 Please access the attached hyperlink for an important electronic communications disclaimer:
 http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
 ===============================================================================
 


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