Boost Asio async_wait handler

The boost asio function deadline_timer async_waitaccepts a form handler:

void handler(const boost::system::error_code& error)

How can I define a handler that accepts const boost::system::error_code& erroras well as a type argument int?

boost::asio::deadline_timer t(io_service);

t.async_wait(handler); //I need the async_wait to take in handler which accepts argument boost::system::error_code& error and an int 

void handler(int, const boost::system::error_code& error )//extra int argument

Thank.

+3
source share
1 answer

You can use Boost.Bind to provide a value for the first argument:

t.async_wait(boost::bind(handler, 0, _1));

Here, the handler will be called with 0 as the first argument, and error_codewill simply be redirected as the second argument.

+4
source

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


All Articles