litespeed-quic/src/liblsquic/lsquic_data_in_if.h

112 lines
3.0 KiB
C
Raw Normal View History

2022-05-06 16:49:46 +00:00
/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */
2017-09-22 21:00:03 +00:00
/*
* lsquic_data_in_if.h -- DATA in interface
*/
#ifndef LSQUIC_DATA_IN_IF_H
#define LSQUIC_DATA_IN_IF_H 1
2017-09-22 21:00:03 +00:00
struct data_frame;
struct data_in;
struct lsquic_conn_public;
struct stream_frame;
2017-09-22 21:00:03 +00:00
enum ins_frame
{
INS_FRAME_OK,
INS_FRAME_ERR,
INS_FRAME_DUP,
2018-05-04 18:00:34 +00:00
INS_FRAME_OVERLAP,
2017-09-22 21:00:03 +00:00
};
2017-09-22 21:00:03 +00:00
struct data_in_iface
{
void
(*di_destroy) (struct data_in *);
int
(*di_empty) (struct data_in *);
2018-05-04 18:00:34 +00:00
/* When INS_FRAME_OK, INS_FRAME_ERR, or INS_FRAME_DUP is returned, the
* caller releases control of stream frame. Do not reference it after
* the call.
*
* When INS_FRAME_OVERLAP is returned the caller has a choice to switch
* to implementation that supports overlaps and try to insert the frame
* again or to treat this as an error. Either way, the caller retains
* control of the frame.
2017-09-22 21:00:03 +00:00
*/
enum ins_frame
(*di_insert_frame) (struct data_in *, struct stream_frame *,
uint64_t read_offset);
struct data_frame *
(*di_get_frame) (struct data_in *, uint64_t read_offset);
void
(*di_frame_done) (struct data_in *, struct data_frame *);
/* Creates a new data_in object, feeds its stream frames to it, deletes
* itself and returns the new object.
*/
struct data_in *
(*di_switch_impl) (struct data_in *, uint64_t read_offset);
Latest changes - [API Change] Sendfile-like functionality is gone. The stream no longer opens files and deals with file descriptors. (Among other things, this makes the code more portable.) Three writing functions are provided: lsquic_stream_write lsquic_stream_writev lsquic_stream_writef (NEW) lsquic_stream_writef() is given an abstract reader that has function pointers for size() and read() functions which the user can implement. This is the most flexible way. lsquic_stream_write() and lsquic_stream_writev() are now both implemented as wrappers around lsquic_stream_writef(). - [OPTIMIZATION] When writing to stream, be it within or without the on_write() callback, place data directly into packet buffer, bypassing auxiliary data structures. This reduces amount of memory required, for the amount of data that can be written is limited by the congestion window. To support writes outside the on_write() callback, we keep N outgoing packet buffers per connection which can be written to by any stream. One half of these are reserved for the highest priority stream(s), the other half for all other streams. This way, low-priority streams cannot write instead of high-priority streams and, on the other hand, low-priority streams get a chance to send their packets out. The algorithm is as follows: - When user writes to stream outside of the callback: - If this is the highest priority stream, place it onto the reserved N/2 queue or fail. (The actual size of this queue is dynamic -- MAX(N/2, CWND) -- rather than N/2, allowing high-priority streams to write as much as can be sent.) - If the stream is not the highest priority, try to place the data onto the reserved N/2 queue or fail. - When tick occurs *and* more packets can be scheduled: - Transfer packets from the high N/2 queue to the scheduled queue. - If more scheduling is allowed: - Call on_write callbacks for highest-priority streams, placing resulting packets directly onto the scheduled queue. - If more scheduling is allowed: - Transfer packets from the low N/2 queue to the scheduled queue. - If more scheduling is allowed: - Call on_write callbacks for non-highest-priority streams, placing resulting packets directly onto the scheduled queue The number N is currently 20, but it could be varied based on resource usage. - If stream is created due to incoming headers, make headers readable from on_new. - Outgoing packets are no longer marked non-writeable to prevent placing more than one STREAM frame from the same stream into a single packet. This property is maintained via code flow and an explicit check. Packets for stream data are allocated using a special function. - STREAM frame elision is cheaper, as we only perform it if a reset stream has outgoing packets referencing it. - lsquic_packet_out_t is smaller, as stream_rec elements are now inside a union.
2017-10-31 13:35:58 +00:00
size_t
(*di_mem_used) (struct data_in *);
2017-09-22 21:00:03 +00:00
void
(*di_dump_state) (struct data_in *);
/* Return number of bytes readable starting at offset `read_offset' */
uint64_t
(*di_readable_bytes) (struct data_in *, uint64_t read_offset);
/* If set, this means that when di_insert_frame() returns INS_FRAME_OK,
* the data_in handler has taken ownership of the frame. Otherwise, it
* is up to the caller to free it.
*/
const int
di_own_on_ok;
};
2017-09-22 21:00:03 +00:00
2017-09-22 21:00:03 +00:00
struct data_in
{
const struct data_in_iface *di_if;
enum {
/* If DI_SWITCH_IMPL is set, switching data_in implementation is
* recommended in order to get better performance for current
* incoming stream frame scenario. Check the value of this flag
* after calls to di_insert_frame() and di_frame_done().
*/
DI_SWITCH_IMPL = (1 << 0),
} di_flags;
};
2018-05-04 18:00:34 +00:00
/* This implementation does not support overlapping frame and may return
* INS_FRAME_OVERLAP.
*/
2017-09-22 21:00:03 +00:00
struct data_in *
lsquic_data_in_nocopy_new (struct lsquic_conn_public *, lsquic_stream_id_t);
2017-09-22 21:00:03 +00:00
2018-05-04 18:00:34 +00:00
/* This implementation supports overlapping frames and will never return
* INS_FRAME_OVERLAP.
*/
2017-09-22 21:00:03 +00:00
struct data_in *
lsquic_data_in_hash_new (struct lsquic_conn_public *, lsquic_stream_id_t,
2017-09-22 21:00:03 +00:00
uint64_t byteage);
enum ins_frame
lsquic_data_in_hash_insert_data_frame (struct data_in *data_in,
2017-09-22 21:00:03 +00:00
const struct data_frame *data_frame, uint64_t read_offset);
struct data_in *
lsquic_data_in_error_new ();
2017-09-22 21:00:03 +00:00
#endif