Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost::asio] Wait for multiple async_read()'s
From: TONGARI J (tongari95_at_[hidden])
Date: 2017-01-21 09:31:59


2017-01-21 20:09 GMT+08:00 Adam Zegelin <adam_at_[hidden]>:

> Hi,
>
> I'm writing a boost::asio application that communicates with multiple
> streams. I'd like to write data to these streams then wait for
> everyone to reply before performing computation on the resulting data.
>
> What is the best way to implement this?
>
> The route I've ventured down involves me calling async_write() on each
> stream, with the callback hander executing async_read(). But this
> where I'm stuck. What is the best way to execute one final hander once
> all read operations have completed?
>

Coroutine may help. Take a simple echo-server for example:
https://github.com/jamboree/co2#asio-echo-server
In your case, you just need to keep the tasks in a list and 'await' for
them to complete.



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