[boost][asio] deadline_timer doesn't delays - async_wait invokes handler at once
Hello, I would like to add timeout to my server which is based on "http server 3" example. But I don't know why but I can't force deadline_timer to work properly. deadline_timer doesn't delays invoking of handler. please look how I modified source code of connection::start() in "http server 3" example. I did it according to suggestion placed on http://lists.boost.org/Archives/boost/2007/04/120339.php Could someone tell me what I.m doing wrong? tom void set_result(boost::optionalboost::system::error_code* a, boost::system::error_code b) { a->reset(b); } void connection::start() { boost::optionalboost::system::error_code timer_result; boost::asio::deadline_timer timer(socket_.io_service(),boost::posix_time::seconds(5)); timer.async_wait(boost::bind(set_result, &timer_result, _1)); boost::optionalboost::system::error_code read_result; socket_.async_read_some(boost::asio::buffer(buffer_), strand_.wrap( boost::bind(&connection::handle_read, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); socket_.io_service().reset(); while (socket_.io_service().run_one()) { if (read_result){ timer.cancel(); }else if(timer_result) { socket_.cancel(); } } if (*read_result) { throw boost::system::system_error(*read_result); } } ---------------------------------------------------- Pierwszy w Polsce profesjonalny serwis o modelkach! Zobacz zdjęcia, video i piękne kobiety. - Kliknij: http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Falemodelki.html&sid=626
boost::asio::deadline_timer timer(socket_.io_service(),boost::posix_time::seconds(5)); timer.async_wait(boost::bind(set_result, &timer_result, _1));
Does it work if you rewrite it as follows? boost::asio::deadline_timer timer(socket_.io_service()); timer.expires_from_now(boost::posix_time::seconds(5)); timer.async_wait(boost::bind(set_result, &timer_result, _1));
participants (2)
-
Igor R
-
tomasz jankowski