Thanks for the response Marat.
There are lots of things I do not explain here - let me list them down:
1. same code works in boost 1.44 - the async-write and epoll work
exactly as i expect them to. I have run these pieces with 1.44 1000s of
times, and never had a need to execute run_one to get data multiple times.
2. the quantum of data i am looking at is <30 bytes
3. the socket in my code is not a busy one at all - exchanges 10-30
bytes only once in a while
4. Marat's code is using io_service.run - why should I not be using
run_one?
5. with boost 1.44 the completion handler would get called from the same
thread after i invoke run_one. I debugged boost headers. With 1.53 that's
not the case - the streambuf does have the data but the completion handler
is not getting called.
6. same code works fine with select but not epoll.
Any thoughts on debugging or setting epoll options from asio interface to
see what is going on?
On Fri, May 24, 2013 at 3:17 PM, Marat Abrarov
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 operations ( http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/async_re ad/overload1.htmlhttp://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/async_re%... ): ... 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 ( http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/asynchro nous_operations.htmlhttp://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/reference/asynchro%...) by the means of the same instance of asio::io_service as AsyncStream provides.
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
So this code: 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); io_service.reset(); io_service.run(); async_read_until(socket, response, '\n', &read_handler); io_service.reset(); io_service.run();
Regards, Marat Abrarov.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Regards, Arpan ----------------------------------------------------------------------------------------------------------------- Reality is merely an illusion, albeit a very persistent one.