-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
docs: add cancel safety section to TcpStream::peek #7305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
cc @maminrayej |
tokio/src/net/tcp/stream.rs
Outdated
/// # Cancel safety | ||
/// | ||
/// This method is cancel safe, as no underlying state gets modified. | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stay consistent with the wording that is used throughout the code base for documenting 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 guaranteed that <insert the appropriate text here>.
For example for TcpListener::accept
, it's:
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 guaranteed that no new connections were accepted by this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link to tokio::select!
isn't working. You need to mark the link properly. See the other examples of how to say where the link should go.
updated to reflect the suggestion. |
/// 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. |
There was a problem hiding this comment.
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.
/// 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. |
Fix #7303