Boost logo

Boost Users :

Subject: [Boost-users] boost asio async_read_some
From: Chris Freehill (cfreehill_at_[hidden])
Date: 2008-12-03 19:52:12


Hi,

I've been struggling for a while trying to get async_read_some() to
call the handler I provided, but it never seems to happen. However,
the buffer provided does seem to be written with the expected data
from the tcp/ip socket I'm using.

Here's a simplified version of my call and handler:

unsigned char tmpBuffer[512]; //global

void MyClass::handler(const boost::system::error_code& error, size_t
bytes_transferred)
{
               boost::system::error_code e;
               std::cerr << "handler called()" << "\n";
}

void MyClass::test()
{

...
       socketPtr->async_read_some(boost::asio::buffer(tmpBuffer, 512),
                             boost::bind(&MyClass::handler, this,
                                       boost::asio::placeholders::error,

boost::asio::placeholders::bytes_transferred));
}

Can anyone give me any idea as to how I can get my handler to be called?

The other thing worth mentioning is that if I use read_some() instead,
I get the expected data.

In the documentation for this method (see link below),
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/reference/basic_stream_socket/async_read_some.html

there is the comment "Regardless of whether the asynchronous operation
completes immediately or not, the handler will not be invoked from
within this function. Invocation of the handler will be performed in a
manner equivalent to using boost::asio::io_service::post()." I'm not
sure exactly what this means...what is this equivalent manner that is
mentioned?

Thanks,

Chris


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