Re: [asio-users] Problem with deadline timer and async connect interaction
Brought to you by:
chris_kohlhoff
From: Christopher K. <ch...@ko...> - 2009-08-10 12:10:08
|
Zachary Turner wrote: > void accept_connections() > { > service_ptr peer_service(new io_service()); > socket_ptr peer_socket(new tcp::socket(*peer_service)); > > acceptor_.async_accept(*peer_socket, > boost::bind(&accept_handler::handle_accept, this, peer_service, > peer_socket, placeholders::error)); > > timer_.expires_from_now(boost::posix_time::seconds(3)); When you call expires_from_now(), it will cancel any existing timer operations. They will complete with asio::error::operation_aborted. As written, your timer_expired() function will simply shut everything down. > timer_.async_wait(boost::bind(&accept_handler::timer_expired, > this, placeholders::error)); > } Maybe it would be cleaner to have two distinct chains of async operations: accept_connections() -> async_accept() --> handle_accept() -> accept_connections() -> async_accept() --> handle_accept() ... and async_wait() --> timer_expired() -> async_wait() --> timer_expired() ... both started from the constructor. That is, don't touch the timer at all in the first chain. Cheers, Chris |