Skip to main content

RecvStream

Trait RecvStream 

Source
pub trait RecvStream: 'static {
    type Error: Error;
    type Lease<'a>: Lease
       where Self: 'a;

    // Required methods
    fn poll_lease(
        &mut self,
        waiter: &Waiter,
        want: usize,
    ) -> Poll<Result<Self::Lease<'_>, Self::Error>>;
    fn set_priority(&mut self, priority: i64);
    fn stop(&mut self, code: u32);

    // Provided methods
    fn poll_reset(&mut self, waiter: &Waiter) -> Poll<Self::Error> { ... }
    fn set_window(&mut self, window: u64) -> Option<u64> { ... }
    fn poll_read_chunk(
        &mut self,
        waiter: &Waiter,
        max: usize,
    ) -> Poll<Result<Option<Bytes>, Self::Error>> { ... }
    fn read_chunk(&mut self, max: usize) -> ReadChunk<'_, Self> ⓘ { ... }
}
Expand description

An incoming stream, read through leases of the bytes its transport buffers.

Leased bytes stay in the transport, counted against its flow control, until Lease::release returns the credit of those read, so an incomplete message holds receive credit rather than memory of its own. When incomplete messages leave no credit for any of them to finish, a transport that bounds them evicts the lowest priority holder, whose next lease fails. A transport that returns credit as it reads, adapted with Buffered, is not bounded this way.

Required Associated Types§

Source

type Error: Error

The error type for every operation on this stream.

Source

type Lease<'a>: Lease where Self: 'a

The unreleased bytes borrowed from this stream.

Required Methods§

Source

fn poll_lease( &mut self, waiter: &Waiter, want: usize, ) -> Poll<Result<Self::Lease<'_>, Self::Error>>

Poll until at least want bytes are leased, or the peer finished the stream with fewer.

Reading the lease as a Buf moves past bytes for good, but they keep their flow-control credit until Lease::release. Bytes not read stay for the next lease. A want the stream’s receive window can never hold is an error rather than a wait, and a want of 0 never waits.

A lease may borrow the transport’s connection state, so release it before touching any other stream of the session.

Source

fn set_priority(&mut self, priority: i64)

Rank this stream for eviction when incomplete messages exhaust the receive window.

Higher keeps it longer, the convention of SendStream::set_priority. A stream starts at 0, and ties evict the newest stream first. A transport without eviction ignores it.

Source

fn stop(&mut self, code: u32)

Send a STOP_SENDING QUIC code, informing the peer that no more data will be read, and discard what is buffered.

An implementation MUST do this on Drop otherwise flow control will be leaked. Call this method manually if you want to specify a code yourself.

Provided Methods§

Source

fn poll_reset(&mut self, waiter: &Waiter) -> Poll<Self::Error>

Poll until the stream fails without reading it: the peer resets it, the receiver evicts it to free a stuck window, or the connection closes. Pending for good once the peer finished it.

A session that stops reading a stream, to pace it (see Session::receive_window) or until a control message says how to read it, watches this instead, so a reset still ends the group it carries and an eviction stops the stream. It takes no bytes and grants no credit. The default never completes, which suits a transport reporting no receive window, since none of its streams pause.

Source

fn set_window(&mut self, window: u64) -> Option<u64>

Let the peer send at most window bytes past what the reader took, rather than the stream’s full receive credit, returning the connection credit the stream may hold from now on: the bytes that arrived and were not released, and those the peer may still send.

A session pacing a stream (see Session::receive_window) shrinks its window as the group runs out of room, so the stream holds little once paused, and many fit in the connection window. Credit already granted stays granted. None when the transport cannot, the default, whose paused streams hold their full stream credit.

A transport that can also implements Lease::set_window.

Source

fn poll_read_chunk( &mut self, waiter: &Waiter, max: usize, ) -> Poll<Result<Option<Bytes>, Self::Error>>

Poll for the next chunk, up to max bytes, or None once the peer finished the stream. Its credit returns as it is read.

An empty max reads nothing and returns an empty chunk: asking for no bytes is not end of stream.

Source

fn read_chunk(&mut self, max: usize) -> ReadChunk<'_, Self> ⓘ

Read the next chunk, up to max bytes, or None once finished.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<S: Chunks> RecvStream for Buffered<S>

Source§

type Error = <S as Chunks>::Error

Source§

type Lease<'a> = BufferedLease<'a> where S: 'a