boost asio async_read_some

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_str... 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

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?
Could you please provide some code-excerpt that should compile and work? I.e. code that contains socket initialization, io_service run and your object creation - because the mistake is probably somewhere at those points.
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?
It means that the handler would be invoked in one of the threads that run the io_service object used by the socked.
participants (2)
-
Chris Freehill
-
Igor R