Subject: Re: [boost] [asio] boost::asio::read with empty input vector leads to an infinite loop
From: Matthew L. Creech (mlcreech_at_[hidden])
Date: 2012-07-13 14:29:57
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.
As for supposing that the buffer might resize the vector for you, ASIO
has no idea (for example) how large you'd be willing to let it grow.
The docs specifically say that buffer(std::vector<...>) is equivalent
data.size() ? &data : 0,
data.size() * sizeof(PodType));
which shows that it's definitely not going to manipulate the container itself.
-- Matthew L. Creech
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk