quic_reassembly (quic v1.10.0)

View Source

Summary

Functions

Extract contiguous data from buffer starting at Offset.

Store Data at Off unless a longer chunk is already there.

Total bytes held in a CRYPTO reassembly buffer.

Drop buffered chunks that end at or before Offset and trim those that straddle it, re-keying them to Offset.

Types

buffer/0

-type buffer() :: gb_trees:tree(non_neg_integer(), binary()).

Functions

extract_contiguous_data(Buffer, Offset)

-spec extract_contiguous_data(buffer(), non_neg_integer()) ->
                                 {binary(), non_neg_integer(), buffer(), non_neg_integer()}.

Extract contiguous data from buffer starting at Offset.

Uses a binary append accumulator, which is amortized O(1) thanks to the refc binary optimization. Returns {Delivered, NewOffset, Buffer, Removed}: Removed is how many bytes left the tree, delivered or trimmed away, so the caller can keep its byte count without walking the tree.

keep_longest_chunk(Off, Data, Buffer)

-spec keep_longest_chunk(non_neg_integer(), binary(), buffer()) -> {buffer(), integer()}.

Store Data at Off unless a longer chunk is already there.

Returns {Buffer, Delta}: the change in bytes held by the tree.

reassembly_buffer_bytes(Buffer)

-spec reassembly_buffer_bytes(buffer()) -> non_neg_integer().

Total bytes held in a CRYPTO reassembly buffer.

Stream buffers keep a running count instead and do not need this.

trim_reassembly_buffer(Buffer, Offset)

-spec trim_reassembly_buffer(buffer(), non_neg_integer()) -> {buffer(), integer()}.

Drop buffered chunks that end at or before Offset and trim those that straddle it, re-keying them to Offset.

Keeps the longest chunk at each offset, so overlapping retransmissions collapse instead of accumulating. Only chunks keyed below Offset can qualify, so the ordered walk stops there; everything above is left untouched. Returns {Buffer, Removed} with the bytes that left the tree.