Struct RecvStream

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

A stream that can only be used to receive data

stop(0) is implicitly called on drop unless:

  • A variant of ReadError has been yielded by a read call
  • stop() was called explicitly

§Cancellation

A read method is said to be cancel-safe when dropping its future before the future becomes ready cannot lead to loss of stream data. This is true of methods which succeed immediately when any progress is made, and is not true of methods which might need to perform multiple reads internally before succeeding. Each read method documents whether it is cancel-safe.

§Common issues

§Data never received on a locally-opened stream

Peers are not notified of streams until they or a later-numbered stream are used to send data. If a bidirectional stream is locally opened but never used to send, then the peer may never see it. Application protocols should always arrange for the endpoint which will first transmit on a stream to be the endpoint responsible for opening it.

§Data never received on a remotely-opened stream

Verify that the stream you are receiving is the same one that the server is sending on, e.g. by logging the id of each. Streams are always accepted in the same order as they are created, i.e. ascending order by StreamId. For example, even if a sender first transmits on bidirectional stream 1, the first stream yielded by Connection::accept_bi on the receiver will be bidirectional stream 0.

Implementations§

Source§

impl RecvStream

Source

pub fn id(&self) -> StreamId

Get the identity of this stream

Source

pub fn is_0rtt(&self) -> bool

Check if this stream has been opened during 0-RTT.

In which case any non-idempotent request should be considered dangerous at the application level. Because read data is subject to replay attacks.

Source

pub fn stop(&mut self, error_code: VarInt) -> Result<(), ClosedStream>

Stop accepting data

Discards unread data and notifies the peer to stop transmitting. Once stopped, further attempts to operate on a stream will yield ClosedStream errors.

Source

pub async fn stopped(&mut self) -> Result<Option<VarInt>, StoppedError>

Completes when the stream has been reset by the peer or otherwise closed.

Yields Some with the reset error code when the stream is reset by the peer. Yields None when the stream was previously stop()ed, or when the stream was finish()ed by the peer and all data has been received, after which it is no longer meaningful for the stream to be reset.

This operation is cancel-safe.

Source

pub async fn read( &mut self, buf: impl BufMut, ) -> Result<Option<usize>, ReadError>

Read data contiguously from the stream.

Yields the number of bytes read into buf on success, or None if the stream was finished.

This operation is cancel-safe.

Source

pub async fn read_exact( &mut self, buf: impl BufMut, ) -> Result<(), ReadExactError>

Read an exact number of bytes contiguously from the stream.

See read() for details. This operation is not cancel-safe.

Source

pub async fn read_chunk( &mut self, max_length: usize, ordered: bool, ) -> Result<Option<Chunk>, ReadError>

Read the next segment of data.

Yields None if the stream was finished. Otherwise, yields a segment of data and its offset in the stream. If ordered is true, the chunk’s offset will be immediately after the last data yielded by read() or read_chunk(). If ordered is false, segments may be received in any order, and the Chunk’s offset field can be used to determine ordering in the caller. Unordered reads are less prone to head-of-line blocking within a stream, but require the application to manage reassembling the original data.

Slightly more efficient than read due to not copying. Chunk boundaries do not correspond to peer writes, and hence cannot be used as framing.

This operation is cancel-safe.

Source

pub async fn read_chunks( &mut self, bufs: &mut [Bytes], ) -> Result<Option<usize>, ReadError>

Read the next segments of data.

Fills bufs with the segments of data beginning immediately after the last data yielded by read or read_chunk, or None if the stream was finished.

Slightly more efficient than read due to not copying. Chunk boundaries do not correspond to peer writes, and hence cannot be used as framing.

This operation is cancel-safe.

Source

pub async fn read_to_end( &mut self, buf: impl BufMut, ) -> Result<usize, ReadError>

Convenience method to read all remaining data into a buffer.

Uses unordered reads to be more efficient than using AsyncRead. If unordered reads have already been made, the resulting buffer may have gaps containing zero.

Depending on BufMut implementation, this method may fail with ReadError::BufferTooShort if the buffer is not large enough to hold the entire stream. For example when using a &mut [u8] it will never receive bytes more than the length of the slice, but when using a &mut Vec<u8> it will allocate more memory as needed.

This operation is not cancel-safe.

Trait Implementations§

Source§

impl AsyncRead for RecvStream

Source§

async fn read<B: IoBufMut>(&mut self, buf: B) -> BufResult<usize, B>

Read some bytes from this source into the IoBufMut buffer and return a BufResult, consisting of the buffer and a usize indicating how many bytes were read. Read more
Source§

async fn read_vectored<V>(&mut self, buf: V) -> BufResult<usize, V>

Like read, except that it reads into a type implements IoVectoredBufMut. Read more
Source§

impl AsyncRead for RecvStream

Available on crate feature io-compat only.
Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize>>

Attempt to read from the AsyncRead into buf. Read more
Source§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Source§

impl Debug for RecvStream

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for RecvStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl RecvStream for RecvStream

Available on crate feature h3 only.
Source§

type Buf = Bytes

The type of Buf for data received on this stream.
Source§

fn poll_data( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Option<Self::Buf>, StreamErrorIncoming>>

Poll the stream for more data. Read more
Source§

fn stop_sending(&mut self, error_code: u64)

Send a STOP_SENDING QUIC code.
Source§

fn recv_id(&self) -> StreamId

Get QUIC send stream id

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<A> AsyncReadExt for A
where A: AsyncRead + ?Sized,

Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of AsyncRead. Read more
Source§

async fn read_exact<T>(&mut self, buf: T) -> BufResult<(), T>
where T: IoBufMut,

Read the exact number of bytes required to fill the buf.
Source§

async fn read_to_end(&mut self, buf: Vec<u8>) -> BufResult<usize, Vec<u8>>

Read all bytes until underlying reader reaches EOF.
Source§

async fn read_vectored_exact<T>(&mut self, buf: T) -> BufResult<(), T>

Read the exact number of bytes required to fill the vectored buf.
Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adaptor which reads at most limit bytes from it. Read more
Source§

async fn read_u8(&mut self) -> Result<u8, Error>

Read a big endian u8 from the underlying reader.
Source§

async fn read_u8_le(&mut self) -> Result<u8, Error>

Read a little endian u8 from the underlying reader.
Source§

async fn read_u16(&mut self) -> Result<u16, Error>

Read a big endian u16 from the underlying reader.
Source§

async fn read_u16_le(&mut self) -> Result<u16, Error>

Read a little endian u16 from the underlying reader.
Source§

async fn read_u32(&mut self) -> Result<u32, Error>

Read a big endian u32 from the underlying reader.
Source§

async fn read_u32_le(&mut self) -> Result<u32, Error>

Read a little endian u32 from the underlying reader.
Source§

async fn read_u64(&mut self) -> Result<u64, Error>

Read a big endian u64 from the underlying reader.
Source§

async fn read_u64_le(&mut self) -> Result<u64, Error>

Read a little endian u64 from the underlying reader.
Source§

async fn read_u128(&mut self) -> Result<u128, Error>

Read a big endian u128 from the underlying reader.
Source§

async fn read_u128_le(&mut self) -> Result<u128, Error>

Read a little endian u128 from the underlying reader.
Source§

async fn read_i8(&mut self) -> Result<i8, Error>

Read a big endian i8 from the underlying reader.
Source§

async fn read_i8_le(&mut self) -> Result<i8, Error>

Read a little endian i8 from the underlying reader.
Source§

async fn read_i16(&mut self) -> Result<i16, Error>

Read a big endian i16 from the underlying reader.
Source§

async fn read_i16_le(&mut self) -> Result<i16, Error>

Read a little endian i16 from the underlying reader.
Source§

async fn read_i32(&mut self) -> Result<i32, Error>

Read a big endian i32 from the underlying reader.
Source§

async fn read_i32_le(&mut self) -> Result<i32, Error>

Read a little endian i32 from the underlying reader.
Source§

async fn read_i64(&mut self) -> Result<i64, Error>

Read a big endian i64 from the underlying reader.
Source§

async fn read_i64_le(&mut self) -> Result<i64, Error>

Read a little endian i64 from the underlying reader.
Source§

async fn read_i128(&mut self) -> Result<i128, Error>

Read a big endian i128 from the underlying reader.
Source§

async fn read_i128_le(&mut self) -> Result<i128, Error>

Read a little endian i128 from the underlying reader.
Source§

async fn read_f32(&mut self) -> Result<f32, Error>

Read a big endian f32 from the underlying reader.
Source§

async fn read_f32_le(&mut self) -> Result<f32, Error>

Read a little endian f32 from the underlying reader.
Source§

async fn read_f64(&mut self) -> Result<f64, Error>

Read a big endian f64 from the underlying reader.
Source§

async fn read_f64_le(&mut self) -> Result<f64, Error>

Read a little endian f64 from the underlying reader.
Source§

impl<R> AsyncReadExt for R
where R: AsyncRead + ?Sized,

Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where Self: Sized, R: AsyncRead,

Creates an adaptor which will chain this stream with another. Read more
Source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>
where Self: Unpin,

Tries to read some bytes directly into the given buf in asynchronous manner, returning a future type. Read more
Source§

fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>], ) -> ReadVectored<'a, Self>
where Self: Unpin,

Creates a future which will read from the AsyncRead into bufs using vectored IO operations. Read more
Source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>
where Self: Unpin,

Creates a future which will read exactly enough bytes to fill buf, returning an error if end of file (EOF) is hit sooner. Read more
Source§

fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>
where Self: Unpin,

Creates a future which will read all the bytes from this AsyncRead. Read more
Source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String, ) -> ReadToString<'a, Self>
where Self: Unpin,

Creates a future which will read all the bytes from this AsyncRead. Read more
Source§

fn split(self) -> (ReadHalf<Self>, WriteHalf<Self>)
where Self: Sized + AsyncWrite,

Helper method for splitting this read/write object into two halves. Read more
Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an AsyncRead adapter which will read at most limit bytes from the underlying reader. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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