25#ifdef OPENVPN_PLATFORM_WIN
82 return Duration(std::numeric_limits<T>::max());
89 return Duration(v + (v * T(3) / T(128)));
95 return milliseconds(openvpn::numeric_util::numeric_cast<T>(ms.count()));
113 return duration_ == std::numeric_limits<T>::max();
121 duration_ = std::numeric_limits<T>::max();
145 const unsigned int ndelta = -
delta;
225#define OPENVPN_DURATION_REL(OP) \
226 bool operator OP(const Duration &d) const \
228 return duration_ OP d.duration_; \
236#undef OPENVPN_DURATION_REL
258 return TimeType(std::numeric_limits<T>::max());
271 return time_ == std::numeric_limits<T>::max();
280 time_ = std::numeric_limits<T>::max();
382 const int idf = int(df);
383 if (df ==
static_cast<double>(idf))
390#define OPENVPN_TIME_REL(OP) \
391 bool operator OP(const TimeType &t) const \
393 return time_ OP t.time_; \
401#undef OPENVPN_TIME_REL
403 template <
typename HASH>
420 if (newbase -
base_ >= (60 * 60 * 24 * 30))
427#ifdef OPENVPN_TIME_NO_BASE
428 static_assert(
sizeof(
base_type) >= 8,
"OPENVPN_TIME_NO_BASE requires time_t to be 64 bits");
430 base_ = ::time(NULL);
431#ifdef OPENVPN_PLATFORM_WIN
432 win_recalibrate(::GetTickCount64());
441 return ((11644473600ULL * uint64_t(
prec)) + (uint64_t(
base_) * uint64_t(
prec)) + uint64_t(
now_())) * 78125ULL / 8ULL;
450#ifdef OPENVPN_PLATFORM_WIN
452 static void win_recalibrate(
const ULONGLONG gtc)
455 gtc_base = ::time(NULL) - gtc_last / 1000;
460 const ULONGLONG gtc = ::GetTickCount64();
462 win_recalibrate(gtc);
463 const time_t sec = gtc_base + gtc / 1000;
464 const unsigned int msec = gtc % 1000;
468 static inline ULONGLONG gtc_last = 0;
469 static inline time_t gtc_base = 0;
476 if (::gettimeofday(&tv,
nullptr) != 0)
477 throw get_time_error();
478 return T((tv.tv_sec -
base_) *
prec + tv.tv_usec *
prec / 1000000);
483#ifdef OPENVPN_TIME_NO_BASE
static Duration binary_ms(const T v)
static Duration infinite()
void min(const Duration &d)
Duration(const T duration)
T to_milliseconds() const
void max(const Duration &d)
Duration operator+(const Duration &d) const
Duration & operator+=(const Duration &d)
Duration operator-(const Duration &d) const
Duration operator+(const int delta) const
static Duration milliseconds(std::chrono::milliseconds ms)
Duration & operator-=(const Duration &d)
static Duration milliseconds(const T v)
static Duration seconds(const T v)
Duration operator*(const unsigned int mult) const
static TimeType from_seconds_since_epoch(const time_t t)
std::string delta_str(const TimeType &t) const
TimeType & operator+=(const Duration &d)
static TimeType infinite()
void max(const TimeType &t)
void min(const TimeType &t)
std::uint64_t nanoseconds_since_epoch() const
static uint64_t win_time()
base_type seconds_since_epoch() const
static void reset_base_conditional()
long delta_prec(const TimeType &t) const
Duration operator-(const TimeType &t) const
long delta(const TimeType &t) const
TimeType operator+(const Duration &d) const
double delta_float(const TimeType &t) const
T fractional_binary_ms() const
#define OPENVPN_SIMPLE_EXCEPTION(C)
Support deferred server-side state creation when client connects.
std::string to_string(T value)
#define OPENVPN_TIME_REL(OP)
#define OPENVPN_DURATION_REL(OP)