I'm a Boost C++ newbie and, using it to write a Server-like application I am wondering if it is possible to concurrently use boost::asio::ip::tcp::socket::async_read_some(...)
and boost::asio::ip::tcp::socket::write_some(...)
.
In my scenario a Connection object listens continuously via:
void Connection::doRead()
{
auto self(shared_from_this());
socket_.async_read_some(boost::asio::buffer(data_rx_, max_length),
[this, self](boost::system::error_code ec, std::size_t length)
{
if (!ec)
{
afterReading(length);
doRead();
}
});
}
At the same time, an asynchronous function callback (running in a different thread) could invoke socket_.read_write
while Connection is "reading".
I've read various Boost::Asio docs but this scenario was never covered.
Is this allowed? What should be done to avoid it if not?
EDIT:
I have read, as suggested, various answers including this: Why do I need strand per connection when using boost::asio?, but still can't find an answer as it is not specified wether mixing async and sync (called by different threads) calls is safe or not.