lsquic_sfcw.h revision 5392f7a3
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_sfcw.h -- Stream flow control window functions
4 */
5
6#ifndef LSQUIC_SFCW_H
7#define LSQUIC_SFCW_H 1
8
9struct lsquic_cfcw;
10struct lsquic_conn_public;
11
12typedef struct lsquic_sfcw {
13    struct lsquic_cfcw *sf_cfcw;            /* Connection flow control window,
14                                             * NULL for streams 1 and 3.
15                                             */
16    uint64_t            sf_max_recv_off;    /* Largest offset observed */
17    uint64_t            sf_recv_off;        /* Flow control receive offset */
18    uint64_t            sf_read_off;        /* Number of bytes consumed */
19    lsquic_time_t       sf_last_updated;    /* Last time window was updated */
20    struct lsquic_conn_public
21                       *sf_conn_pub;
22    unsigned            sf_max_recv_win;    /* Maximum receive window */
23    lsquic_stream_id_t  sf_stream_id;       /* Used for logging */
24} lsquic_sfcw_t;
25
26
27void
28lsquic_sfcw_init (lsquic_sfcw_t *, unsigned initial_max_recv_window,
29                  struct lsquic_cfcw *cfcw, struct lsquic_conn_public *,
30                  lsquic_stream_id_t stream_id);
31
32/* If update is to be sent, updates max_recv_off and returns true.  Note
33 * that if you call this function twice, the second call will return false.
34 */
35int
36lsquic_sfcw_fc_offsets_changed (lsquic_sfcw_t *);
37
38#define lsquic_sfcw_get_fc_recv_off(fc) ((fc)->sf_recv_off)
39
40#define lsquic_sfcw_get_max_recv_off(fc) ((fc)->sf_max_recv_off)
41
42/* Returns false if flow control violation is encountered */
43int
44lsquic_sfcw_set_max_recv_off (lsquic_sfcw_t *, uint64_t);
45
46/* Void because we do not expect the caller to make a mistake.
47 */
48void
49lsquic_sfcw_set_read_off (lsquic_sfcw_t *, uint64_t);
50
51#define lsquic_sfcw_consume_rem(sfcw) do {                        \
52    lsquic_sfcw_set_read_off(sfcw,                                \
53                    lsquic_sfcw_get_max_recv_off(sfcw));          \
54} while (0)
55
56#endif
57