From 02f6d2f35bf52f5115967d3de1071137eea6ed1c Mon Sep 17 00:00:00 2001 From: Clara Engler Date: Sun, 4 May 2025 19:00:14 +0200 Subject: [PATCH] docs: add cancel safety section to TcpStream::peek Fix #7303 --- tokio/src/net/tcp/stream.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index b0e3ec27ce1..5661f101aa5 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -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. + /// /// # Examples /// /// ```no_run