lsquic_alarmset.h revision 7d09751d
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_alarmset.h -- A set of alarms 4 */ 5 6#ifndef LSQUIC_ALARM_H 7#define LSQUIC_ALARM_H 1 8 9#include "lsquic_int_types.h" 10 11enum alarm_id; 12struct lsquic_conn; 13 14typedef void (*lsquic_alarm_cb_f)(enum alarm_id, void *cb_ctx, 15 lsquic_time_t expiry, lsquic_time_t now); 16 17typedef struct lsquic_alarm { 18 lsquic_alarm_cb_f callback; 19 void *cb_ctx; 20} lsquic_alarm_t; 21 22 23enum alarm_id { 24 AL_HANDSHAKE, 25 AL_RETX_INIT, 26 AL_RETX_HSK = AL_RETX_INIT + PNS_HSK, 27 AL_RETX_APP = AL_RETX_INIT + PNS_APP, 28 AL_PING, 29 AL_IDLE, 30 AL_ACK_INIT, 31 AL_ACK_HSK = AL_ACK_INIT + PNS_HSK, 32 AL_ACK_APP = AL_ACK_INIT + PNS_APP, 33 AL_RET_CIDS, 34 AL_CID_THROT, 35 AL_PATH_CHAL, 36 AL_PATH_CHAL_0 = AL_PATH_CHAL, 37 AL_PATH_CHAL_1, 38 AL_SESS_TICKET, 39 MAX_LSQUIC_ALARMS 40}; 41 42 43enum alarm_id_bit { 44 ALBIT_HANDSHAKE = 1 << AL_HANDSHAKE, 45 ALBIT_RETX_INIT = 1 << AL_RETX_INIT, 46 ALBIT_RETX_HSK = 1 << AL_RETX_HSK, 47 ALBIT_RETX_APP = 1 << AL_RETX_APP, 48 ALBIT_ACK_APP = 1 << AL_ACK_APP, 49 ALBIT_ACK_INIT = 1 << AL_ACK_INIT, 50 ALBIT_ACK_HSK = 1 << AL_ACK_HSK, 51 ALBIT_PING = 1 << AL_PING, 52 ALBIT_IDLE = 1 << AL_IDLE, 53 ALBIT_RET_CIDS = 1 << AL_RET_CIDS, 54 ALBIT_CID_THROT = 1 << AL_CID_THROT, 55 ALBIT_PATH_CHAL_0 = 1 << AL_PATH_CHAL_0, 56 ALBIT_PATH_CHAL_1 = 1 << AL_PATH_CHAL_1, 57 ALBIT_SESS_TICKET = 1 << AL_SESS_TICKET, 58}; 59 60 61typedef struct lsquic_alarmset { 62 enum alarm_id_bit as_armed_set; 63 lsquic_time_t as_expiry[MAX_LSQUIC_ALARMS]; 64 const struct lsquic_conn *as_conn; /* Used for logging */ 65 struct lsquic_alarm as_alarms[MAX_LSQUIC_ALARMS]; 66} lsquic_alarmset_t; 67 68 69void 70lsquic_alarmset_init (lsquic_alarmset_t *, const struct lsquic_conn *); 71 72void 73lsquic_alarmset_init_alarm (lsquic_alarmset_t *, enum alarm_id, 74 lsquic_alarm_cb_f, void *cb_ctx); 75 76#define lsquic_alarmset_set(alarmset, al_id, exp) do { \ 77 (alarmset)->as_armed_set |= 1 << (al_id); \ 78 (alarmset)->as_expiry[al_id] = exp; \ 79} while (0) 80 81#define lsquic_alarmset_unset(alarmset, al_id) do { \ 82 (alarmset)->as_armed_set &= ~(1 << (al_id)); \ 83} while (0) 84 85#define lsquic_alarmset_is_set(alarmset, al_id) \ 86 ((alarmset)->as_armed_set & (1 << (al_id))) 87 88#define lsquic_alarmset_are_set(alarmset, flags) \ 89 ((alarmset)->as_armed_set & (flags)) 90 91/* Timers "fire," alarms "ring." */ 92void 93lsquic_alarmset_ring_expired (lsquic_alarmset_t *, lsquic_time_t now); 94 95lsquic_time_t 96lsquic_alarmset_mintime (const lsquic_alarmset_t *, enum alarm_id *); 97 98extern const char *const lsquic_alid2str[]; 99 100#endif 101