|
cppnet
C++ network utilities for asynchronous servers.
|
Provides event-loop timers. More...
#include <net/timers/timers.hpp>
Public Types | |
| using | interrupt_type = interrupt< Interrupt > |
| The base interrupt type. | |
Public Types inherited from net::timers::interrupt< Interrupt > | |
| using | interrupt_source_t = Source |
| The underlying interrupt source type. | |
Public Member Functions | |
| timers ()=default | |
| Default constructor. | |
| timers (const timers &other)=delete | |
| Deleted copy constructor. | |
| timers (timers &&other) noexcept | |
| Move constructor. | |
| auto | operator= (const timers &other)=delete |
| Deleted copy assignment. | |
| auto | operator= (timers &&other) noexcept -> timers & |
| Move assignment. | |
| auto | add (timestamp when, handler_t handler, duration period=duration::zero()) -> timer_id |
| Add a new timer. | |
| template<class Rep , class Period > | |
| auto | add (std::chrono::duration< Rep, Period > when, handler_t handler, duration period=duration::zero()) -> timer_id |
Overloaded add function that uses a std::chrono::duration instead of a time_point for the first timeout. | |
| auto | add (std::uint64_t when, handler_t handler, std::uint64_t period=0) -> timer_id |
Overloaded add function that uses a uint64_t instead of a time_point for the first timeout and the period. | |
| auto | remove (timer_id tid) noexcept -> timer_id |
| Removes the timer with the given id. | |
| auto | resolve () -> duration |
| Resolves all expired event handles. | |
| ~timers ()=default | |
| Default destructor. | |
Public Member Functions inherited from net::timers::interrupt< Interrupt > | |
| auto | operator() () const noexcept -> void |
| Calls the underlying interrupt. | |
Friends | |
| template<InterruptSource I> | |
| auto | swap (timers< I > &lhs, timers< I > &rhs) noexcept -> void |
| Swap function. | |
Provides event-loop timers.
| Interrupt | An interrupt source that satisfies the InterruptSource concept. |
timers is the spritual successor to cpptime and has been modified for integration with the cppnet context_thread event-loop. As such, it exposes the same API as a CppTime::Timer for adding and removing timers. Unlike a CppTime::Timer, timers does not execute the timer callbacks in a separate thread. Instead, to resolve the timer event callbacks an event loop must explicitly call the public resolve method. The resolve method return a std::chrono duration until the next event timeout. If there are no more events in the internal event queue, then the resolve method returns duration(-1), otherwise the returned duration contains a strictly non-negative count.
| auto net::timers::timers< Interrupt >::add | ( | std::chrono::duration< Rep, Period > | when, |
| handler_t | handler, | ||
| duration | period = duration::zero() |
||
| ) | -> timer_id |
Overloaded add function that uses a std::chrono::duration instead of a time_point for the first timeout.
| Rep | The arithmetic tick type for a std::chrono::duration. |
| Period | The std::ratio of a std::chrono::duration. |
| when | The time until the timer times out. |
| handler | The timer event handler. |
| period | The time between events for a periodic timer. |
| auto net::timers::timers< Interrupt >::add | ( | std::uint64_t | when, |
| handler_t | handler, | ||
| std::uint64_t | period = 0 |
||
| ) | -> timer_id |
Overloaded add function that uses a uint64_t instead of a time_point for the first timeout and the period.
| when | The number of microseconds until the event times out. |
| handler | The event handler. |
| period | The number of microseconds between events for a periodic timer. |
| auto net::timers::timers< Interrupt >::add | ( | timestamp | when, |
| handler_t | handler, | ||
| duration | period = duration::zero() |
||
| ) | -> timer_id |
Add a new timer.
| when | The time at which the handler is invoked. |
| handler | The callable that is invoked when the timer fires. |
| period | The periodicity at which the timer fires. Only used for periodic timers. |
|
noexcept |
Removes the timer with the given id.
| tid | The timer_id to remove. |
remove is designed to be used in a self-assignment statement. When the timer has been disarmed, the original timer_id will be cleared to an INVALID state. This minimizes the risk of calling remove on a timer twice.
| auto net::timers::timers< Interrupt >::resolve | ( | ) | -> duration |
Resolves all expired event handles.
duration(-1) if the internal eventq is empty.