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