注册用于提升io_service的每个对象的回调函数是什么?

What's the callback function for every object registered to boost io_service?

本文关键字:对象 回调 函数 是什么 注册 io service 用于      更新时间:2023-10-16

我们使用构造函数将一个对象注册到io_service:

boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));

以及如何指定此对象的回调函数?在boost io_service示例中,回调函数为:

t.async_wait(print);

但是,我们可以为t指定其他或多个回调函数吗?io_service如何知道哪个回调函数是正确的?

如果您查看timer.3和boost::asio中的以下示例,您将看到boost::bind和占位符的使用。这就是绑定回调函数的方式。每个async_wait只有一个回调函数。