Skip to content

Instantly share code, notes, and snippets.

@HungMingWu
Created February 20, 2019 08:05
Show Gist options
  • Save HungMingWu/75bef528561d27d5f936728dcbabf2ed to your computer and use it in GitHub Desktop.
Save HungMingWu/75bef528561d27d5f936728dcbabf2ed to your computer and use it in GitHub Desktop.
Write my own custom asio async function
#include <boost/system/error_code.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
template<
class ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(
ReadHandler, void(boost::system::error_code, std::size_t))
async_read(ReadHandler&& handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a ReadHandler.
BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check;
boost::asio::async_completion<ReadHandler,
void(boost::system::error_code, std::size_t)> init(handler);
return init.result.get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment