-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Strengthen/clarify "It is an error to..." wording #48311
Comments
We do have an explicit check: rust/src/libstd/sys/unix/net.rs Lines 282 to 285 in ff2a7c8
rust/src/libstd/sys/windows/net.rs Lines 261 to 264 in ff2a7c8
|
@sfackler ah, i didn't see those. i just checked redox and it looks like it doesn't have that conditional. seems like this is prone to happen again in the future, unless we had:
|
Yeah it seems reasonable to have tests to check for that error case. |
@sfackler for |
I'd just spawn off a listener in a background thread: let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = listener.local_addr().unwrap();
thread::spawn(move || {
listener.accept().unwrap();
});
let socket = TcpStream::connect(addr).unwrap();
match socket.set_read_timeout(Some(Duration::from_secs(0))) {
Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {}
_ => panic!("expected error"),
} |
Documentation fix side of rust-lang#48311.
…on, r=sfackler Add tests ensuring zero-Duration timeouts result in errors; fix Redox issues. Part of rust-lang#48311
…on, r=sfackler Add tests ensuring zero-Duration timeouts result in errors; fix Redox issues. Part of rust-lang#48311
UdpSocket::set_read_timeout
UdpSocket::set_write_timeout
TcpStream::connect_timeout
TcpStream::set_read_timeout
TcpStream::set_write_timeout
UnixDatagram::set_read_timeout
UnixDatagram::set_write_timeout
UnixStream::set_read_timeout
UnixStream::set_write_timeout
For all of the APIs above, the docs have a line with this wording:
My initial thought is, what does "it is an error" mean? Does this mean the API will panic if
Some(Duration::from_secs(0))
is passed or will it just return anErr
? The answer appears to be the latter.Also since it's the latter, and we don't have an explicit check for
Duration(0)
in our codebase, it means we're relying on the behavior being the same across all platforms. Is this alright? Should/can we add an explicit check forDuration(0)
? Should we add a test ensuring this is the behavior across all platforms?Maybe I'm overthinking this...
The text was updated successfully, but these errors were encountered: