Boost::asio async_read doesn't receive data or doesn't use callback?

Boost::asio::service::run () is a blocking call. Now, in your example it may or may not return immediately. In case it doesn't, you you are blocked even before you create a socket, and never call read, so cannot expect a callback.

Otherwise, dispatch loop is exited, so no callbacks are ever delivered.

Boost::asio::service::run () is a blocking call. Now, in your example it may or may not return immediately. In case it doesn't, you you are blocked even before you create a socket, and never call read, so cannot expect a callback.

Otherwise, dispatch loop is exited, so no callbacks are ever delivered. Read more about boost::asio::service::run (). I recommend you check out documentation including tutorial, examples and reference.It is worth going trough it in full to understand the concept.

Hope it helps! P.S.: On a side note, your code is not exception safe. Beware that if constructor of the class fails with exception then destructor of that class instance is never called.

Thus, you may leak at least m_pSocket if its type is not one of the "smart pointers". You should consider making it exception safe, moving the code to another method that should be called by user, or even wrapping this functionality with a free function.

1 this is an important concept to understand when using Boost.Asio. You need to ensure the io_service has some work to do prior to invoking io_service::run(). – Sam Miller Oct 15 at 17:49 +1 for advice to read the docs and the tutorials.

Just about everything you need is in there. – Sean Oct 15 at 18:31 Thanks, I moved the call to run() after the call to async_read and it works now. I'm pretty sure I tried this before but I might have made another mistake at that time.

If I understood correctly, the callback qlso needs to call async_read before it returns so the io_service doesn't stop. As for the exception safety, the code isn't exactly like this in reality, I just summarized several functions in order to make it shorter and easily readable. – Jukurrpa Oct 17 at 13:05.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions