Boost Users :
Subject: Re: [Boost-users] [asio] async write handler is not called until the socket is not closed
From: Igor R (boost.lists_at_[hidden])
Date: 2009-05-01 08:01:43
> Let's imagine one IO thread. on timer event (each second) it pushes X
> messages to socket with async_write.
> Also, at this time, the IO thread receives Y messages with async_read
> through the same socket.
> Is there any limit in pushing messages with async_write? What it is?
I know nothing about such a limit, but I suspect another issue in your
approach: your description sounds like you don't ensure that
async_write is complete (i.e. the handler is called) before issuing
another one. If my assumption is correct, you might run into various
problems, as the order of execution of your async_writes is undefined.
The same applies to async_read's.
The correct approach would be like this:
class connection : public enable_shared_from_this<connection>
void send(Data data)
void syncSend(Data data)
// enqueue the data and ensure the write is active
if (!activeWrite_ && unsentDataExists)
activeWrite_ = true;
activeWrite_ = false;
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