您的位置:首页 > 运维架构 > Linux

Boost中timer的简易用法

2013-06-25 15:50 330 查看


boost::asio::deadline_timer timer_;

timer_(io_service),

timer_.expires_from_now(boost::posix_time::seconds(1));
timer_.async_wait(
boost::bind(&sender::handle_timeout, this,
boost::asio::placeholders::error));

void handle_timeout(const boost::system::error_code& error)
{
if (!error)
{
timer_.expires_from_now(boost::posix_time::seconds(1));
timer_.async_wait(
boost::bind(&sender::handle_timeout, this,
boost::asio::placeholders::error));
/*Insert Your Functions*/

}
}

在你所用的类中声明一个boost 的timer 见第一句话,

初始化这个timer 第二句话,

第三句,第四句话,使timer正常的工作起来。

后面的的timer的时间到后,的执行程序。

执行程序中,进行了迭代,可以再次计时,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Boost C++ Linux 编程 timer