Rollup merge of #112464 - eval-exec:exec/fix-connect_timeout-overflow, r=ChrisDenton

Fix windows `Socket::connect_timeout` overflow

This PR want to close #112405

- [x] add unit test
This commit is contained in:
Guillaume Gomez 2023-06-20 14:23:39 +02:00 committed by GitHub
commit 816b659157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -46,6 +46,17 @@ fn connect_error() {
}
}
#[test]
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn connect_timeout_error() {
let socket_addr = next_test_ip4();
let result = TcpStream::connect_timeout(&socket_addr, Duration::MAX);
assert!(!matches!(result, Err(e) if e.kind() == ErrorKind::TimedOut));
let _listener = TcpListener::bind(&socket_addr).unwrap();
assert!(TcpStream::connect_timeout(&socket_addr, Duration::MAX).is_ok());
}
#[test]
fn listen_localhost() {
let socket_addr = next_test_ip4();

View File

@ -159,7 +159,7 @@ impl Socket {
}
let mut timeout = c::timeval {
tv_sec: timeout.as_secs() as c_long,
tv_sec: cmp::min(timeout.as_secs(), c_long::MAX as u64) as c_long,
tv_usec: (timeout.subsec_nanos() / 1000) as c_long,
};