Boost logo

Boost Users :

Subject: Re: [Boost-users] asio::transfer_at_least strange behavior
From: Timenkov Yuri (ytimenkov_at_[hidden])
Date: 2009-02-12 15:14:59


On Thu, Feb 12, 2009 at 10:16 PM, Igor R <boost.lists_at_[hidden]> wrote:

> Is transfer_at_least supposed to return success only if requested number of
>> bytes transferred at once or at all?
>>
>
>
> http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/reference/transfer_at_least.html
> "Return a completion condition function object that indicates that a read
> or write operation **should continue until** a minimum number of bytes has
> been transferred, or until an error occurs."
>
>
>
>> For example, I want to receive 800 bytes and put them into streambuf using
>> transfer_at_least(800) as completion condition, but I receive 2 chunks of
>> 400 bytes, therefore I never get a success, because transfer_at_least_t
>> always wants more data.
>
>
> When 800 bytes are received (at once or by chunks) or error occurs, the
> completion handler is invoked - that's the effect of this completion
> condition. If you encounter different behaviour, could you please provide
> minimal code demonstrating this?
>
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).

>From implementation:
class transfer_at_least_t
{
public:
  typedef std::size_t result_type;

  explicit transfer_at_least_t(std::size_t minimum)
    : minimum_(minimum)
  {
  }

  template <typename Error>
  std::size_t operator()(const Error& err, std::size_t bytes_transferred)
  {
    return (!!err || bytes_transferred >= minimum_)
    ? 0 : default_max_transfer_size;
  }

private:
  std::size_t minimum_;
};

This handler called after each read operation and bytes_transferred each
time is 400, but minimum_ is 800.

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