lsquic_conn_flow.h revision 10c492f0
1/* Copyright (c) 2017 - 2018 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_blocked;        /* Last blocked offset used */
27};
28
29
30#define lsquic_conn_cap_init(cc, max) do {                          \
31    (cc)->cc_sent = 0;                                              \
32    (cc)->cc_max = max;                                             \
33} while (0)
34
35
36#define lsquic_conn_cap_avail(cap) (                                \
37    (assert((cap)->cc_max >= (cap)->cc_sent)),                      \
38        (cap)->cc_max - (cap)->cc_sent)
39
40
41void
42lsquic_cfcw_init (lsquic_cfcw_t *, struct lsquic_conn_public *,
43                                        unsigned initial_max_recv_window);
44
45/* If update is to be sent, updates max_recv_off and returns true.  Note
46 * that if you call this function twice, the second call will return false.
47 */
48int
49lsquic_cfcw_fc_offsets_changed (lsquic_cfcw_t *);
50
51#define lsquic_cfcw_get_fc_recv_off(fc) (+(fc)->cf_recv_off)
52
53#define lsquic_cfcw_get_max_recv_off(fc) (+(fc)->cf_max_recv_off)
54
55#define lsquic_cfcw_get_max_recv_window(fc) (+(fc)->cf_max_recv_win)
56
57/* Returns false if flow control violation is encountered */
58int
59lsquic_cfcw_incr_max_recv_off (lsquic_cfcw_t *, uint64_t);
60
61/* Void because we do not expect the caller to make a mistake.
62 */
63void
64lsquic_cfcw_incr_read_off (lsquic_cfcw_t *, uint64_t);
65
66#endif
67