pub struct StreamDemultiplexer { /* private fields */ }Expand description
A lightweight stream demultiplexer that routes packets to registered streams.
§Design
UDP Socket → StreamDemultiplexer → Stream[0] (reliable)
→ Stream[1] (reliable)
→ Stream[2] (unreliable)
→ control channelEach stream is identified by a u32 stream ID extracted from the packet header.
Unrecognized stream IDs are dropped (with a log warning).
Implementations§
Source§impl StreamDemultiplexer
impl StreamDemultiplexer
Sourcepub fn new(control_buffer: usize) -> (Self, Receiver<Bytes>)
pub fn new(control_buffer: usize) -> (Self, Receiver<Bytes>)
Create a new demultiplexer with a control channel.
The control channel (stream_id = 0) receives session-level packets such as keepalives, migration signals, and stream management.
Sourcepub fn open_stream(&self, buffer_size: usize) -> StreamHandle
pub fn open_stream(&self, buffer_size: usize) -> StreamHandle
Register a new stream and get back a handle with the assigned ID.
buffer_size controls the depth of the per-stream receive buffer.
Sourcepub fn register_stream(
&self,
stream_id: u32,
buffer_size: usize,
) -> StreamHandle
pub fn register_stream( &self, stream_id: u32, buffer_size: usize, ) -> StreamHandle
Register a stream with a specific ID (e.g., for accepting remote-initiated streams).
Sourcepub fn close_stream(&self, stream_id: u32)
pub fn close_stream(&self, stream_id: u32)
Remove a stream from the routing table.
Sourcepub fn route_data(&self, stream_id: u32, payload: Bytes) -> bool
pub fn route_data(&self, stream_id: u32, payload: Bytes) -> bool
Route data payload to the appropriate stream.
Returns true if the packet was successfully delivered,
false if the stream was not found or the buffer was full.
Sourcepub async fn route_data_async(&self, stream_id: u32, payload: Bytes) -> bool
pub async fn route_data_async(&self, stream_id: u32, payload: Bytes) -> bool
Route data asynchronously (waits if buffer is full).
Sourcepub fn route_ack(&self, stream_id: u32, seq: SequenceNumber) -> bool
pub fn route_ack(&self, stream_id: u32, seq: SequenceNumber) -> bool
Route an ACK signal to a stream without blocking. Returns
false if the stream is unknown or its buffer is full — the recv pump
uses this on its never-block path, where a vestigial/absent stream
consumer must not stall inbound ACK/control processing.
Sourcepub fn route_close(&self, stream_id: u32) -> bool
pub fn route_close(&self, stream_id: u32) -> bool
Route a stream-closure signal without blocking (see Self::route_ack).
Sourcepub async fn route_ack_async(&self, stream_id: u32, seq: SequenceNumber) -> bool
pub async fn route_ack_async(&self, stream_id: u32, seq: SequenceNumber) -> bool
Route an ACK signal to a stream asynchronously.
Sourcepub async fn route_close_async(&self, stream_id: u32) -> bool
pub async fn route_close_async(&self, stream_id: u32) -> bool
Route a stream closure signal asynchronously.
Sourcepub fn active_stream_count(&self) -> usize
pub fn active_stream_count(&self) -> usize
Number of active streams (excluding control channel).
Sourcepub fn has_stream(&self, stream_id: u32) -> bool
pub fn has_stream(&self, stream_id: u32) -> bool
Check if a stream is registered.