Best example asio deadline_timer

I am after the best example of boost::asio::deadline_timer

The above examples will always be absent and call the close method. I tried calling cancel() on a timer, but this calls an immediate call to the function passed to async_wait .

What is the correct way to work with timers in an async tcp client?

+6
c ++ timer boost-asio
source share
1 answer

You mentioned that calling the cancel () function on a timer causes an immediate call to the function passed to async_wait. This is expected behavior, but remember that you can check the error passed to the timer handler to determine if the timer has been canceled. If the timer has been canceled, abort_operation is sent. For example:

 void handleTimer(const boost::system::error_code& error) { if (error == boost::asio::error::operation_aborted) { std::cout << "Timer was canceled" << std::endl; } else if (error) { std::cout << "Timer error: " << error.message() << std::endl; } } 

Hope this helps. If not, what is the specific example you are looking for?

+20
source share

All Articles