Provides waitable timer functionality. More...
#include <basic_waitable_timer.hpp>
Public Types | |
typedef Clock | clock_type |
The clock type. More... | |
typedef clock_type::duration | duration |
The duration type of the clock. More... | |
typedef clock_type::time_point | time_point |
The time point type of the clock. More... | |
typedef WaitTraits | traits_type |
The wait traits type. More... | |
typedef WaitableTimerService | service_type |
The type of the service that will be used to provide I/O operations. More... | |
typedef service_type::implementation_type | implementation_type |
The underlying implementation type of I/O object. More... | |
Public Member Functions | |
basic_waitable_timer (boost::asio::io_service &io_service) | |
Constructor. More... | |
basic_waitable_timer (boost::asio::io_service &io_service, const time_point &expiry_time) | |
Constructor to set a particular expiry time as an absolute time. More... | |
basic_waitable_timer (boost::asio::io_service &io_service, const duration &expiry_time) | |
Constructor to set a particular expiry time relative to now. More... | |
std::size_t | cancel () |
Cancel any asynchronous operations that are waiting on the timer. More... | |
std::size_t | cancel (boost::system::error_code &ec) |
Cancel any asynchronous operations that are waiting on the timer. More... | |
std::size_t | cancel_one () |
Cancels one asynchronous operation that is waiting on the timer. More... | |
std::size_t | cancel_one (boost::system::error_code &ec) |
Cancels one asynchronous operation that is waiting on the timer. More... | |
time_point | expires_at () const |
Get the timer's expiry time as an absolute time. More... | |
std::size_t | expires_at (const time_point &expiry_time) |
Set the timer's expiry time as an absolute time. More... | |
std::size_t | expires_at (const time_point &expiry_time, boost::system::error_code &ec) |
Set the timer's expiry time as an absolute time. More... | |
duration | expires_from_now () const |
Get the timer's expiry time relative to now. More... | |
std::size_t | expires_from_now (const duration &expiry_time) |
Set the timer's expiry time relative to now. More... | |
std::size_t | expires_from_now (const duration &expiry_time, boost::system::error_code &ec) |
Set the timer's expiry time relative to now. More... | |
void | wait () |
Perform a blocking wait on the timer. More... | |
void | wait (boost::system::error_code &ec) |
Perform a blocking wait on the timer. More... | |
template<typename WaitHandler > | |
BOOST_ASIO_INITFN_RESULT_TYPE (WaitHandler, void(boost::system::error_code)) async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler) | |
Start an asynchronous wait on the timer. More... | |
boost::asio::io_service & | get_io_service () |
Get the io_service associated with the object. More... | |
Protected Member Functions | |
service_type & | get_service () |
Get the service associated with the I/O object. More... | |
const service_type & | get_service () const |
Get the service associated with the I/O object. More... | |
implementation_type & | get_implementation () |
Get the underlying implementation of the I/O object. More... | |
const implementation_type & | get_implementation () const |
Get the underlying implementation of the I/O object. More... | |
Protected Attributes | |
service_type & | service |
(Deprecated: Use get_service().) The service associated with the I/O object. More... | |
implementation_type | implementation |
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. More... | |
Provides waitable timer functionality.
The basic_waitable_timer class template provides the ability to perform a blocking or asynchronous wait for a timer to expire.
A waitable timer is always in one of two states: "expired" or "not expired". If the wait() or async_wait() function is called on an expired timer, the wait operation will complete immediately.
Most applications will use one of the boost::asio::steady_timer, boost::asio::system_timer or boost::asio::high_resolution_timer typedefs.
<chrono>
facility, or with the Boost.Chrono library.Changing the expiry time of a timer while there are pending asynchronous waits causes those wait operations to be cancelled. To ensure that the action associated with the timer is performed only once, use something like this: used:
typedef Clock boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::clock_type |
The clock type.
typedef clock_type::duration boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::duration |
The duration type of the clock.
|
inherited |
The underlying implementation type of I/O object.
|
inherited |
The type of the service that will be used to provide I/O operations.
typedef clock_type::time_point boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::time_point |
The time point type of the clock.
typedef WaitTraits boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::traits_type |
The wait traits type.
|
inlineexplicit |
Constructor.
This constructor creates a timer without setting an expiry time. The expires_at() or expires_from_now() functions must be called to set an expiry time before the timer can be waited on.
io_service | The io_service object that the timer will use to dispatch handlers for any asynchronous operations performed on the timer. |
|
inline |
Constructor to set a particular expiry time as an absolute time.
This constructor creates a timer and sets the expiry time.
io_service | The io_service object that the timer will use to dispatch handlers for any asynchronous operations performed on the timer. |
expiry_time | The expiry time to be used for the timer, expressed as an absolute time. |
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Constructor to set a particular expiry time relative to now.
This constructor creates a timer and sets the expiry time.
io_service | The io_service object that the timer will use to dispatch handlers for any asynchronous operations performed on the timer. |
expiry_time | The expiry time to be used for the timer, relative to now. |
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Start an asynchronous wait on the timer.
This function may be used to initiate an asynchronous wait against the timer. It always returns immediately.
For each call to async_wait(), the supplied handler will be called exactly once. The handler will be called when:
handler | The handler to be called when the timer expires. Copies will be made of the handler as required. The function signature of the handler must be: Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using boost::asio::io_service::post(). |
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Cancel any asynchronous operations that are waiting on the timer.
This function forces the completion of any pending asynchronous wait operations against the timer. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.
Cancelling the timer does not change the expiry time.
boost::system::system_error | Thrown on failure. |
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, boost::asio::s, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Cancel any asynchronous operations that are waiting on the timer.
This function forces the completion of any pending asynchronous wait operations against the timer. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.
Cancelling the timer does not change the expiry time.
ec | Set to indicate what error occurred, if any. |
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Cancels one asynchronous operation that is waiting on the timer.
This function forces the completion of one pending asynchronous wait operation against the timer. Handlers are cancelled in FIFO order. The handler for the cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.
Cancelling the timer does not change the expiry time.
boost::system::system_error | Thrown on failure. |
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, boost::asio::s, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Cancels one asynchronous operation that is waiting on the timer.
This function forces the completion of one pending asynchronous wait operation against the timer. Handlers are cancelled in FIFO order. The handler for the cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.
Cancelling the timer does not change the expiry time.
ec | Set to indicate what error occurred, if any. |
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Get the timer's expiry time as an absolute time.
This function may be used to obtain the timer's current expiry time. Whether the timer has expired or not does not affect this value.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Set the timer's expiry time as an absolute time.
This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.
expiry_time | The expiry time to be used for the timer. |
boost::system::system_error | Thrown on failure. |
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, boost::asio::s, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Set the timer's expiry time as an absolute time.
This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.
expiry_time | The expiry time to be used for the timer. |
ec | Set to indicate what error occurred, if any. |
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Get the timer's expiry time relative to now.
This function may be used to obtain the timer's current expiry time. Whether the timer has expired or not does not affect this value.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Set the timer's expiry time relative to now.
This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.
expiry_time | The expiry time to be used for the timer. |
boost::system::system_error | Thrown on failure. |
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, boost::asio::s, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Set the timer's expiry time relative to now.
This function sets the expiry time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.
expiry_time | The expiry time to be used for the timer. |
ec | Set to indicate what error occurred, if any. |
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inlineprotectedinherited |
Get the underlying implementation of the I/O object.
|
inlineprotectedinherited |
Get the underlying implementation of the I/O object.
|
inlineinherited |
Get the io_service associated with the object.
This function may be used to obtain the io_service object that the I/O object uses to dispatch handlers for asynchronous operations.
|
inlineprotectedinherited |
Get the service associated with the I/O object.
|
inlineprotectedinherited |
Get the service associated with the I/O object.
|
inline |
Perform a blocking wait on the timer.
This function is used to wait for the timer to expire. This function blocks and does not return until the timer has expired.
boost::system::system_error | Thrown on failure. |
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
inline |
Perform a blocking wait on the timer.
This function is used to wait for the timer to expire. This function blocks and does not return until the timer has expired.
ec | Set to indicate what error occurred, if any. |
References boost::asio::basic_io_object< WaitableTimerService >::implementation, and boost::asio::basic_io_object< WaitableTimerService >::service.
|
protectedinherited |
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object.
Referenced by boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::basic_waitable_timer(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::BOOST_ASIO_INITFN_RESULT_TYPE(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::cancel(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::cancel_one(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::expires_at(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::expires_from_now(), and boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::wait().
|
protectedinherited |
(Deprecated: Use get_service().) The service associated with the I/O object.
Referenced by boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::basic_waitable_timer(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::BOOST_ASIO_INITFN_RESULT_TYPE(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::cancel(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::cancel_one(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::expires_at(), boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::expires_from_now(), and boost::asio::basic_waitable_timer< Clock, WaitTraits, WaitableTimerService >::wait().