OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::TimeType< T > Class Template Reference

#include <time.hpp>

Classes

class  Duration
 

Public Types

enum  { prec = 1024 }
 
typedef ::time_t base_type
 
typedef T type
 

Public Member Functions

 TimeType () noexcept
 
bool is_infinite () const
 
void reset ()
 
void set_infinite ()
 
bool defined () const
 
bool operator! () const
 
base_type seconds_since_epoch () const
 
std::uint64_t nanoseconds_since_epoch () const
 
fractional_binary_ms () const
 
void update ()
 
TimeType operator+ (const Duration &d) const
 
TimeTypeoperator+= (const Duration &d)
 
Duration operator- (const TimeType &t) const
 
void min (const TimeType &t)
 
void max (const TimeType &t)
 
long delta_prec (const TimeType &t) const
 
long delta (const TimeType &t) const
 
double delta_float (const TimeType &t) const
 
std::string delta_str (const TimeType &t) const
 
template<typename HASH >
void hash (HASH &h) const
 
raw () const
 

Static Public Member Functions

static TimeType zero ()
 
static TimeType infinite ()
 
static TimeType from_seconds_since_epoch (const time_t t)
 
static TimeType now ()
 
static void reset_base_conditional ()
 
static void reset_base ()
 
static uint64_t win_time ()
 

Private Member Functions

 TimeType (const T time)
 

Static Private Member Functions

static T now_ ()
 

Private Attributes

time_
 

Static Private Attributes

static base_type base_ = 0
 

Detailed Description

template<typename T>
class openvpn::TimeType< T >

These are our fundamental Time and Time Duration classes. We normally deal with time in units of 1/1024 of a second. This allows us to use 32-bit values to represent most time and time duration values, but still gives us reasonable accuracy. Using units of 1/1024 of a second vs. straight milliseconds gives us an advantage of not needing to do very much integer multiplication and division which can help us on platforms such as ARM that lack integer division instructions. Note that the data type used to store the time is an oulong, so it will automatically expand to 64 bits on 64-bit machines (see olong.hpp). Using a 32-bit data type for time durations is normally fine for clients, but imposes a wraparound limit of ~ 48 days. Servers should always use a 64-bit data type to avoid this limitation.

This code was originally designed to be efficient on 32-bit processors. On 64-bit processors, define OPENVPN_TIME_NO_BASE to optimize out the base_ variable. This also has the benefit of allowing Time to represent any arbitrary time_t value.

Definition at line 57 of file time.hpp.

Member Typedef Documentation

◆ base_type

template<typename T >
typedef ::time_t openvpn::TimeType< T >::base_type

Definition at line 64 of file time.hpp.

◆ type

template<typename T >
typedef T openvpn::TimeType< T >::type

Definition at line 65 of file time.hpp.

Member Enumeration Documentation

◆ anonymous enum

template<typename T >
anonymous enum
Enumerator
prec 

Definition at line 60 of file time.hpp.

Constructor & Destructor Documentation

◆ TimeType() [1/2]

template<typename T >
openvpn::TimeType< T >::TimeType ( )
inlinenoexcept

Definition at line 247 of file time.hpp.

Here is the caller graph for this function:

◆ TimeType() [2/2]

template<typename T >
openvpn::TimeType< T >::TimeType ( const T  time)
inlineexplicitprivate

Definition at line 445 of file time.hpp.

Member Function Documentation

◆ defined()

template<typename T >
bool openvpn::TimeType< T >::defined ( ) const
inline

Definition at line 283 of file time.hpp.

Here is the caller graph for this function:

◆ delta()

template<typename T >
long openvpn::TimeType< T >::delta ( const TimeType< T > &  t) const
inline

Definition at line 359 of file time.hpp.

Here is the caller graph for this function:

◆ delta_float()

template<typename T >
double openvpn::TimeType< T >::delta_float ( const TimeType< T > &  t) const
inline

Definition at line 364 of file time.hpp.

Here is the caller graph for this function:

◆ delta_prec()

template<typename T >
long openvpn::TimeType< T >::delta_prec ( const TimeType< T > &  t) const
inline

Definition at line 354 of file time.hpp.

Here is the caller graph for this function:

◆ delta_str()

template<typename T >
std::string openvpn::TimeType< T >::delta_str ( const TimeType< T > &  t) const
inline

Return a human-readable number of seconds that *this is ahead of t. t is usually now().

Definition at line 372 of file time.hpp.

◆ fractional_binary_ms()

template<typename T >
T openvpn::TimeType< T >::fractional_binary_ms ( ) const
inline

Definition at line 300 of file time.hpp.

Here is the caller graph for this function:

◆ from_seconds_since_epoch()

template<typename T >
static TimeType openvpn::TimeType< T >::from_seconds_since_epoch ( const time_t  t)
inlinestatic

Definition at line 261 of file time.hpp.

◆ hash()

template<typename T >
template<typename HASH >
void openvpn::TimeType< T >::hash ( HASH &  h) const
inline

Definition at line 404 of file time.hpp.

◆ infinite()

template<typename T >
static TimeType openvpn::TimeType< T >::infinite ( )
inlinestatic

Definition at line 256 of file time.hpp.

Here is the caller graph for this function:

◆ is_infinite()

template<typename T >
bool openvpn::TimeType< T >::is_infinite ( ) const
inline

Definition at line 269 of file time.hpp.

Here is the caller graph for this function:

◆ max()

template<typename T >
void openvpn::TimeType< T >::max ( const TimeType< T > &  t)
inline

Definition at line 348 of file time.hpp.

Here is the caller graph for this function:

◆ min()

template<typename T >
void openvpn::TimeType< T >::min ( const TimeType< T > &  t)
inline

Definition at line 342 of file time.hpp.

Here is the caller graph for this function:

◆ nanoseconds_since_epoch()

template<typename T >
std::uint64_t openvpn::TimeType< T >::nanoseconds_since_epoch ( ) const
inline

Definition at line 296 of file time.hpp.

◆ now()

template<typename T >
static TimeType openvpn::TimeType< T >::now ( )
inlinestatic

Definition at line 305 of file time.hpp.

◆ now_()

template<typename T >
static T openvpn::TimeType< T >::now_ ( )
inlinestaticprivate

Definition at line 473 of file time.hpp.

Here is the caller graph for this function:

◆ operator!()

template<typename T >
bool openvpn::TimeType< T >::operator! ( ) const
inline

Definition at line 287 of file time.hpp.

◆ operator+()

template<typename T >
TimeType openvpn::TimeType< T >::operator+ ( const Duration d) const
inline

Definition at line 315 of file time.hpp.

◆ operator+=()

template<typename T >
TimeType & openvpn::TimeType< T >::operator+= ( const Duration d)
inline

Definition at line 323 of file time.hpp.

◆ operator-()

template<typename T >
Duration openvpn::TimeType< T >::operator- ( const TimeType< T > &  t) const
inline

Definition at line 332 of file time.hpp.

◆ raw()

template<typename T >
T openvpn::TimeType< T >::raw ( ) const
inline

Definition at line 409 of file time.hpp.

Here is the caller graph for this function:

◆ reset()

template<typename T >
void openvpn::TimeType< T >::reset ( )
inline

Definition at line 274 of file time.hpp.

Here is the caller graph for this function:

◆ reset_base()

template<typename T >
static void openvpn::TimeType< T >::reset_base ( )
inlinestatic

Definition at line 425 of file time.hpp.

Here is the caller graph for this function:

◆ reset_base_conditional()

template<typename T >
static void openvpn::TimeType< T >::reset_base_conditional ( )
inlinestatic

Definition at line 414 of file time.hpp.

◆ seconds_since_epoch()

template<typename T >
base_type openvpn::TimeType< T >::seconds_since_epoch ( ) const
inline

Definition at line 292 of file time.hpp.

Here is the caller graph for this function:

◆ set_infinite()

template<typename T >
void openvpn::TimeType< T >::set_infinite ( )
inline

Definition at line 278 of file time.hpp.

Here is the caller graph for this function:

◆ update()

template<typename T >
void openvpn::TimeType< T >::update ( )
inline

Definition at line 310 of file time.hpp.

Here is the caller graph for this function:

◆ win_time()

template<typename T >
static uint64_t openvpn::TimeType< T >::win_time ( )
inlinestatic

number of tenths of a microsecond since January 1, 1601.

Definition at line 438 of file time.hpp.

◆ zero()

template<typename T >
static TimeType openvpn::TimeType< T >::zero ( )
inlinestatic

Definition at line 252 of file time.hpp.

Member Data Documentation

◆ base_

template<typename T >
base_type openvpn::TimeType< T >::base_ = 0
inlinestaticprivate

Definition at line 486 of file time.hpp.

◆ time_

template<typename T >
T openvpn::TimeType< T >::time_
private

Definition at line 489 of file time.hpp.


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