lsquic_qenc_hdl.h revision 5392f7a3
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_qenc_hdl.h -- QPACK encoder streams handler
4 *
5 * The handler owns two unidirectional streams: a) locally-initiated QPACK
6 * encoder stream, to which it writes; and b) peer-initiated QPACK decoder
7 * stream, from which it reads.
8 */
9
10#ifndef LSQUIC_QENC_HDL_H
11#define LSQUIC_QENC_HDL_H 1
12
13struct lsquic_conn;
14struct lsquic_stream;
15struct lsquic_stream_if;
16
17struct qpack_enc_hdl
18{
19    struct lsquic_conn      *qeh_conn;
20    enum {
21        QEH_INITIALIZED     = 1 << 0,
22        QEH_HAVE_SETTINGS   = 1 << 1,
23    }                        qeh_flags;
24    unsigned                 qeh_max_prefix_size;
25    struct lsqpack_enc       qeh_encoder;
26    struct lsquic_stream    *qeh_enc_sm_out;
27    struct frab_list         qeh_fral;
28    struct lsquic_stream    *qeh_dec_sm_in;
29    size_t                   qeh_tsu_sz;
30    unsigned char            qeh_tsu_buf[LSQPACK_LONGEST_SDTC];
31};
32
33void
34lsquic_qeh_init (struct qpack_enc_hdl *, struct lsquic_conn *);
35
36int
37lsquic_qeh_settings (struct qpack_enc_hdl *, unsigned max_table_size,
38            unsigned dyn_table_size, unsigned max_risked_streams, int server);
39
40void
41lsquic_qeh_cleanup (struct qpack_enc_hdl *);
42
43#define lsquic_qeh_has_dec_stream(qeh) ((qeh)->qeh_dec_sm_in != NULL)
44
45enum qwh_status {
46    QWH_FULL,   /* All bytes written to encoder stream.  This is also returned
47                 * if there were no bytes to write.
48                 */
49    QWH_PARTIAL,/* Not all bytes are written to the encoder stream.  In this
50                 * case, `completion_offset' is set to the value of the
51                 * encoder stream offset when the necessary bytes will have
52                 * been written.
53                 */
54    QWH_ENOBUF, /* Not enough room in `buf' to write the full header block */
55    QWH_ERR,    /* Some other error */
56};
57
58enum qwh_status
59lsquic_qeh_write_headers (struct qpack_enc_hdl *, lsquic_stream_id_t stream_id,
60    unsigned seqno, const struct lsquic_http_headers *, unsigned char *buf,
61    size_t *prefix_sz, size_t *headers_sz, uint64_t *completion_offset);
62
63uint64_t
64lsquic_qeh_enc_off (struct qpack_enc_hdl *);
65
66size_t
67lsquic_qeh_write_avail (struct qpack_enc_hdl *);
68
69size_t
70lsquic_qeh_max_prefix_size (const struct qpack_enc_hdl *);
71
72extern const struct lsquic_stream_if *const lsquic_qeh_enc_sm_out_if;
73extern const struct lsquic_stream_if *const lsquic_qeh_dec_sm_in_if;
74
75#endif
76