Boost logo

Boost Users :

Subject: Re: [Boost-users] Which socket read get first when both asio::async_read and asio::read are active?
From: jupiter (jupiter.hce_at_[hidden])
Date: 2017-08-02 10:38:17

Thanks for the advice.

On Wed, Aug 2, 2017 at 12:38 PM, Gavin Lambert via Boost-users <
boost-users_at_[hidden]> wrote:

> On 2/08/2017 13:30, jupiter wrote:
>> I have a socket server program to activate in asio::async_read for
>> receive any messages initiated from client. But when the server sends a
>> message to the client, it uses sync write and flowing a sync read
>> (asio::read) to immediately receive the response. The issue I can think of
>> is who will get first read when both asio::async_read and asio::read are
>> active?
> One or both of them selected at semi-random by the OS. Basically: don't
> do that.
> (Especially because both read and async_read are not necessarily single
> operations -- they can internally be composed of multiple calls to
> [async_]read_some.)
> Each individual data block will only be received by at most one of the
> handlers, but a single "response" could come in as arbitrarily many blocks,
> and if you have multiple read operations pending simultaneously then the
> chances of multiple blocks hitting multiple handlers are nearly certain.
> You will need to remove the sync read and only do the async read; your
> async read handler (or downstream code) will need to recognise the
> difference between an unsolicited message and a response and handle it
> accordingly.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

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