Skip to main content

Stream

Struct Stream 

Source
pub struct Stream { /* private fields */ }
Expand description

Stream - multiplexed data channel within a session

Implementations§

Source§

impl Stream

Source

pub fn new(id: StreamId) -> Self

Create a new stream

Source

pub fn id(&self) -> StreamId

Get stream ID

Source

pub async fn state(&self) -> StreamState

Get current state

Source

pub fn priority(&self) -> u32

Get priority

Source

pub fn set_priority(&self, priority: u32)

Set priority

Source

pub fn peer_send_window(&self) -> u32

Bytes the peer currently allows us to send.

Source

pub fn try_consume_send_window(&self, n: u32) -> bool

Atomically reserve n bytes from the peer’s send window. Returns true if the reservation succeeded (and the window was decremented); false if the window doesn’t have enough capacity — caller must wait for a WINDOW_UPDATE.

Source

pub fn apply_peer_window_update(&self, credit: u32)

Process an inbound WINDOW_UPDATE from the peer. The payload is a relative credit — the number of bytes the peer’s application just consumed and is therefore newly willing to receive. We add it to the send window (saturating at MAX_SEND_WINDOW so a misbehaving peer’s inflated credit cannot overflow the counter).

Relative credit (vs. an absolute window) is what makes flow control correct for a session of any length: the sender’s window is initial + Σ credit_granted − Σ bytes_sent = initial + consumed − sent, so the receiver’s outstanding (unconsumed) bytes sent − consumed are bounded by initial. An absolute u32 window could not express this for sessions exceeding 4 GiB and over-committed the receiver’s buffer.

Source

pub fn local_recv_window(&self) -> u32

Bytes the local side has granted the peer.

Source

pub fn record_app_consumed(&self, n: u32) -> Option<u32>

Record that the application has actually consumed n bytes from this stream (called by the receive delivery task on real drainage, not on routing). Accumulates the consumed bytes and, once the unreported total crosses half the initial window, returns Some(credit) — the relative credit to advertise in a WINDOW_UPDATE (the peer adds it to its send window). The half-window threshold trades update frequency against peer stalls.

Source

pub fn stage_window_update_credit(&self, credit: u32)

Stage relative flow-control credit to be flushed by the send loop. Called by the receive delivery task after it credits real app consumption. Credits accumulate additively (saturating at u32::MAX) rather than overwriting, so several grants landing between two send-loop flushes are summed instead of lost — the send loop is the single emitter (epoch-safe), and it may run arbitrarily after a grant.

Source

pub fn take_pending_window_update(&self) -> Option<u32>

Take all staged credit (swaps the slot back to 0). The send loop calls this each drain pass and emits one WINDOW_UPDATE carrying the summed credit if Some.

Source

pub async fn send_reliable(&self, data: Bytes) -> SequenceNumber

Queue data for sending with reliability

Returns the sequence number assigned to this chunk.

Source

pub fn next_send_sequence(&self) -> SequenceNumber

Reserve the next outbound sequence number from this stream’s send space.

Control frames that are emitted directly on a data stream (e.g. WINDOW_UPDATE, a bare FIN) MUST draw their sequence from here rather than a private counter: the AEAD nonce is (epoch, stream_id, sequence, path_id) and the receiver’s replay window is keyed on (stream_id, sequence), so a control frame sharing a (stream_id, sequence) with a data packet in the same epoch would reuse a nonce and be dropped as a replay. Sharing one monotonic space keeps every packet on the stream unique. Control frames are unreliable, so the resulting gap in the data sequence is harmless (no ACK is expected, nothing waits to reassemble it).

Source

pub async fn send_unreliable(&self, data: Bytes) -> SequenceNumber

Queue data for unreliable sending

Returns the sequence number assigned to this chunk.

Source

pub async fn poll_send(&self, cwnd_budget: u64) -> Option<OutboundSegment>

Get the next segment to (re)transmit, or None if nothing is due.

cwnd_budget is how many bytes of new data the congestion window currently permits. Retransmissions ignore it — loss recovery must always proceed — but a first transmission is withheld (None) when it would exceed the budget, so the next drain resumes once ACKs free the window. Pass u64::MAX to disable the limit.

Source

pub async fn ack(&self, sequence: SequenceNumber) -> Option<(Instant, u64)>

Mark a sequence number as acknowledged. Returns the timestamp when the packet was originally sent and its size, if found.

Source

pub async fn mark_unsent(&self, sequence: SequenceNumber)

Reset a still-buffered reliable segment’s send timestamp so the next poll_send re-offers it immediately (as an unsent segment) rather than waiting a full RTO for the retransmit pass. Used when a send attempt failed after poll_send had already stamped sent_at — the bytes never reached the wire, so the segment must not be treated as in-flight. No-op if the segment was already acknowledged and removed.

Source

pub async fn on_receive(&self, sequence: SequenceNumber, data: Bytes)

Handle received data

Data is buffered until it can be delivered in order.

Source

pub async fn recv(&self) -> Option<Bytes>

Read data from the stream (async, waits if no data available)

Source

pub async fn try_recv(&self) -> Option<Bytes>

Try to read data without waiting

Source

pub async fn finish(&self)

Mark local side as finished (no more data to send)

Source

pub async fn on_remote_finish(&self)

Mark remote side as finished

Source

pub async fn pending_send_count(&self) -> usize

Get number of pending send chunks

Source

pub async fn pending_recv_count(&self) -> usize

Get number of pending receive chunks

Source

pub fn is_closed(&self) -> bool

Check if stream is closed

Trait Implementations§

Source§

impl Debug for Stream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
Source§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more