mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-22 11:13:44 +00:00
improve wording, correct example
This commit is contained in:
committed by
Benjamin Saunders
parent
69348e54f1
commit
01fa7a4eaa
+19
-10
@@ -25,28 +25,36 @@ use crate::{
|
||||
///
|
||||
/// When a stream is expected to be closed gracefully the sender should call
|
||||
/// [`SendStream::finish`]. However there is no guarantee the connected [`RecvStream`] will
|
||||
/// receive this End Of File (EOF) indicator in the same QUIC frame as the last frame which
|
||||
/// receive the "finished" notification in the same QUIC frame as the last frame which
|
||||
/// carried data.
|
||||
///
|
||||
/// Even if the application layer logic already knows it read all the data because it
|
||||
/// does its own framing, it must still read from the [`RecvStream`] until EOF. Otherwise
|
||||
/// it risks inadvertently calling [`RecvStream::stop`] if it drops the stream. And calling
|
||||
/// [`RecvStream::stop`] could result in the connected [`SendStream::finish`] call failing
|
||||
/// with a [`WriteError::Stopped`] error.
|
||||
/// Even if the application layer logic already knows it read all the data because it does
|
||||
/// its own framing, it must still read from the [`RecvStream`] until `AsyncRead` signals
|
||||
/// End Of File (EOF). Otherwise it risks inadvertently calling [`RecvStream::stop`] if it
|
||||
/// drops the stream. And calling [`RecvStream::stop`] could result in the connected
|
||||
/// [`SendStream::finish`] call failing with a [`WriteError::Stopped`] error.
|
||||
///
|
||||
/// For example if exactly 10 bytes are to be read, you still need to explicitly read EOF:
|
||||
///
|
||||
/// ```ignore
|
||||
/// ```no_run
|
||||
/// # use quinn::{SendStream, RecvStream};
|
||||
/// # async fn func(
|
||||
/// # send_stream: &mut SendStream,
|
||||
/// # recv_stream: &mut RecvStream,
|
||||
/// # ) -> anyhow::Result<()>
|
||||
/// # {
|
||||
/// // In the sending task
|
||||
/// send_stream.write(&b"0123456789"[..]).await?;
|
||||
/// send_stream.finish()?;
|
||||
/// send_stream.finish().await?;
|
||||
///
|
||||
/// // In the receiving task
|
||||
/// let mut buf = [0u8; 10];
|
||||
/// let data = recv_stream.read_exact(&mut buf);
|
||||
/// let data = recv_stream.read_exact(&mut buf).await?;
|
||||
/// if let Some(chunk) = recv_stream.read_chunk(8, false).await? {
|
||||
/// reader.stop(0u8.into()).ok();
|
||||
/// recv_stream.stop(0u8.into()).ok();
|
||||
/// }
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// Note that in this example the receiver sends an error to the sender if it received some
|
||||
@@ -55,6 +63,7 @@ use crate::{
|
||||
/// [`ReadError`]: crate::ReadError
|
||||
/// [`stop()`]: RecvStream::stop
|
||||
/// [`SendStream::finish`]: crate::SendStream::finish
|
||||
/// [`WriteError::Stopped`]: crate::WriteError::Stopped
|
||||
#[derive(Debug)]
|
||||
pub struct RecvStream {
|
||||
conn: ConnectionRef,
|
||||
|
||||
Reference in New Issue
Block a user