James -

    I'm sure others can better explain the internal reasons "why"- (I believe you are enqueing work to the proactor).
        http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/design/async.html

    On the "how", you are correct.  If you look at the examples, you have to enque operations in your async (read_callback).
        http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/examples.html
        http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/example/http/client/async_client.cpp <- as well as the other async examples

   Typically I do the following, which I gleened from the examples:
       async_read_some ()
       check if message is complete
       if so notify() listener(s)
       async_read_some()
  
Cheers,
Tim  



On Wed, Jul 2, 2008 at 7:11 AM, James Vanns <james.vanns@framestore.com> wrote:
Hi, I don't quite understand how to register an async call back once with an IO service? Consider this model:

* Server accepts connection
* connection object *registers* it's read callback (to be executed whenever there is a
 read available from the underlying epoll)
* connection object is doing some processing or conversing with the main server etc.
* epoll (or IO service) says there is data to be read
* call back gets executed
* the processing resumes (based on the newly received data)

I'm prettu sure that is normal. But how do I actually achieve this with ASIO? I mean, I have the main server that runs io_service::run() so it knows when there is data to be read on a socket - that socket is of course associated with this client connection object and it is this object that acts on the data (and may also send of course). However, using the async_read methods I appear to have to keep re-registering the callback in the actual callback:

client::register_read_callback()
{
   m_socket.async_read_some(buffer(m_inbound, p_max),
                            boost::bind(&base_io::read_callback,
                                        shared_from_this(),
                                        placeholders::error,
                                        placeholders::bytes_transferred));

}

client::read_callback(error_code &ec, size_t bytes)
{
  // I have to call register_read_callback() again here!
}

client::start() // I get called when I am established between two endpoints
{
  register_read_callback();
  do_some_processing();
}

client::do_some_processing()
{
}

I'm trying to build a library that transparently buffers messages received from an endpoint. THe library silently receives the data (through the epoll based io service and the asio tcp sockets), builds the messages from the received data and puts them in a stack ready to be poppped off by an application calling pop_msg().

I'm having difficulty in separating these two operations.

Regards,

Jim Vanns

--
James Vanns
Systems Programmer
Framestore CFC Ltd.
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users



--
Regards,
Timothy St. Clair
[timothysc@gmail.com]