Template Class timed_base

Nested Relationships

Inheritance Relationships

Derived Types

Class Documentation

template<typename Clock>
class stream_client::detail::timed_base

Base class with timeout handling.

This class implements basic setup/reset for internal timer instance. Instances of this class own boost::asio::io_service and boost::asio::basic_waitable_timer via std::unique_ptr. Inherited classes should implement deadline_actor() which is called when timer goes off.

Note

This class does neither run nor poll its’ io_service, it is up to descendants.

tparam Clock

type of clock to use, see boost::asio::basic_waitable_timer

Subclassed by stream_client::resolver::base_resolver< protocol_type >, stream_client::base_socket< boost::asio::basic_datagram_socket< Protocol > >, stream_client::base_socket< boost::asio::basic_stream_socket< Protocol > >, stream_client::base_socket< Socket >, stream_client::resolver::base_resolver< Protocol >

Public Types

using clock_type = Clock
using time_duration_type = typename clock_type::duration
using time_point_type = typename clock_type::time_point
using timer_type = typename boost::asio::basic_waitable_timer<clock_type>

Public Functions

inline timed_base()

Default constructor.

timed_base(const timed_base<Clock> &other) = delete

Copy constructor is not permitted.

timed_base<Clock> &operator=(const timed_base<Clock> &other) = delete

Copy assignment is not permitted.

timed_base(timed_base<Clock> &&other) = default

Move constructor.

timed_base &operator=(timed_base<Clock> &&other) = default

Move assignment.

inline virtual ~timed_base()

Destructor.

inline boost::asio::io_service &get_io_service()

Non-const accessor to owned boost::asio::io_service.

inline const boost::asio::io_service &get_io_service() const

Const accessor to owned boost::asio::io_service.

template<typename Time>
inline expiration scope_expire(const Time &timeout_or_deadline)

Setup expiration and return its’ handler.

Template Parameters

Time – Type of timeout_or_deadline, either time_duration_type or time_point_type.

Parameters

[in] timeout_or_deadline – Expiration time-point.

Returns

expiration RAII-complaint expiration handler - reset timer on destruction

Public Static Attributes

static constexpr time_duration_type kInfiniteDuration = time_duration_type::max()

Indefinite duration.

static constexpr time_duration_type kZeroDuration = time_duration_type(0)

Zero span duration.

static constexpr time_duration_type kDurationResolution = time_duration_type(1000)

Minimal resolvable duration (anything else may be less than timeout setup overhead)

static constexpr time_duration_type kMinTimeout = 2 * kDurationResolution

Minimal timeout = 2 x kDurationResolution.

Protected Functions

virtual void deadline_actor() = 0

To-be implemented timer handler. Called if timer goes past expiration point.

Protected Attributes

bool deadline_fired_

Set before deadline_actor() called.

class expiration

RAII wrapper to set timer expiration.

Public Functions

inline expiration(timer_type *timer = nullptr)
inline expiration(timer_type *timer, const time_duration_type &duration)
inline expiration(timer_type *timer, const time_point_type &deadline)
expiration(const expiration &other) = default
inline expiration(expiration &&other) noexcept
inline expiration &operator=(const expiration &other) = default
inline expiration &operator=(expiration &&other) noexcept
inline ~expiration()