73 const int status = gettimeofday(tv, tz);
117 return tv->tv_sec > 0 && tv->tv_usec > 0;
122tv_subtract(
const struct timeval *tv1,
const struct timeval *tv2,
const int max_seconds)
124 const int max_usec = max_seconds * 1000000;
125 const tv_sec_t sec_diff = tv1->tv_sec - tv2->tv_sec;
127 if (sec_diff > (max_seconds + 10))
131 else if (sec_diff < -(max_seconds + 10))
135 const time_t complete_diff = sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec);
136 return constrain_int((
int)complete_diff, -max_usec, max_usec);
140tv_add(
struct timeval *dest,
const struct timeval *src)
142 dest->tv_sec += src->tv_sec;
143 dest->tv_usec += src->tv_usec;
144 dest->tv_sec += (dest->tv_usec >> 20);
145 dest->tv_usec &= 0x000FFFFF;
146 if (dest->tv_usec >= 1000000)
148 dest->tv_usec -= 1000000;
154tv_lt(
const struct timeval *t1,
const struct timeval *t2)
156 if (t1->tv_sec < t2->tv_sec)
160 else if (t1->tv_sec > t2->tv_sec)
166 return t1->tv_usec < t2->tv_usec;
171tv_le(
const struct timeval *t1,
const struct timeval *t2)
173 if (t1->tv_sec < t2->tv_sec)
177 else if (t1->tv_sec > t2->tv_sec)
183 return t1->tv_usec <= t2->tv_usec;
188tv_ge(
const struct timeval *t1,
const struct timeval *t2)
190 if (t1->tv_sec > t2->tv_sec)
194 else if (t1->tv_sec < t2->tv_sec)
200 return t1->tv_usec >= t2->tv_usec;
205tv_gt(
const struct timeval *t1,
const struct timeval *t2)
207 if (t1->tv_sec > t2->tv_sec)
211 else if (t1->tv_sec < t2->tv_sec)
217 return t1->tv_usec > t2->tv_usec;
222tv_eq(
const struct timeval *t1,
const struct timeval *t2)
224 return t1->tv_sec == t2->tv_sec && t1->tv_usec == t2->tv_usec;
228tv_delta(
struct timeval *dest,
const struct timeval *t1,
const struct timeval *t2)
230 tv_sec_t sec = t2->tv_sec - t1->tv_sec;
231 tv_usec_t usec = t2->tv_usec - t1->tv_usec;
245 dest->tv_usec = usec;
248#define TV_WITHIN_SIGMA_MAX_SEC 600
249#define TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000)
255tv_within_sigma(
const struct timeval *t1,
const struct timeval *t2,
unsigned int sigma)
259 return -(int)sigma <= delta && delta <= (
int)sigma;
static int constrain_int(int x, int min, int max)
static SERVICE_STATUS status
static bool tv_le(const struct timeval *t1, const struct timeval *t2)
static bool tv_eq(const struct timeval *t1, const struct timeval *t2)
static void tv_delta(struct timeval *dest, const struct timeval *t1, const struct timeval *t2)
static void interval_earliest_wakeup(interval_t *wakeup, time_t at, time_t current)
const char * time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc)
struct frequency_limit * frequency_limit_init(int max, int per)
void update_now(const time_t system_time)
void update_now_usec(struct timeval *tv)
static bool tv_ge(const struct timeval *t1, const struct timeval *t2)
void frequency_limit_free(struct frequency_limit *f)
const char * tv_string(const struct timeval *tv, struct gc_arena *gc)
static bool tv_lt(const struct timeval *t1, const struct timeval *t2)
const char * tv_string_abs(const struct timeval *tv, struct gc_arena *gc)
bool frequency_limit_event_allowed(struct frequency_limit *f)
static time_t openvpn_time(time_t *t)
static bool tv_gt(const struct timeval *t1, const struct timeval *t2)
static void update_time(void)
static int openvpn_gettimeofday(struct timeval *tv, void *tz)
static void tv_clear(struct timeval *tv)
static bool tv_defined(const struct timeval *tv)
#define TV_WITHIN_SIGMA_MAX_SEC
static bool tv_within_sigma(const struct timeval *t1, const struct timeval *t2, unsigned int sigma)
static int tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const int max_seconds)
static void tv_add(struct timeval *dest, const struct timeval *src)
Garbage collection arena used to keep track of dynamically allocated memory.