我有以下(最小化)类处理我的服务器连接:
class AsioServer {
protected:
boost::asio::io_service ioService;
public:
AsioServer() {}
void add_request() {
//Adding async requests to the ioService
}
void timeout() {
//Stop all pedning async operations
ioService.stop();
}
void perform() {
//Set a timer
boost::asio::deadline_timer timer(ioService);
timer.expires_from_now(boost::posix_time::seconds(5));
timer.async_wait(std::bind(&AsioServer::timeout, this));
//Performe all Async operations
ioService.run();
ioService.reset();
}
};
我的问题是截止日期计时器阻止返回,ioService.run()
直到它到期。我想要的是计时器仅在体验然后取消异步操作时才被调用,而不是work
在io_service
. 是否有计时器不作为工作,或者处理这种情况的另一种好方法?