lsquic_data_in_if.h revision be4cfad0
110c492f0SDmitri Tikhonov/* Copyright (c) 2017 - 2018 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
950aadb33SDmitri Tikhonov
1050aadb33SDmitri Tikhonovstruct data_frame;
1150aadb33SDmitri Tikhonovstruct data_in;
1250aadb33SDmitri Tikhonovstruct lsquic_conn_public;
1350aadb33SDmitri Tikhonovstruct stream_frame;
1450aadb33SDmitri Tikhonov
1550aadb33SDmitri Tikhonov
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
2450aadb33SDmitri Tikhonov
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};
6150aadb33SDmitri Tikhonov
6250aadb33SDmitri Tikhonov
6350aadb33SDmitri Tikhonovstruct data_in
6450aadb33SDmitri Tikhonov{
6550aadb33SDmitri Tikhonov    const struct data_in_iface  *di_if;
6650aadb33SDmitri Tikhonov    enum {
6750aadb33SDmitri Tikhonov        /* If DI_SWITCH_IMPL is set, switching data_in implementation is
6850aadb33SDmitri Tikhonov         * recommended in order to get better performance for current
6950aadb33SDmitri Tikhonov         * incoming stream frame scenario.  Check the value of this flag
7050aadb33SDmitri Tikhonov         * after calls to di_insert_frame() and di_frame_done().
7150aadb33SDmitri Tikhonov         */
7250aadb33SDmitri Tikhonov        DI_SWITCH_IMPL = (1 << 0),
7350aadb33SDmitri Tikhonov    }                            di_flags;
7450aadb33SDmitri Tikhonov};
7550aadb33SDmitri Tikhonov
7650aadb33SDmitri Tikhonov
77be4cfad0SDmitri Tikhonov/* This implementation does not support overlapping frame and may return
78be4cfad0SDmitri Tikhonov * INS_FRAME_OVERLAP.
79be4cfad0SDmitri Tikhonov */
8050aadb33SDmitri Tikhonovstruct data_in *
8150aadb33SDmitri Tikhonovdata_in_nocopy_new (struct lsquic_conn_public *, uint32_t stream_id);
8250aadb33SDmitri Tikhonov
83be4cfad0SDmitri Tikhonov/* This implementation supports overlapping frames and will never return
84be4cfad0SDmitri Tikhonov * INS_FRAME_OVERLAP.
85be4cfad0SDmitri Tikhonov */
8650aadb33SDmitri Tikhonovstruct data_in *
8750aadb33SDmitri Tikhonovdata_in_hash_new (struct lsquic_conn_public *, uint32_t stream_id,
8850aadb33SDmitri Tikhonov                  uint64_t byteage);
8950aadb33SDmitri Tikhonov
9050aadb33SDmitri Tikhonovenum ins_frame
9150aadb33SDmitri Tikhonovdata_in_hash_insert_data_frame (struct data_in *data_in,
9250aadb33SDmitri Tikhonov                const struct data_frame *data_frame, uint64_t read_offset);
9350aadb33SDmitri Tikhonov
9450aadb33SDmitri Tikhonovstruct data_in *
9550aadb33SDmitri Tikhonovdata_in_error_new ();
9650aadb33SDmitri Tikhonov
9750aadb33SDmitri Tikhonov#endif
98