quic_stream (quic v1.3.0)

View Source

QUIC stream state management.

This module manages individual stream state, including: - Stream lifecycle (idle -> open -> half-closed -> closed) - Send and receive buffers - Per-stream flow control - Data ordering and reassembly

Stream Types

Stream IDs encode the initiator and directionality: - Bit 0: 0 = client-initiated, 1 = server-initiated - Bit 1: 0 = bidirectional, 1 = unidirectional

Client-initiated bidirectional: 0, 4, 8, ... Server-initiated bidirectional: 1, 5, 9, ... Client-initiated unidirectional: 2, 6, 10, ... Server-initiated unidirectional: 3, 7, 11, ...

Summary

Functions

Acknowledge that sent data was received.

Check if the stream is blocked on flow control.

Get number of bytes available for reading.

Get number of bytes waiting to be sent.

Check if we can send data on this stream.

Close the stream gracefully.

Get the direction of the stream.

Get the stream priority. Returns {Urgency, Incremental} where Urgency is 0-7 (lower = more urgent) and Incremental indicates whether data can be processed incrementally.

Get data to send, up to MaxBytes. Returns {Data, Offset, Fin, UpdatedStream}

Get the stream ID.

Get the initiator of the stream.

Check if this is a bidirectional stream.

Check if the stream is fully closed.

Check if this stream was initiated by us.

Check if the receive side is closed.

Check if the send side is closed.

Create a new stream with default flow control limits.

Create a new stream with custom options.

Read all available contiguous data.

Read up to MaxBytes of contiguous data.

Receive data at a specific offset.

Mark that FIN was received at the given offset.

Reset the stream (send RESET_STREAM).

Queue data for sending on the stream.

Mark the stream as finished for sending (FIN).

Set the stream priority. Urgency: 0-7 (lower = more urgent, default 3) Incremental: boolean (data can be processed incrementally, default false) Returns {ok, UpdatedStream} or {error, invalid_urgency}.

Get the current stream state.

Handle STOP_SENDING frame from peer.

Update the maximum data we can receive.

Update the send window (peer's MAX_STREAM_DATA).

Types

stream/0

-opaque stream()

Functions

ack_send(Stream, AckedOffset)

-spec ack_send(stream(), non_neg_integer()) -> stream().

Acknowledge that sent data was received.

blocked(Stream)

-spec blocked(stream()) -> boolean().

Check if the stream is blocked on flow control.

bytes_available(Stream)

-spec bytes_available(stream()) -> non_neg_integer().

Get number of bytes available for reading.

bytes_to_send(Stream)

-spec bytes_to_send(stream()) -> non_neg_integer().

Get number of bytes waiting to be sent.

can_send(Stream)

-spec can_send(stream()) -> boolean().

Check if we can send data on this stream.

close(Stream)

-spec close(stream()) -> stream().

Close the stream gracefully.

direction(Stream)

-spec direction(stream()) -> bidirectional | unidirectional.

Get the direction of the stream.

get_priority(Stream)

-spec get_priority(stream()) -> {0..7, boolean()}.

Get the stream priority. Returns {Urgency, Incremental} where Urgency is 0-7 (lower = more urgent) and Incremental indicates whether data can be processed incrementally.

get_send_data(Stream, MaxBytes)

-spec get_send_data(stream(), non_neg_integer()) -> {binary(), non_neg_integer(), boolean(), stream()}.

Get data to send, up to MaxBytes. Returns {Data, Offset, Fin, UpdatedStream}

id(Stream)

-spec id(stream()) -> non_neg_integer().

Get the stream ID.

initiator(Stream)

-spec initiator(stream()) -> client | server.

Get the initiator of the stream.

is_bidi(Stream)

-spec is_bidi(stream()) -> boolean().

Check if this is a bidirectional stream.

is_closed(Stream)

-spec is_closed(stream()) -> boolean().

Check if the stream is fully closed.

is_local(Stream, Role)

-spec is_local(stream(), client | server) -> boolean().

Check if this stream was initiated by us.

is_recv_closed(Stream)

-spec is_recv_closed(stream()) -> boolean().

Check if the receive side is closed.

is_send_closed(Stream)

-spec is_send_closed(stream()) -> boolean().

Check if the send side is closed.

new(StreamId, Role)

-spec new(non_neg_integer(), client | server) -> stream().

Create a new stream with default flow control limits.

new(StreamId, Role, Opts)

-spec new(non_neg_integer(), client | server, map()) -> stream().

Create a new stream with custom options.

read(Stream)

-spec read(stream()) -> {binary(), stream()}.

Read all available contiguous data.

read(Stream, MaxBytes)

-spec read(stream(), non_neg_integer() | infinity) -> {binary(), stream()}.

Read up to MaxBytes of contiguous data.

receive_data(Stream, Offset, Data, Fin)

-spec receive_data(stream(), non_neg_integer(), binary(), boolean()) -> {ok, stream()} | {error, term()}.

Receive data at a specific offset.

receive_fin(Stream, FinalSize)

-spec receive_fin(stream(), non_neg_integer()) -> {ok, stream()} | {error, term()}.

Mark that FIN was received at the given offset.

reset(Stream, ErrorCode)

-spec reset(stream(), non_neg_integer()) -> stream().

Reset the stream (send RESET_STREAM).

send(Stream, Data)

-spec send(stream(), binary()) -> {ok, stream()} | {error, term()}.

Queue data for sending on the stream.

send_fin(Stream)

-spec send_fin(stream()) -> {ok, stream()} | {error, term()}.

Mark the stream as finished for sending (FIN).

set_priority(Stream, Urgency, Incremental)

-spec set_priority(stream(), 0..7, boolean()) -> {ok, stream()} | {error, invalid_urgency}.

Set the stream priority. Urgency: 0-7 (lower = more urgent, default 3) Incremental: boolean (data can be processed incrementally, default false) Returns {ok, UpdatedStream} or {error, invalid_urgency}.

state(Stream)

-spec state(stream()) -> idle | open | half_closed_local | half_closed_remote | closed.

Get the current stream state.

stop_sending(Stream, ErrorCode)

-spec stop_sending(stream(), non_neg_integer()) -> stream().

Handle STOP_SENDING frame from peer.

update_max_data(Stream, NewMax)

-spec update_max_data(stream(), non_neg_integer()) -> stream().

Update the maximum data we can receive.

update_send_window(Stream, NewMax)

-spec update_send_window(stream(), non_neg_integer()) -> stream().

Update the send window (peer's MAX_STREAM_DATA).