Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Get less bytes then expected with with boost::asio::transfer_at_least within async_read call.
From: Nikolai N Fetissov (nikolai-boost_at_[hidden])
Date: 2010-02-08 13:33:20


Unless I'm missing something it looks like you are
passing zero-length vector to the buffer() function.
>From asio docs this call is equivalent to:

mutable_buffers_1(
    data.size() ? &data[0] : 0,
    min(data.size() * sizeof(PodType), max_size_in_bytes));

,where the data.size() = read_buffer_.size() i.e. zero for empty vector.
You might try vector::resize(15) or just a size-taking constructor.

Cheers,

--
 Nikolai
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

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