Boost logo

Boost :

Subject: Re: [boost] [asio] boost::asio::read with empty input vector leads to an infinite loop
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2012-07-13 19:51:46


On 13/07/12 14:29, Matthew L. Creech wrote:
> On Fri, Jul 13, 2012 at 2:19 PM, Michael Kochetkov <michael.kv_at_[hidden]> wrote:
>> I would prefer a error message or crash because it is logically to suppose
>> the asio would resize the vector or emit a error because it cannot handle
>> situation properly (IMO). The concern behind the issue is working time and
>> money -- it is really tricky for inexperienced boost users to figure out the
>> culprit of the behavior. The program does not crash, it reports no errors
>> and it just does not work.
>>
>
> It seems like the documentation already addresses both of these questions.
>
> For boost::asio::read() it says "The call will block until one of the
> following conditions is true: 1) The supplied buffers are full. That
> is, the bytes transferred is equal to the sum of the buffer sizes..."
>
> For an empty vector, that's always going to be the case, so it will never block.

That is how the docs appear, and it may be true for this function, but
at least for async_read_some with a zero-size buffer the handler won't
be called until there is some data to be read (but it won't actually
read it), which is a very useful feature. It may well be that read is
doing the same (i.e. returning once there is data to be read).

John Bytheway


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk