Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Does ssl::stream allow multiple pending async operations?
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2017-11-06 04:53:54


On 6/11/2017 12:00, Bjorn Reese wrote:
> On 11/05/2017 05:46 PM, Phil Sean wrote:
>
>> What about two outstanding read operations or two outstanding write
>> operations? I think they're safe for tcp::socket but not ssl::stream.
>
> You are not guaranteed that multiple asynchronous write operations are
> executed in the order you initiate them, so having more than one
> outstanding operation can lead to unexpected results.

They're also not guaranteed to execute atomically -- ie. you can have
part of write1 interleaved with part of write2, although all of the
bytes in each individual write should eventually turn up in the correct
relative order -- but that's rarely sufficient.

The same applies for reads -- if you have two outstanding reads on the
same socket/stream then any received bytes could up spread
non-deterministically between the two completion handlers.

So regardless of whether the objects officially support it or not, I
cannot think of a situation in which actually doing that would be
anything other than a mess. So just don't do it.

UDP is a different story; there are scenarios where multiple pending
reads or writes makes sense there. But not for anything stream-oriented.


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