pub struct RecvStream { /* private fields */ }quic only.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 fn poll_read_uninit(
&mut self,
cx: &mut Context<'_>,
buf: &mut [MaybeUninit<u8>],
) -> Poll<Result<usize, ReadError>>
pub fn poll_read_uninit( &mut self, cx: &mut Context<'_>, buf: &mut [MaybeUninit<u8>], ) -> Poll<Result<usize, ReadError>>
Attempts to read from the stream into the provided buffer
On success, returns Poll::Ready(Ok(num_bytes_read)) and places data
into buf. If the buffer passed in has non-zero length and a 0 is
returned, that indicates that the remote side has finished the
stream and the local side has already read all bytes.
If no data is available for reading, this returns Poll::Pending and
arranges for the current task (via cx.waker()) to be notified when
the stream becomes readable or is closed.
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<B>(&mut self, buf: B) -> BufResult<usize, B>where
B: IoBufMut,
pub async fn read_to_end<B>(&mut self, buf: B) -> BufResult<usize, B>where
B: IoBufMut,
Convenience method to read all remaining data into a buffer.
If unordered reads have already been made, the resulting buffer may have gaps containing zeros.
This operation is not cancel-safe.
Sourcepub fn into_compat(self) -> CompatRecvStream
Available on crate feature io-compat only.
pub fn into_compat(self) -> CompatRecvStream
io-compat only.Convert into an [futures_util] compatible stream.
Trait Implementations§
Source§impl AsyncRead for RecvStream
impl AsyncRead for RecvStream
Source§impl Debug for RecvStream
impl Debug for RecvStream
Source§impl Drop for RecvStream
impl Drop for RecvStream
Source§impl RecvStream for RecvStream
impl RecvStream for RecvStream
Source§fn poll_data(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<<RecvStream as RecvStream>::Buf>, StreamErrorIncoming>>
fn poll_data( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Option<<RecvStream as RecvStream>::Buf>, StreamErrorIncoming>>
Source§fn stop_sending(&mut self, error_code: u64)
fn stop_sending(&mut self, error_code: u64)
STOP_SENDING QUIC code.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§
§impl<A> AsyncReadExt for A
impl<A> AsyncReadExt for A
§async fn append<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoBufMut,
async fn append<T>(&mut self, buf: T) -> BufResult<usize, T>where
T: IoBufMut,
AsyncRead::read, but it appends data to the end of the
buffer; in other words, it read to the beginning of the uninitialized
area.§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,
§async fn read_to_string(&mut self, buf: String) -> BufResult<usize, String>
async fn read_to_string(&mut self, buf: String) -> BufResult<usize, String>
String until underlying reader reaches EOF.§async fn read_to_end<A>(
&mut self,
buf: Vec<u8, A>,
) -> BufResult<usize, Vec<u8, A>>where
A: Allocator + 'static,
async fn read_to_end<A>(
&mut self,
buf: Vec<u8, A>,
) -> BufResult<usize, Vec<u8, A>>where
A: Allocator + 'static,
EOF.§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,
§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 more§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.§async fn read_u16(&mut self) -> Result<u16, Error>
async fn read_u16(&mut self) -> Result<u16, Error>
u16 from the underlying reader.§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.§async fn read_u32(&mut self) -> Result<u32, Error>
async fn read_u32(&mut self) -> Result<u32, Error>
u32 from the underlying reader.§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.§async fn read_u64(&mut self) -> Result<u64, Error>
async fn read_u64(&mut self) -> Result<u64, Error>
u64 from the underlying reader.§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.§async fn read_u128(&mut self) -> Result<u128, Error>
async fn read_u128(&mut self) -> Result<u128, Error>
u128 from the underlying reader.§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.§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.§async fn read_i16(&mut self) -> Result<i16, Error>
async fn read_i16(&mut self) -> Result<i16, Error>
i16 from the underlying reader.§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.§async fn read_i32(&mut self) -> Result<i32, Error>
async fn read_i32(&mut self) -> Result<i32, Error>
i32 from the underlying reader.§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.§async fn read_i64(&mut self) -> Result<i64, Error>
async fn read_i64(&mut self) -> Result<i64, Error>
i64 from the underlying reader.§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.§async fn read_i128(&mut self) -> Result<i128, Error>
async fn read_i128(&mut self) -> Result<i128, Error>
i128 from the underlying reader.§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.§async fn read_f32(&mut self) -> Result<f32, Error>
async fn read_f32(&mut self) -> Result<f32, Error>
f32 from the underlying reader.§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.§async fn read_f64(&mut self) -> Result<f64, Error>
async fn read_f64(&mut self) -> Result<f64, Error>
f64 from the underlying reader.§async fn read_f64_le(&mut self) -> Result<f64, Error>
async fn read_f64_le(&mut self) -> Result<f64, Error>
f64 from the underlying reader.Source§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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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