lsquic_conn_flow.h revision 50aadb33
1/* Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_conn_flow.h -- Connection flow control-related functions 4 */ 5 6#ifndef LSQUIC_CONN_FLOW_H 7#define LSQUIC_CONN_FLOW_H 1 8 9struct lsquic_conn_public; 10 11typedef struct lsquic_cfcw { 12 struct lsquic_conn_public 13 *cf_conn_pub; 14 uint64_t cf_max_recv_off; /* Largest offset observed (cumulative) */ 15 uint64_t cf_recv_off; /* Flow control receive offset */ 16 uint64_t cf_read_off; /* Number of bytes consumed (cumulative) */ 17 lsquic_time_t cf_last_updated; 18 unsigned cf_max_recv_win; /* Maximum receive window */ 19} lsquic_cfcw_t; 20 21struct lsquic_conn_cap { 22 uint64_t cc_sent; /* Number of bytes sent on connection */ 23 uint64_t cc_max; /* Maximum cumulative number of bytes allowed 24 * to be sent on this connection. 25 */ 26 uint64_t cc_tosend; /* Number of bytes scheduled to be sent 27 * accross all streams. 28 */ 29 uint64_t cc_blocked; /* Last blocked offset used */ 30}; 31 32 33#define lsquic_conn_cap_init(cc, max) do { \ 34 (cc)->cc_sent = 0; \ 35 (cc)->cc_tosend = 0; \ 36 (cc)->cc_max = max; \ 37} while (0) 38 39 40#define lsquic_conn_cap_avail(cap) ( \ 41 ((cap)->cc_sent + (cap)->cc_tosend <= (cap)->cc_max) \ 42 ? \ 43 ((cap)->cc_max - (cap)->cc_sent - (cap)->cc_tosend) \ 44 : \ 45 0 \ 46) 47 48 49void 50lsquic_cfcw_init (lsquic_cfcw_t *, struct lsquic_conn_public *, 51 unsigned initial_max_recv_window); 52 53/* If update is to be sent, updates max_recv_off and returns true. Note 54 * that if you call this function twice, the second call will return false. 55 */ 56int 57lsquic_cfcw_fc_offsets_changed (lsquic_cfcw_t *); 58 59#define lsquic_cfcw_get_fc_recv_off(fc) (+(fc)->cf_recv_off) 60 61#define lsquic_cfcw_get_max_recv_off(fc) (+(fc)->cf_max_recv_off) 62 63#define lsquic_cfcw_get_max_recv_window(fc) (+(fc)->cf_max_recv_win) 64 65/* Returns false if flow control violation is encountered */ 66int 67lsquic_cfcw_incr_max_recv_off (lsquic_cfcw_t *, uint64_t); 68 69/* Void because we do not expect the caller to make a mistake. 70 */ 71void 72lsquic_cfcw_incr_read_off (lsquic_cfcw_t *, uint64_t); 73 74#endif 75