Some clarifications required asynchronous operations and Boost asio timers.

There is one aspect of timers in asynchronous connections that I want to know if I understand correctly.

Suppose we set a timer before performing a read operation that includes a handler and then run()io_service.

As I understand it, io_service ends as soon as the manager ends after the call, which can happen for two reasons:

a) the read operation is complete.

b) the timer has reached its limit.

Assume that the first (a) condition is satisfied, and the read operation completed before the timer ends.

Question: what happens with this timer? Do I need to finish this. Let's say

dTimer_.expires_from_now (boost::posix_time::seconds(0));

after the io_service.run()?

Can you reset to a new interval, if necessary, reuse the same timer object for another read operation?

reset() io_service run() ?

+5
1

: ? ? .

, cancel it

void my_read_handler() {
     dTimer_.cancel(); // remember to catch exceptions
}

async_wait handler boost::asio::error::operation_aborted, . async_wait, cancel, io_service, .


reset , ?

deadline_timer reset expires_from_now

. . :: ASIO:: :: operation_aborted .


reset() io_service run() ?

io_service run() poll() .

run(), run_one(), poll() poll_one(), - io_service . io_service reset , "" .

+8

All Articles