pub enum RecvStream {
Quic(RecvStream),
}Expand description
A transport-agnostic receive stream.
Variants§
Quic(RecvStream)
Raw QUIC receive stream.
Implementations§
Source§impl RecvStream
impl RecvStream
Sourcepub async fn read(
&mut self,
buf: &mut [u8],
) -> Result<Option<usize>, TransportError>
pub async fn read( &mut self, buf: &mut [u8], ) -> Result<Option<usize>, TransportError>
Read data into the buffer. Returns Ok(Some(n)) with bytes read,
Ok(None) on stream end, or Err on failure.
Fails with TransportError::StreamReset carrying the peer’s
application error code if the peer reset the stream, which is how
callers distinguish an abandoned stream from a clean FIN
(Ok(None)).
Sourcepub async fn received_reset(&mut self) -> Result<Option<u64>, TransportError>
pub async fn received_reset(&mut self) -> Result<Option<u64>, TransportError>
Wait for the peer to reset this stream — without reading a byte.
read is the only other way to learn that a peer sent
RESET_STREAM, and it is unusable by a reader that has stopped
consuming on purpose: a forwarder applying backpressure holds its
source unread, so the reset surfaces on a call it is deliberately
not making, and the abandonment goes unobserved for as long as the
backpressure lasts. This observes the same event on its own.
It consumes nothing. No bytes leave the receive buffer, so no
MAX_STREAM_DATA credit is granted and the peer stays flow-control
blocked exactly as it was. That is the whole point: it is safe to
poll while backpressure is being applied, which
read is not.
Cancel-safe: it registers interest and consumes no state, so dropping the future loses nothing.
§Returns
Ok(Some(code))— the peer reset the stream with this application error code. The same codeTransportError::StreamResetwould have carried out ofread.Ok(None)— no reset is observable on this stream, now or ever, and the caller must stop asking: this resolves immediately every time, so a caller that re-polls it in a loop spins. Either the transport freed the stream’s state (it was finished and fully read, or stopped) or, on the WebTransport arm,wtransportexposes no reset-only observable at all and this answersOk(None)unconditionally.Err— a connection-level failure.
Sourcepub fn stop(&mut self, code: u64) -> Result<(), TransportError>
pub fn stop(&mut self, code: u64) -> Result<(), TransportError>
Stop accepting data on the stream, discarding anything unread and
telling the peer to stop transmitting with code as the
STOP_SENDING application error code.
Dropping a RecvStream also stops it, but with a hard-coded code
of 0 — so a forwarder mirroring a peer’s STOP_SENDING must call
this explicitly to keep the original code intact.
After a successful call the stream is no longer readable, and the
two arms say so differently: the QUIC arm’s read
returns TransportError::Read, the WebTransport arm’s returns
TransportError::StreamClosed (the inner stream is consumed,
because wtransport::RecvStream::stop takes self by value).
Stop reading once you have stopped a stream rather than matching
on which error comes back.
§Errors
TransportError::StreamClosedif the stream was already stopped, finished or reset.TransportError::Writeifcodeis outside the QUIC varint range (0..2^62) —Writebecause what failed is theSTOP_SENDINGframe this endpoint would have sent. Nothing is sent in that case and the stream stays readable.