Line data Source code
1 : #ifndef HEADER_fd_src_waltz_quic_fd_quic_svc_q_h 2 : #define HEADER_fd_src_waltz_quic_fd_quic_svc_q_h 3 : 4 : #include "fd_quic_common.h" 5 : 6 : /* service queue types */ 7 138500459 : #define FD_QUIC_SVC_INSTANT (0U) /* as soon as possible */ 8 96354407 : #define FD_QUIC_SVC_DYNAMIC (1U) /* some dynamic amount of time */ 9 69637438 : #define FD_QUIC_SVC_CNT (2U) /* number of FD_QUIC_SVC_{...} levels */ 10 : 11 : /* sentinel index */ 12 14427851 : #define FD_QUIC_SVC_PRQ_IDX_INVAL (~0UL) 13 41345955 : #define FD_QUIC_SVC_DLIST_IDX_INVAL (~0U) 14 : 15 : /* fd_quic_svc_queue_t is a dlist. */ 16 : struct fd_quic_svc_queue { 17 : uint cnt; 18 : uint head; 19 : uint tail; 20 : }; 21 : 22 : typedef struct fd_quic_svc_queue fd_quic_svc_queue_t; 23 : 24 : struct fd_quic_svc_timers_conn_meta { 25 : long next_timeout; /* next timeout for this connection */ 26 : struct { 27 : union { 28 : ulong prq_idx; /* only non-IDX_INVALID when in prq*/ 29 : struct { 30 : uint next; /* next connection in dlist */ 31 : uint prev; /* prev connection in dlist */ 32 : } dlist; /* only used for dlist */ 33 : }; 34 : uint svc_type; /* FD_QUIC_SVC_* */ 35 : } private; 36 : }; 37 : typedef struct fd_quic_svc_timers_conn_meta fd_quic_svc_timers_conn_meta_t; 38 : 39 : /* Event structure stored in timers */ 40 : struct __attribute__((packed)) fd_quic_svc_event { 41 : long timeout; 42 : fd_quic_conn_t * conn; 43 : }; 44 : typedef struct fd_quic_svc_event fd_quic_svc_event_t; 45 : 46 : /* the timers struct */ 47 : struct fd_quic_svc_timers { 48 : fd_quic_svc_event_t * prq; /* priority queue for DYNAMIC timers */ 49 : fd_quic_svc_queue_t instant; /* INSTANT queue (dlist) */ 50 : fd_quic_state_t * state; /* state pointer */ 51 : }; 52 : typedef struct fd_quic_svc_timers fd_quic_svc_timers_t; 53 : 54 : /* Setup functions ****************************************************/ 55 : 56 : /* fd_quic_svc_timers_footprint returns the footprint of the timers */ 57 : ulong 58 : fd_quic_svc_timers_footprint( ulong max_conn ); 59 : 60 : /* fd_quic_svc_timers_align returns the alignment of the timers */ 61 : ulong 62 : fd_quic_svc_timers_align( void ); 63 : 64 : /* fd_quic_svc_timers_init initializes the timers 65 : mem is a pointer to ALIGNED memory to initialize 66 : max_conn is the maximum number of connections to support 67 : NOT JUST A SIMPLE POINTER CAST FROM mem 68 : Retains a read interest in state throughout lifetime */ 69 : fd_quic_svc_timers_t * 70 : fd_quic_svc_timers_init( void * mem, 71 : ulong max_conn, 72 : fd_quic_state_t * state ); 73 : 74 : /* fd_quic_svc_timers_init_conn initializes the conn_meta in this conn */ 75 : void 76 : fd_quic_svc_timers_init_conn( fd_quic_conn_t * conn ); 77 : 78 : /* Public functions ***************************************************/ 79 : 80 : /* fd_quic_svc_timers_schedule schedules a connection timer. 81 : Uses conn->svc_meta.next_timeout as the expiry time, retaining a 82 : read interest until the connection is removed from the queue! 83 : A connection that is already scheduled can only be rescheduled 84 : for earlier, not later. Such rescheduling will remove the old timer. 85 : 'Now' is assumed monotonic across ALL svc_calls.*/ 86 : void 87 : fd_quic_svc_timers_schedule( fd_quic_svc_timers_t * timers, 88 : fd_quic_conn_t * conn, 89 : long now ); 90 : 91 : /* fd_quic_svc_timers_validate checks that events and 92 : connections point to each other 93 : returns 1 if valid, 0 otherwise */ 94 : int 95 : fd_quic_svc_timers_validate( fd_quic_svc_timers_t * timers, 96 : fd_quic_t * quic ); 97 : 98 : /* fd_quic_svc_cancel removes a connection from the service queue */ 99 : void 100 : fd_quic_svc_timers_cancel( fd_quic_svc_timers_t * timers, 101 : fd_quic_conn_t * conn ); 102 : 103 : /* fd_quic_svc_timers_next returns next event. If 'pop' is true, 104 : the event (if in past) is popped from the queue, and next_timeout 105 : is reset to ULONG_MAX. If next event is in the future with pop=true, 106 : will return none! If pop is false, event will remain enqueued and 107 : may be in the future. Returns NULL conn if queue empty. 108 : 'Now' is assumed monotonic across all svc_timers-* calls, 109 : NOT just to this method. */ 110 : fd_quic_svc_event_t 111 : fd_quic_svc_timers_next( fd_quic_svc_timers_t * timers, 112 : long now, 113 : int pop ); 114 : 115 : /* fd_quic_svc_timers_get_event returns event for a given conn 116 : returns event with conn==NULL if not found 117 : 'Now' is assumed monotonic.*/ 118 : fd_quic_svc_event_t 119 : fd_quic_svc_timers_get_event( fd_quic_svc_timers_t * timers, 120 : fd_quic_conn_t * conn, 121 : long now ); 122 : 123 : 124 : /* fd_quic_svc_timers_cnt_events returns the number of conns with active timers 125 : Primarily used for testing/validation. */ 126 : ulong 127 : fd_quic_svc_timers_cnt_events( fd_quic_svc_timers_t * timers ); 128 : 129 : #endif /* HEADER_fd_src_waltz_quic_fd_quic_svc_q_h */