user10444601
user10444601

Reputation:

Asio async handler is never called, no other handler invoked

I have a asio sync connection. ioService is in one thread (I have only one thread.).

Smaller problem:

boost::asio::async_write(m_socket, boost::asio::buffer(requestStr.data(), requestStr.size()), handler);

The handler is never called, but the server gets it and replies that I get.

The bigger problem:

boost::asio::async_read_until(m_socket, sbuf, '\n', sendingHandler);

It also doesn't call the handler. The sbuf is immediately filled and I can read it there, but I don't know the position of the deliminator. Therefore I need the handler to get the bytes_transferred parameter. (I'm not going to iterate the buffer.)

I tried several things and I could invoke the handler once, but I don't remember what the issue was about after a small refract. Any help? Thanks!

When I used sync messaging, everything was fine, but there is no timeout there.

EDIT: If you know any nice solution to find the deliminator I don't need the handler. Because, I would send the msg sync_write and read async.

Upvotes: 0

Views: 411

Answers (1)

grapes
grapes

Reputation: 8636

It wont be called, because it is async. Async methods for writing and reading never call handlers from within the place they're called:

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().

You need to manually call io_service methods like run or run_once to perform operations and that is the moment when your callback will be called.

Upvotes: 0

Related Questions