Boost Asio async_wait handler

时间秒杀一切 提交于 2019-12-12 14:07:43

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4426802/boost-asio-async-wait-handler

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!