-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
net: improve from_std
docs
#5332
Conversation
tokio/src/net/tcp/socket.rs
Outdated
@@ -666,6 +666,7 @@ impl TcpSocket { | |||
/// socket must not have been connected prior to calling this function. This | |||
/// function is typically used together with crates such as [`socket2`] to | |||
/// configure socket options that are not available on `TcpSocket`. | |||
/// It is left up to the user to set the socket in non-blocking mode. |
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.
I wonder if this ought to be explicitly marked as a Note or Warning so that it's very obvious to users? Perhaps the warning also should note what will happen if users don't do this?
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.
Yeah, I agree.
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.
I applied your suggestion and created a more obvious section about this. I did the same with other docs containing the same warning and added missing examples.
TcpSocket::from_std_stream
docsfrom_std
docs
/// | ||
/// #[tokio::main] | ||
/// async fn main() -> Result<(), Box<dyn Error>> { | ||
/// let tokio_socket = tokio::net::UnixDatagram::bind("127.0.0.1:0")?; |
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.
Some examples used IP addresses to bind Unix sockets.
tokio/src/net/tcp/listener.rs
Outdated
/// | ||
/// The caller is responsible for ensuring that the listener is in | ||
/// non-blocking mode. Otherwise all I/O operations on the listener | ||
/// will block the thread, what can cause unexpected behavior. |
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.
/// will block the thread, what can cause unexpected behavior. | |
/// will block the thread, which will cause unexpected behavior. |
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.
Looks good to me.
Motivation
Unlike documentation for other methods performing conversion from std types, docs for the
TcpSocket::from_std_stream
method do not warn about setting the socket in non-blocking mode.The attached example also doesn't set the socket in non-blocking mode.
Solution
This change adds a suitable comment in the docs and sets the socket in non-blocking mode in the example.