OpenVPN
Data Structures | Macros | Functions
interval.h File Reference
#include "otime.h"
Include dependency graph for interval.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  interval
 
struct  event_timeout
 
struct  usec_timer
 

Macros

#define INTERVAL_DEBUG   0
 
#define ETT_DEFAULT   (-1)
 
#define USEC_TIMER_MAX   60 /* maximum interval size in seconds */
 
#define USEC_TIMER_MAX_USEC   (USEC_TIMER_MAX * 1000000)
 

Functions

void interval_init (struct interval *top, int horizon, int refresh)
 
static bool interval_test (struct interval *top)
 
static void interval_schedule_wakeup (struct interval *top, interval_t *wakeup)
 
static void interval_future_trigger (struct interval *top, interval_t wakeup)
 
static void interval_action (struct interval *top)
 
static bool event_timeout_defined (const struct event_timeout *et)
 
static void event_timeout_clear (struct event_timeout *et)
 Clears the timeout and reset all values to 0. More...
 
static void event_timeout_init (struct event_timeout *et, interval_t n, const time_t last)
 Initialises a timer struct. More...
 
static void event_timeout_reset (struct event_timeout *et)
 Resets a timer. More...
 
static void event_timeout_modify_wakeup (struct event_timeout *et, interval_t n)
 Sets the interval n of a timeout. More...
 
static interval_t event_timeout_remaining (struct event_timeout *et)
 Returns the time until the timeout should triggered, from now. More...
 
bool event_timeout_trigger (struct event_timeout *et, struct timeval *tv, int et_const_retry)
 This is the principal function for testing and triggering recurring timers. More...
 
static void usec_timer_start (struct usec_timer *obj)
 
static void usec_timer_end (struct usec_timer *obj)
 
static bool usec_timer_interval_defined (struct usec_timer *obj)
 
static int usec_timer_interval (struct usec_timer *obj)
 

Macro Definition Documentation

◆ ETT_DEFAULT

#define ETT_DEFAULT   (-1)

Definition at line 224 of file interval.h.

◆ INTERVAL_DEBUG

#define INTERVAL_DEBUG   0

Definition at line 35 of file interval.h.

◆ USEC_TIMER_MAX

#define USEC_TIMER_MAX   60 /* maximum interval size in seconds */

Definition at line 266 of file interval.h.

◆ USEC_TIMER_MAX_USEC

#define USEC_TIMER_MAX_USEC   (USEC_TIMER_MAX * 1000000)

Definition at line 268 of file interval.h.

Function Documentation

◆ event_timeout_clear()

static void event_timeout_clear ( struct event_timeout et)
inlinestatic

◆ event_timeout_defined()

static bool event_timeout_defined ( const struct event_timeout et)
inlinestatic

◆ event_timeout_init()

static void event_timeout_init ( struct event_timeout et,
interval_t  n,
const time_t  last 
)
inlinestatic

Initialises a timer struct.

The timer will become true/trigger after last + n seconds.

Parameters
etTimer struct
nInterval of the timer for periodic timer. A negative value for n will be interpreted as 0.
lastSets the base time of the timer.

Definition at line 174 of file interval.h.

References event_timeout::defined, event_timeout::last, and event_timeout::n.

Referenced by check_add_routes(), check_connection_established(), check_tls(), do_init_server_poll_timeout(), do_init_timers(), do_up(), fragment_init(), man_bytecount(), multi_init(), process_explicit_exit_notification_init(), schedule_exit(), and status_open().

◆ event_timeout_modify_wakeup()

static void event_timeout_modify_wakeup ( struct event_timeout et,
interval_t  n 
)
inlinestatic

Sets the interval n of a timeout.

Parameters
et
nInterval value of the timer, negative values will be interpreted as 0
Note
you might need to call reset_coarse_timers after this

Definition at line 206 of file interval.h.

References event_timeout::defined, and event_timeout::n.

Referenced by check_push_request().

◆ event_timeout_remaining()

static interval_t event_timeout_remaining ( struct event_timeout et)
inlinestatic

Returns the time until the timeout should triggered, from now.

This function does not check if the timeout is actually valid.

Definition at line 219 of file interval.h.

References event_timeout::last, event_timeout::n, and now.

Referenced by event_timeout_trigger(), and get_server_poll_remaining_time().

◆ event_timeout_reset()

static void event_timeout_reset ( struct event_timeout et)
inlinestatic

Resets a timer.

Sets the last time the timer has been triggered for the calculation of the next event.

Parameters
et

Definition at line 189 of file interval.h.

References event_timeout::defined, event_timeout::last, and now.

Referenced by check_add_routes(), check_inactivity_timeout(), check_send_occ_req_dowork(), check_server_poll_timeout(), process_incoming_link_part1(), process_incoming_link_part2(), process_outgoing_link(), and register_activity().

◆ event_timeout_trigger()

bool event_timeout_trigger ( struct event_timeout et,
struct timeval *  tv,
int  et_const_retry 
)

This is the principal function for testing and triggering recurring timers.

If *et is not triggered, *tv is set to remaining time until the timeout if not already lower:

 *tv = minimum(*tv, event_timeout_remaining(*et))

If *et triggers and et_const_retry is negative (ETT_DEFAULT is -1):

  • the function will return true
  • *et will be armed for the next event (et->last set to now).
  • *tv will be lowered to the event period (n) if larger than the period of the event (set to *et's next timeout)
  • *et will not changed (ie also not rearmed, stays armed)

If *et triggers and et_const_retry >= 0, *tv will be lowered to et_const_try if larger:

*tv = *minimum(*tv, et_const_retry)

This is mainly useful if the trigger cannot yet be triggered for other reasons and a backoff timeout should be returned if the timer is ready to trigger.

Parameters
etthe timeout to check
tvwill be set to timeout for next check for this timeout unless already smaller.
et_const_retrysee above
Returns
if the timeout has triggered and event has been reset

Definition at line 43 of file interval.c.

References D_INTERVAL, event_timeout::defined, dmsg, event_timeout_remaining(), event_timeout::last, event_timeout::n, and now.

Referenced by check_add_routes(), check_ping_restart(), check_ping_send(), check_send_occ_load_test(), check_send_occ_req(), check_session_timeout(), management_check_bytecount(), process_coarse_timers(), process_explicit_exit_notification_timer_wakeup(), stale_route_check_trigger(), and status_trigger().

◆ interval_action()

static void interval_action ( struct interval top)
inlinestatic

Definition at line 124 of file interval.h.

References D_INTERVAL, dmsg, interval::last_action, and now.

Referenced by check_tls(), process_incoming_link_part1(), and reschedule_multi_process().

◆ interval_future_trigger()

static void interval_future_trigger ( struct interval top,
interval_t  wakeup 
)
inlinestatic

Definition at line 108 of file interval.h.

References D_INTERVAL, dmsg, interval::future_trigger, and now.

Referenced by check_tls().

◆ interval_init()

void interval_init ( struct interval top,
int  horizon,
int  refresh 
)

Definition at line 35 of file interval.c.

References CLEAR, interval::horizon, and interval::refresh.

Referenced by do_init_timers().

◆ interval_schedule_wakeup()

static void interval_schedule_wakeup ( struct interval top,
interval_t wakeup 
)
inlinestatic

◆ interval_test()

static bool interval_test ( struct interval top)
inlinestatic

◆ usec_timer_end()

static void usec_timer_end ( struct usec_timer obj)
inlinestatic

Definition at line 285 of file interval.h.

References usec_timer::end, and openvpn_gettimeofday().

◆ usec_timer_interval()

static int usec_timer_interval ( struct usec_timer obj)
inlinestatic

Definition at line 299 of file interval.h.

References usec_timer::end, usec_timer::start, tv_subtract(), and USEC_TIMER_MAX.

◆ usec_timer_interval_defined()

static bool usec_timer_interval_defined ( struct usec_timer obj)
inlinestatic

Definition at line 293 of file interval.h.

References usec_timer::end, and usec_timer::start.

◆ usec_timer_start()

static void usec_timer_start ( struct usec_timer obj)
inlinestatic

Definition at line 278 of file interval.h.

References CLEAR, openvpn_gettimeofday(), and usec_timer::start.