0

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.

Depp
  • 35
  • 7

1 Answers1

1

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.

grapes
  • 8,185
  • 1
  • 19
  • 31