Steveng
Steveng

Reputation: 2465

Boost Asio async_wait handler

The boost asio deadline_timer async_wait function is taking handler of the form :

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

How could I define a handler which takes in const boost::system::error_code& error and also an argument of type 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

Thanks.

Upvotes: 3

Views: 2976

Answers (1)

icecrime
icecrime

Reputation: 76745

You could 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 a 0 as its first argument and the error_code will simply be forwarded as a second argument.

Upvotes: 4

Related Questions