asio::basic_deadline_timer< Time, TimeTraits, TimerService > Class Template Reference

Provides waitable timer functionality. More...

#include <basic_deadline_timer.hpp>

Inheritance diagram for asio::basic_deadline_timer< Time, TimeTraits, TimerService >:

asio::basic_io_object< TimerService >

List of all members.

Public Types

typedef TimeTraits traits_type
 The time traits type.
typedef traits_type::time_type time_type
 The time type.
typedef traits_type::duration_type duration_type
 The duration type.

Public Member Functions

 basic_deadline_timer (asio::io_service &io_service)
 Constructor.
 basic_deadline_timer (asio::io_service &io_service, const time_type &expiry_time)
 Constructor to set a particular expiry time as an absolute time.
 basic_deadline_timer (asio::io_service &io_service, const duration_type &expiry_time)
 Constructor to set a particular expiry time relative to now.
std::size_t cancel ()
 Cancel any asynchronous operations that are waiting on the timer.
std::size_t cancel (asio::error_code &ec)
 Cancel any asynchronous operations that are waiting on the timer.
time_type expires_at () const
 Get the timer's expiry time as an absolute time.
std::size_t expires_at (const time_type &expiry_time)
 Set the timer's expiry time as an absolute time.
std::size_t expires_at (const time_type &expiry_time, asio::error_code &ec)
 Set the timer's expiry time as an absolute time.
duration_type expires_from_now () const
 Get the timer's expiry time relative to now.
std::size_t expires_from_now (const duration_type &expiry_time)
 Set the timer's expiry time relative to now.
std::size_t expires_from_now (const duration_type &expiry_time, asio::error_code &ec)
 Set the timer's expiry time relative to now.
void wait ()
 Perform a blocking wait on the timer.
void wait (asio::error_code &ec)
 Perform a blocking wait on the timer.
template<typename WaitHandler>
void async_wait (WaitHandler handler)
 Start an asynchronous wait on the timer.


Detailed Description

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
class asio::basic_deadline_timer< Time, TimeTraits, TimerService >

Provides waitable timer functionality.

The basic_deadline_timer class template provides the ability to perform a blocking or asynchronous wait for a timer to expire.

Most applications will use the asio::deadline_timer typedef.

Thread Safety
Distinct objects: Safe.
Shared objects: Unsafe.
See also:
Changing an active deadline_timer's expiry time
Examples
Performing a blocking wait:
 // Construct a timer without setting an expiry time.
 asio::deadline_timer timer(io_service);

 // Set an expiry time relative to now.
 timer.expires_from_now(boost::posix_time::seconds(5));

 // Wait for the timer to expire.
 timer.wait();
Performing an asynchronous wait:
 void handler(const asio::error_code& error)
 {
   if (!error)
   {
     // Timer expired.
   }
 }

 ...

 // Construct a timer with an absolute expiry time.
 asio::deadline_timer timer(io_service,
     boost::posix_time::time_from_string("2005-12-07 23:59:59.000"));

 // Start an asynchronous wait.
 timer.async_wait(handler);

Definition at line 82 of file basic_deadline_timer.hpp.


Member Typedef Documentation

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
typedef TimeTraits asio::basic_deadline_timer< Time, TimeTraits, TimerService >::traits_type

The time traits type.

Definition at line 87 of file basic_deadline_timer.hpp.

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
typedef traits_type::time_type asio::basic_deadline_timer< Time, TimeTraits, TimerService >::time_type

The time type.

Definition at line 90 of file basic_deadline_timer.hpp.

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
typedef traits_type::duration_type asio::basic_deadline_timer< Time, TimeTraits, TimerService >::duration_type

The duration type.

Definition at line 93 of file basic_deadline_timer.hpp.


Constructor & Destructor Documentation

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
asio::basic_deadline_timer< Time, TimeTraits, TimerService >::basic_deadline_timer ( asio::io_service io_service  )  [inline, explicit]

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.

Parameters:
io_service The io_service object that the timer will use to dispatch handlers for any asynchronous operations performed on the timer.

Definition at line 104 of file basic_deadline_timer.hpp.

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
asio::basic_deadline_timer< Time, TimeTraits, TimerService >::basic_deadline_timer ( asio::io_service io_service,
const time_type expiry_time 
) [inline]

Constructor to set a particular expiry time as an absolute time.

This constructor creates a timer and sets the expiry time.

Parameters:
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.

Definition at line 119 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, asio::basic_io_object< TimerService >::service, and asio::detail::throw_error().

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
asio::basic_deadline_timer< Time, TimeTraits, TimerService >::basic_deadline_timer ( asio::io_service io_service,
const duration_type expiry_time 
) [inline]

Constructor to set a particular expiry time relative to now.

This constructor creates a timer and sets the expiry time.

Parameters:
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.

Definition at line 138 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, asio::basic_io_object< TimerService >::service, and asio::detail::throw_error().


Member Function Documentation

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
std::size_t asio::basic_deadline_timer< Time, TimeTraits, TimerService >::cancel (  )  [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 asio::error::operation_aborted error code.

Cancelling the timer does not change the expiry time.

Returns:
The number of asynchronous operations that were cancelled.
Exceptions:
asio::system_error Thrown on failure.

Definition at line 159 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, simple_client::s, asio::basic_io_object< TimerService >::service, and asio::detail::throw_error().

Referenced by libtorrent::timeout_handler::cancel().

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
std::size_t asio::basic_deadline_timer< Time, TimeTraits, TimerService >::cancel ( asio::error_code ec  )  [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 asio::error::operation_aborted error code.

Cancelling the timer does not change the expiry time.

Parameters:
ec Set to indicate what error occurred, if any.
Returns:
The number of asynchronous operations that were cancelled.

Definition at line 179 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, and asio::basic_io_object< TimerService >::service.

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
time_type asio::basic_deadline_timer< Time, TimeTraits, TimerService >::expires_at (  )  const [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.

Definition at line 189 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, and asio::basic_io_object< TimerService >::service.

Referenced by libtorrent::timeout_handler::set_timeout(), and libtorrent::timeout_handler::timeout_callback().

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
std::size_t asio::basic_deadline_timer< Time, TimeTraits, TimerService >::expires_at ( const time_type expiry_time  )  [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 asio::error::operation_aborted error code.

See Changing an active deadline_timer's expiry time for more information on altering the expiry time of an active timer.

Parameters:
expiry_time The expiry time to be used for the timer.
Returns:
The number of asynchronous operations that were cancelled.
Exceptions:
asio::system_error Thrown on failure.

Definition at line 209 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, simple_client::s, asio::basic_io_object< TimerService >::service, and asio::detail::throw_error().

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
std::size_t asio::basic_deadline_timer< Time, TimeTraits, TimerService >::expires_at ( const time_type expiry_time,
asio::error_code ec 
) [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 asio::error::operation_aborted error code.

See Changing an active deadline_timer's expiry time for more information on altering the expiry time of an active timer.

Parameters:
expiry_time The expiry time to be used for the timer.
ec Set to indicate what error occurred, if any.
Returns:
The number of asynchronous operations that were cancelled.

Definition at line 233 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, and asio::basic_io_object< TimerService >::service.

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
duration_type asio::basic_deadline_timer< Time, TimeTraits, TimerService >::expires_from_now (  )  const [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.

Definition at line 244 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, and asio::basic_io_object< TimerService >::service.

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
std::size_t asio::basic_deadline_timer< Time, TimeTraits, TimerService >::expires_from_now ( const duration_type expiry_time  )  [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 asio::error::operation_aborted error code.

See Changing an active deadline_timer's expiry time for more information on altering the expiry time of an active timer.

Parameters:
expiry_time The expiry time to be used for the timer.
Returns:
The number of asynchronous operations that were cancelled.
Exceptions:
asio::system_error Thrown on failure.

Definition at line 264 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, simple_client::s, asio::basic_io_object< TimerService >::service, and asio::detail::throw_error().

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
std::size_t asio::basic_deadline_timer< Time, TimeTraits, TimerService >::expires_from_now ( const duration_type expiry_time,
asio::error_code ec 
) [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 asio::error::operation_aborted error code.

See Changing an active deadline_timer's expiry time for more information on altering the expiry time of an active timer.

Parameters:
expiry_time The expiry time to be used for the timer.
ec Set to indicate what error occurred, if any.
Returns:
The number of asynchronous operations that were cancelled.

Definition at line 288 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, and asio::basic_io_object< TimerService >::service.

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
void asio::basic_deadline_timer< Time, TimeTraits, TimerService >::wait (  )  [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.

Exceptions:
asio::system_error Thrown on failure.

Definition at line 302 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, asio::basic_io_object< TimerService >::service, and asio::detail::throw_error().

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
void asio::basic_deadline_timer< Time, TimeTraits, TimerService >::wait ( asio::error_code ec  )  [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.

Parameters:
ec Set to indicate what error occurred, if any.

Definition at line 316 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, and asio::basic_io_object< TimerService >::service.

template<typename Time, typename TimeTraits = asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>>
template<typename WaitHandler>
void asio::basic_deadline_timer< Time, TimeTraits, TimerService >::async_wait ( WaitHandler  handler  )  [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:

  • The timer has expired.
Parameters:
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:
 void handler(
   const asio::error_code& error // Result of operation.
 ); 
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 asio::io_service::post().

Definition at line 346 of file basic_deadline_timer.hpp.

References asio::basic_io_object< TimerService >::implementation, and asio::basic_io_object< TimerService >::service.

Referenced by libtorrent::timeout_handler::set_timeout(), and libtorrent::timeout_handler::timeout_callback().


The documentation for this class was generated from the following file:

Generated on Sun May 25 00:21:26 2008 by  doxygen 1.5.6