|
Boost Users : |
Subject: [Boost-users] Boost asio deadline_timer, bug?
From: Allan Nielsen (a_at_[hidden])
Date: 2011-08-19 03:25:53
Hi
Is this a bug, or am I doing something wrong?
#include <iostream>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
using namespace std;
using namespace boost::asio;
struct A {
A(io_service & service) : timer1(service), timer2(service) {
timer1.expires_from_now( boost::posix_time::seconds(5) );
timer1.async_wait(boost::bind(&A::handler, this, _1));
timer2.expires_from_now( boost::posix_time::seconds(2) );
timer2.async_wait(boost::bind(&A::interrupt, this, _1));
}
void handler(const boost::system::error_code &ec) {
cout << "Forbidden handler" << endl;
assert(0);
}
void handler_interrupted(const boost::system::error_code &ec) {
cout << "Hello world" << endl;
}
void interrupt(const boost::system::error_code &ec) {
cout << "Interrupted" << endl;
int res = timer1.cancel();
assert(res > 0);
timer1.expires_from_now( boost::posix_time::milliseconds(0) );
timer1.async_wait(boost::bind(&A::handler_interrupted, this, _1));
}
int count, max, timeout1, timeout2;
deadline_timer timer1;
deadline_timer timer2;
};
int main() {
io_service service;
A a(service);
service.run();
return 0;
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net