Boost logo

Boost Users :

Subject: Re: [Boost-users] [solved] asio::transfer_at_least strange behavior
From: Timenkov Yuri (ytimenkov_at_[hidden])
Date: 2009-02-13 04:24:20


On Fri, Feb 13, 2009 at 12:22 AM, Igor R <boost.lists_at_[hidden]> wrote:

> Yes, exactly. Code snippet may be uselese, but I'm using something like
>> this:
>> boost::asio::read(sock, buf, boost::asio::transfer_at_least(800),
>> myhandler);
>>
>> and myhandler is never called (because no more data arrives).
>>
>
>
> So, probably 800 bytes do not arrive, or there's some other issue.
>
>
>
>> This handler called after each read operation and bytes_transferred each
>> time is 400, but minimum_ is 800.
>>
>>>
> Look at the implementation of read():
> (Note that bytes_transferred passed to the completion_condition is
> accumulated each time)
>
> template <typename SyncReadStream, typename MutableBufferSequence,
> typename CompletionCondition>
> std::size_t read(SyncReadStream& s, const MutableBufferSequence& buffers,
> CompletionCondition completion_condition, boost::system::error_code&
> ec)
> {
> ec = boost::system::error_code();
> boost::asio::detail::consuming_buffers<
> mutable_buffer, MutableBufferSequence> tmp(buffers);
> std::size_t total_transferred = 0;
> tmp.set_max_size(detail::adapt_completion_condition_result(
> completion_condition(ec, total_transferred)));
> while (tmp.begin() != tmp.end())
> {
> std::size_t bytes_transferred = s.read_some(tmp, ec);
> tmp.consume(bytes_transferred);
> * total_transferred += bytes_transferred;*
> tmp.set_max_size(detail::adapt_completion_condition_result(
> completion_condition(ec, total_transferred)));
> }
> return total_transferred;
> }
>
Yes, my bad, sorry for noise.

Actually, I've used streambuf to read HTTP response with content-length. But
some data was already in buffer. I've changed my code to something like
this:
contentLength -= boost::asio::buffer_size(m_readBuffer.data());
boost::asio::async_read(m_socket, m_readBuffer,
boost::asio::transfer_at_least(contentLength),
                myhandler);

And now everything works fine.
Thanks for help.

>
>
>
>
> _______________________________________________
> 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