Skip to content

Commit 816b659

Browse files
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
2 parents 6fc0273 + a0c757a commit 816b659

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

library/std/src/net/tcp/tests.rs

+11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ fn connect_error() {
4646
}
4747
}
4848

49+
#[test]
50+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
51+
fn connect_timeout_error() {
52+
let socket_addr = next_test_ip4();
53+
let result = TcpStream::connect_timeout(&socket_addr, Duration::MAX);
54+
assert!(!matches!(result, Err(e) if e.kind() == ErrorKind::TimedOut));
55+
56+
let _listener = TcpListener::bind(&socket_addr).unwrap();
57+
assert!(TcpStream::connect_timeout(&socket_addr, Duration::MAX).is_ok());
58+
}
59+
4960
#[test]
5061
fn listen_localhost() {
5162
let socket_addr = next_test_ip4();

library/std/src/sys/windows/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Socket {
159159
}
160160

161161
let mut timeout = c::timeval {
162-
tv_sec: timeout.as_secs() as c_long,
162+
tv_sec: cmp::min(timeout.as_secs(), c_long::MAX as u64) as c_long,
163163
tv_usec: (timeout.subsec_nanos() / 1000) as c_long,
164164
};
165165

0 commit comments

Comments
 (0)