-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Improve docs for UdpSocket::set_nonblocking. #45449
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
@sfackler one more here when you have a moment |
src/libstd/net/udp.rs
Outdated
@@ -721,16 +721,44 @@ impl UdpSocket { | |||
|
|||
/// Moves this UDP socket into or out of nonblocking mode. | |||
/// | |||
/// On Unix this corresponds to calling fcntl, and on Windows this | |||
/// corresponds to calling ioctlsocket. | |||
/// This will result in `recv` and `send` operations/ becoming nonblocking, |
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.
Stray /
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.
Also send_to/recv_from
src/libstd/net/udp.rs
Outdated
/// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address"); | ||
/// socket.set_nonblocking(true).expect("set_nonblocking call failed"); | ||
/// let socket = UdpSocket::bind("127.0.0.1:7878").unwrap(); | ||
/// socket.connect("127.0.0.1:7879").unwrap(); |
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.
Would it be simpler to not connect and use send_to/recv_from instead?
src/libstd/net/udp.rs
Outdated
/// // wait until network socket is ready, typically implemented | ||
/// // via platform-specific APIs such as epoll or IOCP | ||
/// wait_for_fd(); | ||
/// continue; |
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.
No need for this continue.
@sfackler thanks for the review! comments addressed in the latest commit |
/// Err(e) => panic!("encountered IO error: {}", e), | ||
/// } | ||
/// }; | ||
/// println!("bytes: {:?}", &buf[..num_bytes_read]); |
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.
CI is failing. Note that .recv_from
returns a Result<(usize, SocketAddr)>
, not Result<usize>
.
[01:04:03] ---- net/udp.rs - net::udp::UdpSocket::set_nonblocking (line 742) stdout ----
[01:04:03] error[E0277]: the trait bound `std::ops::RangeTo<(usize, std::net::SocketAddr)>: std::slice::SliceIndex<[u8]>` is not satisfied
[01:04:03] --> net/udp.rs:23:26
[01:04:03] |
[01:04:03] 23 | println!("bytes: {:?}", &buf[..num_bytes_read]);
[01:04:03] | ^^^^^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
[01:04:03] |
[01:04:03] = help: the trait `std::slice::SliceIndex<[u8]>` is not implemented for `std::ops::RangeTo<(usize, std::net::SocketAddr)>`
[01:04:03] = note: required because of the requirements on the impl of `std::ops::Index<std::ops::RangeTo<(usize, std::net::SocketAddr)>>` for `[u8]`
[01:04:03]
[01:04:03] thread 'rustc' panicked at 'couldn't compile the test', /checkout/src/librustdoc/test.rs:287:12
[01:04:03] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:04:03]
[01:04:03]
[01:04:03] failures:
[01:04:03] net/udp.rs - net::udp::UdpSocket::set_nonblocking (line 742)
[01:04:03]
[01:04:03] test result: FAILED. 876 passed; 1 failed; 10 ignored; 0 measured; 0 filtered out
15d8c28
to
04f27f0
Compare
ci passes now |
@bors r+ rollup |
📌 Commit 04f27f0 has been approved by |
…r=sfackler Improve docs for UdpSocket::set_nonblocking. Closes rust-lang#44050.
…r=sfackler Improve docs for UdpSocket::set_nonblocking. Closes rust-lang#44050.
Closes #44050.