lsquic_data_in_if.h revision 229fce07
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
950aadb33SDmitri Tikhonovstruct data_frame;
1050aadb33SDmitri Tikhonovstruct data_in;
1150aadb33SDmitri Tikhonovstruct lsquic_conn_public;
1250aadb33SDmitri Tikhonovstruct stream_frame;
1350aadb33SDmitri Tikhonov
1450aadb33SDmitri Tikhonovenum ins_frame
1550aadb33SDmitri Tikhonov{
1650aadb33SDmitri Tikhonov    INS_FRAME_OK,
1750aadb33SDmitri Tikhonov    INS_FRAME_ERR,
1850aadb33SDmitri Tikhonov    INS_FRAME_DUP,
19be4cfad0SDmitri Tikhonov    INS_FRAME_OVERLAP,
2050aadb33SDmitri Tikhonov};
2150aadb33SDmitri Tikhonov
2250aadb33SDmitri Tikhonovstruct data_in_iface
2350aadb33SDmitri Tikhonov{
2450aadb33SDmitri Tikhonov    void
2550aadb33SDmitri Tikhonov    (*di_destroy) (struct data_in *);
2650aadb33SDmitri Tikhonov
2750aadb33SDmitri Tikhonov    int
2850aadb33SDmitri Tikhonov    (*di_empty) (struct data_in *);
2950aadb33SDmitri Tikhonov
30be4cfad0SDmitri Tikhonov    /* When INS_FRAME_OK, INS_FRAME_ERR, or INS_FRAME_DUP is returned, the
31be4cfad0SDmitri Tikhonov     * caller releases control of stream frame.  Do not reference it after
32be4cfad0SDmitri Tikhonov     * the call.
33be4cfad0SDmitri Tikhonov     *
34be4cfad0SDmitri Tikhonov     * When INS_FRAME_OVERLAP is returned the caller has a choice to switch
35be4cfad0SDmitri Tikhonov     * to implementation that supports overlaps and try to insert the frame
36be4cfad0SDmitri Tikhonov     * again or to treat this as an error.  Either way, the caller retains
37be4cfad0SDmitri Tikhonov     * control of the frame.
3850aadb33SDmitri Tikhonov     */
3950aadb33SDmitri Tikhonov    enum ins_frame
4050aadb33SDmitri Tikhonov    (*di_insert_frame) (struct data_in *, struct stream_frame *,
4150aadb33SDmitri Tikhonov                                                        uint64_t read_offset);
4250aadb33SDmitri Tikhonov
4350aadb33SDmitri Tikhonov    struct data_frame *
4450aadb33SDmitri Tikhonov    (*di_get_frame) (struct data_in *, uint64_t read_offset);
4550aadb33SDmitri Tikhonov
4650aadb33SDmitri Tikhonov    void
4750aadb33SDmitri Tikhonov    (*di_frame_done) (struct data_in *, struct data_frame *);
4850aadb33SDmitri Tikhonov
4950aadb33SDmitri Tikhonov    /* Creates a new data_in object, feeds its stream frames to it, deletes
5050aadb33SDmitri Tikhonov     * itself and returns the new object.
5150aadb33SDmitri Tikhonov     */
5250aadb33SDmitri Tikhonov    struct data_in *
5350aadb33SDmitri Tikhonov    (*di_switch_impl) (struct data_in *, uint64_t read_offset);
54c51ce338SDmitri Tikhonov
55c51ce338SDmitri Tikhonov    size_t
56c51ce338SDmitri Tikhonov    (*di_mem_used) (struct data_in *);
5750aadb33SDmitri Tikhonov
58355db7c6SDmitri Tikhonov};
5950aadb33SDmitri Tikhonov
6050aadb33SDmitri Tikhonovstruct data_in
6150aadb33SDmitri Tikhonov{
6250aadb33SDmitri Tikhonov    const struct data_in_iface  *di_if;
6350aadb33SDmitri Tikhonov    enum {
6450aadb33SDmitri Tikhonov        /* If DI_SWITCH_IMPL is set, switching data_in implementation is
6550aadb33SDmitri Tikhonov         * recommended in order to get better performance for current
6650aadb33SDmitri Tikhonov         * incoming stream frame scenario.  Check the value of this flag
6750aadb33SDmitri Tikhonov         * after calls to di_insert_frame() and di_frame_done().
6850aadb33SDmitri Tikhonov         */
6950aadb33SDmitri Tikhonov        DI_SWITCH_IMPL = (1 << 0),
7050aadb33SDmitri Tikhonov    }                            di_flags;
7150aadb33SDmitri Tikhonov};
7250aadb33SDmitri Tikhonov
73be4cfad0SDmitri Tikhonov/* This implementation does not support overlapping frame and may return
74be4cfad0SDmitri Tikhonov * INS_FRAME_OVERLAP.
75be4cfad0SDmitri Tikhonov */
7650aadb33SDmitri Tikhonovstruct data_in *
7750aadb33SDmitri Tikhonovdata_in_nocopy_new (struct lsquic_conn_public *, uint32_t stream_id);
7850aadb33SDmitri Tikhonov
79be4cfad0SDmitri Tikhonov/* This implementation supports overlapping frames and will never return
80be4cfad0SDmitri Tikhonov * INS_FRAME_OVERLAP.
81be4cfad0SDmitri Tikhonov */
8250aadb33SDmitri Tikhonovstruct data_in *
8350aadb33SDmitri Tikhonovdata_in_hash_new (struct lsquic_conn_public *, uint32_t stream_id,
8450aadb33SDmitri Tikhonov                  uint64_t byteage);
8550aadb33SDmitri Tikhonov
8650aadb33SDmitri Tikhonovenum ins_frame
8750aadb33SDmitri Tikhonovdata_in_hash_insert_data_frame (struct data_in *data_in,
8850aadb33SDmitri Tikhonov                const struct data_frame *data_frame, uint64_t read_offset);
8950aadb33SDmitri Tikhonov
9050aadb33SDmitri Tikhonovstruct data_in *
9150aadb33SDmitri Tikhonovdata_in_error_new ();
9250aadb33SDmitri Tikhonov
9350aadb33SDmitri Tikhonov#endif
94