Scenario:
Inside object A (thread A), boost::asio::ip::tcp::socket is being read from and written to asynchronously.
Object B (thread B) posts data to object A's data queue.
Object A should write the data in its data queue as soon as possible.
How to achieve the third point efficiently?
Right now I'm doing this:
There might be no data in the queue.
socket->async_send(data, handler);
inside handler: back to point two.
I'm worried that this approach is highly inefficient - calling async_send with zero-length data most of the time until actual data can be sent.
Might it be that a better approach would be to have an additional thread inside object A that performs synchronous writes on the socket as soon as new data is posted? Peforming the write from object B's thread is out of question.