lsquic_data_in_if.h revision 355db7c6
1/* Copyright (c) 2017 - 2018 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_data_in_if.h -- DATA in interface
4 */
5
6#ifndef LSQUIC_DATA_IN_IF_H
7#define LSQUIC_DATA_IN_IF_H 1
8
9struct data_frame;
10struct data_in;
11struct lsquic_conn_public;
12struct stream_frame;
13
14enum ins_frame
15{
16    INS_FRAME_OK,
17    INS_FRAME_ERR,
18    INS_FRAME_DUP,
19    INS_FRAME_OVERLAP,
20};
21
22struct data_in_iface
23{
24    void
25    (*di_destroy) (struct data_in *);
26
27    int
28    (*di_empty) (struct data_in *);
29
30    /* When INS_FRAME_OK, INS_FRAME_ERR, or INS_FRAME_DUP is returned, the
31     * caller releases control of stream frame.  Do not reference it after
32     * the call.
33     *
34     * When INS_FRAME_OVERLAP is returned the caller has a choice to switch
35     * to implementation that supports overlaps and try to insert the frame
36     * again or to treat this as an error.  Either way, the caller retains
37     * control of the frame.
38     */
39    enum ins_frame
40    (*di_insert_frame) (struct data_in *, struct stream_frame *,
41                                                        uint64_t read_offset);
42
43    struct data_frame *
44    (*di_get_frame) (struct data_in *, uint64_t read_offset);
45
46    void
47    (*di_frame_done) (struct data_in *, struct data_frame *);
48
49    /* Creates a new data_in object, feeds its stream frames to it, deletes
50     * itself and returns the new object.
51     */
52    struct data_in *
53    (*di_switch_impl) (struct data_in *, uint64_t read_offset);
54
55    size_t
56    (*di_mem_used) (struct data_in *);
57
58};
59
60struct data_in
61{
62    const struct data_in_iface  *di_if;
63    enum {
64        /* If DI_SWITCH_IMPL is set, switching data_in implementation is
65         * recommended in order to get better performance for current
66         * incoming stream frame scenario.  Check the value of this flag
67         * after calls to di_insert_frame() and di_frame_done().
68         */
69        DI_SWITCH_IMPL = (1 << 0),
70    }                            di_flags;
71};
72
73/* This implementation does not support overlapping frame and may return
74 * INS_FRAME_OVERLAP.
75 */
76struct data_in *
77data_in_nocopy_new (struct lsquic_conn_public *, uint32_t stream_id);
78
79/* This implementation supports overlapping frames and will never return
80 * INS_FRAME_OVERLAP.
81 */
82struct data_in *
83data_in_hash_new (struct lsquic_conn_public *, uint32_t stream_id,
84                  uint64_t byteage);
85
86enum ins_frame
87data_in_hash_insert_data_frame (struct data_in *data_in,
88                const struct data_frame *data_frame, uint64_t read_offset);
89
90struct data_in *
91data_in_error_new ();
92
93#endif
94