Boost logo

Boost Users :

Subject: Re: [Boost-users] std::future::wait_for() not working in Boost UDP socket async receive operation
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2016-11-29 19:12:48

On 29/11/2016 23:09, TONGARI J wrote:
> I think we're wrong about whether it's allowed to call
> async_receive_from() multiple times before it completes.
> It was from my impression that we can't do that, but skimming over the
> ASIO docs I found nothing says that.
> Experiments show that it works, so I think my argument in this regard
> was wrong, at least ASIO itself does not enforce the restriction.

It's technically permitted but it's rarely a good idea to have multiple
pending operations of the same type (eg. more than one read or more than
one write) on the same socket/whatever, as it becomes undefined what
order things end up at the other end, which is rarely acceptable. (You
can sometimes get away with concurrent writes with UDP, if done
carefully; you typically can't get away with it with TCP. It's almost
never sensible to have concurrent reads with either.)

And also because user code will tend to supply the same buffers for
multiple such operations of the same type, and that's definitely not
allowed to use the same buffer in multiple concurrent operations.

It's ok to have a pending read and a pending write on the same
socket/whatever (as long as they use separate buffers), but then you
can't selectively cancel() one of them, which may not be what you want.

(It is actually possible to cancel an individual operation in WinAPI,
but I don't think ASIO exposes this; possibly this isn't supported on
Linux or because ASIO's own API doesn't really provide operation handles
to let you specify what you want to be cancelled.)

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at