Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tokio/src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,13 @@ impl TcpStream {
/// Successive calls return the same data. This is accomplished by passing
/// `MSG_PEEK` as a flag to the underlying `recv` system call.
///
/// # Cancel safety
///
/// This method is cancel safe. If the method is used as the event in a
/// [`tokio::select!`] statement and some other branch completes first,
/// then it is guranteed that no data was permanently read from the
/// stream's buffer.
Comment on lines +1075 to +1078
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Unlike read, peek never reads data permanently even if you let it complete.

Suggested change
/// This method is cancel safe. If the method is used as the event in a
/// [`tokio::select!`] statement and some other branch completes first,
/// then it is guranteed that no data was permanently read from the
/// stream's buffer.
/// This method is cancel safe. If the method is used as the event in a
/// [`tokio::select!`] statement and some other branch completes first,
/// then it is guranteed that no peek was performed, and that `buf`
/// has not been modified.

///
/// # Examples
///
/// ```no_run
Expand Down
Loading