Boost logo

Boost :

Subject: Re: [boost] [ASIO] Issue with epoll reactor? Callback handler not executed.
From: Marat Abrarov (abrarov_at_[hidden])
Date: 2013-05-24 05:47:07

Hi, Arpan.

> Everything works fine till async_write.

You forgot that free functions like
asio::async_write(_until)/asio::async_read(_until)/etc. are composed
This operation is implemented in terms of zero or more calls to the stream's
async_read_some function, and is known as a composed operation.

Any composed operation (failed to find documentation for this) is
implemented by means of multiple simple asynchronous operations. For example
asio::async_read is implemented in terms of multiple calls of
AsyncStream::async_read_some. So during any composed operation there are
multiple (>=1) completions of simple asynchronous operations each of those
has its own (intermediate) completion handler. Each of such intermediate
completion handlers is dispatched like bound completion handler
nous_operations.html) by the means of the same instance of asio::io_service
as AsyncStream provides.

So this code:
> async_write(socket, buffer(command.c_str()), &write_handler);
> io_service.reset();
> io_service.run_one();
will implement only one completions handler. That completion handler may be
the intermediate completion handler if async_write needs to make more than
one call to async_write_some (may be this needs to be explicitly described
in Boost.Asio documentation?). That is the reason why your write_handler is
not called sometimes.

May be this can solve the problem:
async_write(socket, buffer(command.c_str()), &write_handler);
async_read_until(socket, response, '\n', &read_handler);

Marat Abrarov.

Boost list run by bdawes at, gregod at, cpdaniel at, john at