OpenVPN
interval.c
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2024 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include "syshead.h"
29
30#include "interval.h"
31
32#include "memdbg.h"
33
34void
35interval_init(struct interval *top, int horizon, int refresh)
36{
37 CLEAR(*top);
38 top->refresh = refresh;
39 top->horizon = horizon;
40}
41
42bool
44 struct timeval *tv,
45 const int et_const_retry)
46{
47 if (!et->defined)
48 {
49 return false;
50 }
51
52 bool ret = false;
53 time_t wakeup = event_timeout_remaining(et);
54
55 if (wakeup <= 0)
56 {
57#if INTERVAL_DEBUG
58 dmsg(D_INTERVAL, "EVENT event_timeout_trigger (%d) etcr=%d", et->n,
59 et_const_retry);
60#endif
61 if (et_const_retry < 0)
62 {
63 et->last = now;
64 wakeup = et->n;
65 ret = true;
66 }
67 else
68 {
69 wakeup = et_const_retry;
70 }
71 }
72
73 if (tv && wakeup < tv->tv_sec)
74 {
75#if INTERVAL_DEBUG
76 dmsg(D_INTERVAL, "EVENT event_timeout_wakeup (%d/%d) etcr=%d",
77 (int) wakeup, et->n, et_const_retry);
78#endif
79 tv->tv_sec = wakeup;
80 tv->tv_usec = 0;
81 }
82 return ret;
83}
#define D_INTERVAL
Definition errlevel.h:158
bool event_timeout_trigger(struct event_timeout *et, struct timeval *tv, const int et_const_retry)
This is the principal function for testing and triggering recurring timers.
Definition interval.c:43
void interval_init(struct interval *top, int horizon, int refresh)
Definition interval.c:35
static interval_t event_timeout_remaining(struct event_timeout *et)
Returns the time until the timeout should triggered, from now.
Definition interval.h:219
#define CLEAR(x)
Definition basic.h:33
#define dmsg(flags,...)
Definition error.h:148
time_t now
Definition otime.c:34
interval_t n
periodic interval for periodic timeouts
Definition interval.h:139
bool defined
This timeout is active.
Definition interval.h:138
time_t last
time of last event
Definition interval.h:140
interval_t horizon
Definition interval.h:45
interval_t refresh
Definition interval.h:44