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:
§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
impl RecvStream
Sourcepub fn is_0rtt(&self) -> bool
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.
Sourcepub fn stop(&mut self, error_code: VarInt) -> Result<(), ClosedStream>
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.
Sourcepub async fn stopped(&mut self) -> Result<Option<VarInt>, StoppedError>
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.
Sourcepub async fn read(
&mut self,
buf: impl BufMut,
) -> Result<Option<usize>, ReadError>
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.
Sourcepub async fn read_exact(
&mut self,
buf: impl BufMut,
) -> Result<(), ReadExactError>
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.
Sourcepub async fn read_chunk(
&mut self,
max_length: usize,
ordered: bool,
) -> Result<Option<Chunk>, ReadError>
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.
Sourcepub async fn read_chunks(
&mut self,
bufs: &mut [Bytes],
) -> Result<Option<usize>, ReadError>
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.
Sourcepub async fn read_to_end(
&mut self,
buf: impl BufMut,
) -> Result<usize, ReadError>
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
impl AsyncRead for RecvStream
Source§impl AsyncRead for RecvStream
Available on crate feature io-compat
only.
impl AsyncRead for RecvStream
io-compat
only.Source§impl Debug for RecvStream
impl Debug for RecvStream
Source§impl Drop for RecvStream
impl Drop for RecvStream
Source§impl RecvStream for RecvStream
Available on crate feature h3
only.
impl RecvStream for RecvStream
h3
only.Auto Trait Implementations§
impl Freeze for RecvStream
impl RefUnwindSafe for RecvStream
impl Send for RecvStream
impl Sync for RecvStream
impl Unpin for RecvStream
impl UnwindSafe for RecvStream
Blanket Implementations§
Source§impl<A> AsyncReadExt for A
impl<A> AsyncReadExt for A
Source§async fn read_exact<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoBufMut,
async fn read_exact<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoBufMut,
Source§async fn read_to_end(&mut self, buf: Vec<u8>) -> BufResult<usize, Vec<u8>>
async fn read_to_end(&mut self, buf: Vec<u8>) -> BufResult<usize, Vec<u8>>
EOF
.Source§async fn read_vectored_exact<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoVectoredBufMut,
async fn read_vectored_exact<T>(&mut self, buf: T) -> BufResult<(), T>where
T: IoVectoredBufMut,
Source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit
bytes from it. Read moreSource§async fn read_u8(&mut self) -> Result<u8, Error>
async fn read_u8(&mut self) -> Result<u8, Error>
u8
from the underlying reader.Source§async fn read_u8_le(&mut self) -> Result<u8, Error>
async fn read_u8_le(&mut self) -> Result<u8, Error>
u8
from the underlying reader.Source§async fn read_u16(&mut self) -> Result<u16, Error>
async fn read_u16(&mut self) -> Result<u16, Error>
u16
from the underlying reader.Source§async fn read_u16_le(&mut self) -> Result<u16, Error>
async fn read_u16_le(&mut self) -> Result<u16, Error>
u16
from the underlying reader.Source§async fn read_u32(&mut self) -> Result<u32, Error>
async fn read_u32(&mut self) -> Result<u32, Error>
u32
from the underlying reader.Source§async fn read_u32_le(&mut self) -> Result<u32, Error>
async fn read_u32_le(&mut self) -> Result<u32, Error>
u32
from the underlying reader.Source§async fn read_u64(&mut self) -> Result<u64, Error>
async fn read_u64(&mut self) -> Result<u64, Error>
u64
from the underlying reader.Source§async fn read_u64_le(&mut self) -> Result<u64, Error>
async fn read_u64_le(&mut self) -> Result<u64, Error>
u64
from the underlying reader.Source§async fn read_u128(&mut self) -> Result<u128, Error>
async fn read_u128(&mut self) -> Result<u128, Error>
u128
from the underlying reader.Source§async fn read_u128_le(&mut self) -> Result<u128, Error>
async fn read_u128_le(&mut self) -> Result<u128, Error>
u128
from the underlying reader.Source§async fn read_i8(&mut self) -> Result<i8, Error>
async fn read_i8(&mut self) -> Result<i8, Error>
i8
from the underlying reader.Source§async fn read_i8_le(&mut self) -> Result<i8, Error>
async fn read_i8_le(&mut self) -> Result<i8, Error>
i8
from the underlying reader.Source§async fn read_i16(&mut self) -> Result<i16, Error>
async fn read_i16(&mut self) -> Result<i16, Error>
i16
from the underlying reader.Source§async fn read_i16_le(&mut self) -> Result<i16, Error>
async fn read_i16_le(&mut self) -> Result<i16, Error>
i16
from the underlying reader.Source§async fn read_i32(&mut self) -> Result<i32, Error>
async fn read_i32(&mut self) -> Result<i32, Error>
i32
from the underlying reader.Source§async fn read_i32_le(&mut self) -> Result<i32, Error>
async fn read_i32_le(&mut self) -> Result<i32, Error>
i32
from the underlying reader.Source§async fn read_i64(&mut self) -> Result<i64, Error>
async fn read_i64(&mut self) -> Result<i64, Error>
i64
from the underlying reader.Source§async fn read_i64_le(&mut self) -> Result<i64, Error>
async fn read_i64_le(&mut self) -> Result<i64, Error>
i64
from the underlying reader.Source§async fn read_i128(&mut self) -> Result<i128, Error>
async fn read_i128(&mut self) -> Result<i128, Error>
i128
from the underlying reader.Source§async fn read_i128_le(&mut self) -> Result<i128, Error>
async fn read_i128_le(&mut self) -> Result<i128, Error>
i128
from the underlying reader.Source§async fn read_f32(&mut self) -> Result<f32, Error>
async fn read_f32(&mut self) -> Result<f32, Error>
f32
from the underlying reader.Source§async fn read_f32_le(&mut self) -> Result<f32, Error>
async fn read_f32_le(&mut self) -> Result<f32, Error>
f32
from the underlying reader.Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
buf
in asynchronous
manner, returning a future type. Read moreSource§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
AsyncRead
into bufs
using vectored
IO operations. Read moreSource§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf
,
returning an error if end of file (EOF) is hit sooner. Read moreSource§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
AsyncRead
. Read moreSource§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
AsyncRead
. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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