Trying to replace my boost :: asio :: read with boost :: asio :: async_read

So, the code I started with and which works (with important caveats below)

int reply_length = boost::asio::read(*m_socketptr, boost::asio::buffer((char*)reply, 6));

This works, I get a header, which I then decodes and tracks with another read that receives my message, and then I go back to the top and read another header. This binds my processor to 100%, so I want to replace the header read above with something like the following:

m_socketptr->async_read_some(boost::asio::buffer(m_data, 6), boost::bind(&CSListener::handleRead, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));

or

boost::asio::async_read(*m_socketptr, boost::asio::buffer(m_data, 6), boost::bind(&CSListener::handleRead, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));

In any case, I encode it, the handleRead method is never called. Help!

TIA

+3
source share
1 answer

, io_service - ? io_service.run() io_service.run_one() . , , run_one() ; /.

+8

Source: https://habr.com/ru/post/1758249/


All Articles