lsquic_data_in_if.h revision 5392f7a3
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov/*
350aadb33SDmitri Tikhonov * lsquic_data_in_if.h -- DATA in interface
450aadb33SDmitri Tikhonov */
550aadb33SDmitri Tikhonov
650aadb33SDmitri Tikhonov#ifndef LSQUIC_DATA_IN_IF_H
750aadb33SDmitri Tikhonov#define LSQUIC_DATA_IN_IF_H 1
850aadb33SDmitri Tikhonov
95392f7a3SLiteSpeed Tech
1050aadb33SDmitri Tikhonovstruct data_frame;
1150aadb33SDmitri Tikhonovstruct data_in;
1250aadb33SDmitri Tikhonovstruct lsquic_conn_public;
1350aadb33SDmitri Tikhonovstruct stream_frame;
1450aadb33SDmitri Tikhonov
155392f7a3SLiteSpeed Tech
1650aadb33SDmitri Tikhonovenum ins_frame
1750aadb33SDmitri Tikhonov{
1850aadb33SDmitri Tikhonov    INS_FRAME_OK,
1950aadb33SDmitri Tikhonov    INS_FRAME_ERR,
2050aadb33SDmitri Tikhonov    INS_FRAME_DUP,
21be4cfad0SDmitri Tikhonov    INS_FRAME_OVERLAP,
2250aadb33SDmitri Tikhonov};
2350aadb33SDmitri Tikhonov
245392f7a3SLiteSpeed Tech
2550aadb33SDmitri Tikhonovstruct data_in_iface
2650aadb33SDmitri Tikhonov{
2750aadb33SDmitri Tikhonov    void
2850aadb33SDmitri Tikhonov    (*di_destroy) (struct data_in *);
2950aadb33SDmitri Tikhonov
3050aadb33SDmitri Tikhonov    int
3150aadb33SDmitri Tikhonov    (*di_empty) (struct data_in *);
3250aadb33SDmitri Tikhonov
33be4cfad0SDmitri Tikhonov    /* When INS_FRAME_OK, INS_FRAME_ERR, or INS_FRAME_DUP is returned, the
34be4cfad0SDmitri Tikhonov     * caller releases control of stream frame.  Do not reference it after
35be4cfad0SDmitri Tikhonov     * the call.
36be4cfad0SDmitri Tikhonov     *
37be4cfad0SDmitri Tikhonov     * When INS_FRAME_OVERLAP is returned the caller has a choice to switch
38be4cfad0SDmitri Tikhonov     * to implementation that supports overlaps and try to insert the frame
39be4cfad0SDmitri Tikhonov     * again or to treat this as an error.  Either way, the caller retains
40be4cfad0SDmitri Tikhonov     * control of the frame.
4150aadb33SDmitri Tikhonov     */
4250aadb33SDmitri Tikhonov    enum ins_frame
4350aadb33SDmitri Tikhonov    (*di_insert_frame) (struct data_in *, struct stream_frame *,
4450aadb33SDmitri Tikhonov                                                        uint64_t read_offset);
4550aadb33SDmitri Tikhonov
4650aadb33SDmitri Tikhonov    struct data_frame *
4750aadb33SDmitri Tikhonov    (*di_get_frame) (struct data_in *, uint64_t read_offset);
4850aadb33SDmitri Tikhonov
4950aadb33SDmitri Tikhonov    void
5050aadb33SDmitri Tikhonov    (*di_frame_done) (struct data_in *, struct data_frame *);
5150aadb33SDmitri Tikhonov
5250aadb33SDmitri Tikhonov    /* Creates a new data_in object, feeds its stream frames to it, deletes
5350aadb33SDmitri Tikhonov     * itself and returns the new object.
5450aadb33SDmitri Tikhonov     */
5550aadb33SDmitri Tikhonov    struct data_in *
5650aadb33SDmitri Tikhonov    (*di_switch_impl) (struct data_in *, uint64_t read_offset);
57c51ce338SDmitri Tikhonov
58c51ce338SDmitri Tikhonov    size_t
59c51ce338SDmitri Tikhonov    (*di_mem_used) (struct data_in *);
6050aadb33SDmitri Tikhonov
615392f7a3SLiteSpeed Tech    void
625392f7a3SLiteSpeed Tech    (*di_dump_state) (struct data_in *);
635392f7a3SLiteSpeed Tech
645392f7a3SLiteSpeed Tech    /* Return number of bytes readable starting at offset `read_offset' */
655392f7a3SLiteSpeed Tech    uint64_t
665392f7a3SLiteSpeed Tech    (*di_readable_bytes) (struct data_in *, uint64_t read_offset);
67355db7c6SDmitri Tikhonov};
6850aadb33SDmitri Tikhonov
695392f7a3SLiteSpeed Tech
7050aadb33SDmitri Tikhonovstruct data_in
7150aadb33SDmitri Tikhonov{
7250aadb33SDmitri Tikhonov    const struct data_in_iface  *di_if;
7350aadb33SDmitri Tikhonov    enum {
7450aadb33SDmitri Tikhonov        /* If DI_SWITCH_IMPL is set, switching data_in implementation is
7550aadb33SDmitri Tikhonov         * recommended in order to get better performance for current
7650aadb33SDmitri Tikhonov         * incoming stream frame scenario.  Check the value of this flag
7750aadb33SDmitri Tikhonov         * after calls to di_insert_frame() and di_frame_done().
7850aadb33SDmitri Tikhonov         */
7950aadb33SDmitri Tikhonov        DI_SWITCH_IMPL = (1 << 0),
8050aadb33SDmitri Tikhonov    }                            di_flags;
8150aadb33SDmitri Tikhonov};
8250aadb33SDmitri Tikhonov
835392f7a3SLiteSpeed Tech
84be4cfad0SDmitri Tikhonov/* This implementation does not support overlapping frame and may return
85be4cfad0SDmitri Tikhonov * INS_FRAME_OVERLAP.
86be4cfad0SDmitri Tikhonov */
8750aadb33SDmitri Tikhonovstruct data_in *
885392f7a3SLiteSpeed Techdata_in_nocopy_new (struct lsquic_conn_public *, lsquic_stream_id_t);
8950aadb33SDmitri Tikhonov
90be4cfad0SDmitri Tikhonov/* This implementation supports overlapping frames and will never return
91be4cfad0SDmitri Tikhonov * INS_FRAME_OVERLAP.
92be4cfad0SDmitri Tikhonov */
9350aadb33SDmitri Tikhonovstruct data_in *
945392f7a3SLiteSpeed Techdata_in_hash_new (struct lsquic_conn_public *, lsquic_stream_id_t,
9550aadb33SDmitri Tikhonov                  uint64_t byteage);
9650aadb33SDmitri Tikhonov
9750aadb33SDmitri Tikhonovenum ins_frame
9850aadb33SDmitri Tikhonovdata_in_hash_insert_data_frame (struct data_in *data_in,
9950aadb33SDmitri Tikhonov                const struct data_frame *data_frame, uint64_t read_offset);
10050aadb33SDmitri Tikhonov
10150aadb33SDmitri Tikhonovstruct data_in *
10250aadb33SDmitri Tikhonovdata_in_error_new ();
10350aadb33SDmitri Tikhonov
10450aadb33SDmitri Tikhonov#endif
105