Hello, Allan,
Using boost::asio::io_service::stop() member function, you can
cancel/interrupt other handlers. The following code show that only one
handler (rather than 3 ones) would be executed:
#include <iostream>
#include
Hi
Is this a bug, or am I doing something wrong?
#include <iostream> #include
#include 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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users