Go to the documentation of this file.
66 const int status = gettimeofday(tv, tz);
110 return tv->tv_sec > 0 && tv->tv_usec > 0;
115 tv_subtract(
const struct timeval *tv1,
const struct timeval *tv2,
const unsigned int max_seconds)
117 const int max_usec = max_seconds * 1000000;
118 const int sec_diff = tv1->tv_sec - tv2->tv_sec;
120 if (sec_diff > ((
int)max_seconds + 10))
124 else if (sec_diff < -((
int)max_seconds + 10))
128 return constrain_int(sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec), -max_usec, max_usec);
132 tv_add(
struct timeval *dest,
const struct timeval *src)
134 dest->tv_sec += src->tv_sec;
135 dest->tv_usec += src->tv_usec;
136 dest->tv_sec += (dest->tv_usec >> 20);
137 dest->tv_usec &= 0x000FFFFF;
138 if (dest->tv_usec >= 1000000)
140 dest->tv_usec -= 1000000;
146 tv_lt(
const struct timeval *t1,
const struct timeval *t2)
148 if (t1->tv_sec < t2->tv_sec)
152 else if (t1->tv_sec > t2->tv_sec)
158 return t1->tv_usec < t2->tv_usec;
163 tv_le(
const struct timeval *t1,
const struct timeval *t2)
165 if (t1->tv_sec < t2->tv_sec)
169 else if (t1->tv_sec > t2->tv_sec)
175 return t1->tv_usec <= t2->tv_usec;
180 tv_ge(
const struct timeval *t1,
const struct timeval *t2)
182 if (t1->tv_sec > t2->tv_sec)
186 else if (t1->tv_sec < t2->tv_sec)
192 return t1->tv_usec >= t2->tv_usec;
197 tv_gt(
const struct timeval *t1,
const struct timeval *t2)
199 if (t1->tv_sec > t2->tv_sec)
203 else if (t1->tv_sec < t2->tv_sec)
209 return t1->tv_usec > t2->tv_usec;
214 tv_eq(
const struct timeval *t1,
const struct timeval *t2)
216 return t1->tv_sec == t2->tv_sec && t1->tv_usec == t2->tv_usec;
220 tv_delta(
struct timeval *dest,
const struct timeval *t1,
const struct timeval *t2)
222 int sec = t2->tv_sec - t1->tv_sec;
223 int usec = t2->tv_usec - t1->tv_usec;
237 dest->tv_usec = usec;
240 #define TV_WITHIN_SIGMA_MAX_SEC 600
241 #define TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000)
247 tv_within_sigma(
const struct timeval *t1,
const struct timeval *t2,
unsigned int sigma)
250 return -(int)sigma <= delta && delta <= (
int)sigma;
const char * time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc)
static void tv_delta(struct timeval *dest, const struct timeval *t1, const struct timeval *t2)
void update_now(const time_t system_time)
static int tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const unsigned int max_seconds)
const char * tv_string(const struct timeval *tv, struct gc_arena *gc)
static void interval_earliest_wakeup(interval_t *wakeup, time_t at, time_t current)
bool frequency_limit_event_allowed(struct frequency_limit *f)
struct frequency_limit * frequency_limit_init(int max, int per)
void update_now_usec(struct timeval *tv)
#define TV_WITHIN_SIGMA_MAX_SEC
static bool tv_le(const struct timeval *t1, const struct timeval *t2)
static void update_time(void)
void frequency_limit_free(struct frequency_limit *f)
static void tv_add(struct timeval *dest, const struct timeval *src)
Garbage collection arena used to keep track of dynamically allocated memory.
static bool tv_lt(const struct timeval *t1, const struct timeval *t2)
static bool tv_within_sigma(const struct timeval *t1, const struct timeval *t2, unsigned int sigma)
static time_t openvpn_time(time_t *t)
static int openvpn_gettimeofday(struct timeval *tv, void *tz)
static SERVICE_STATUS status
static bool tv_gt(const struct timeval *t1, const struct timeval *t2)
static bool tv_eq(const struct timeval *t1, const struct timeval *t2)
static bool tv_ge(const struct timeval *t1, const struct timeval *t2)
static int constrain_int(int x, int min, int max)
const char * tv_string_abs(const struct timeval *tv, struct gc_arena *gc)
static void tv_clear(struct timeval *tv)
static bool tv_defined(const struct timeval *tv)