diff options
| author | Steven Fackler <sfackler@gmail.com> | 2017-10-13 19:22:33 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2017-10-14 13:56:30 -0700 |
| commit | cab99a3f8c8dcdfd9052fd54787d22611ab36edc (patch) | |
| tree | 7e3a4d2fe0181c9a6ec65b603fe51fce08cd4f65 /src/libstd/net | |
| parent | 02a24dbdd8c3a5daa6578af72116020de75b5f93 (diff) | |
| download | rust-cab99a3f8c8dcdfd9052fd54787d22611ab36edc.tar.gz rust-cab99a3f8c8dcdfd9052fd54787d22611ab36edc.zip | |
Fix TcpStream::connect_timeout on linux
Linux appears to set POLLOUT when a conection's refused, which is pretty weird. Invert the check to look for an error explicitly. Also add an explict test for this case. Closes #45265.
Diffstat (limited to 'src/libstd/net')
| -rw-r--r-- | src/libstd/net/tcp.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index b904641a336..4656cc5a7a7 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -1580,6 +1580,21 @@ mod tests { } #[test] + fn connect_timeout_unbound() { + // bind and drop a socket to track down a "probably unassigned" port + let socket = TcpListener::bind("127.0.0.1:0").unwrap(); + let addr = socket.local_addr().unwrap(); + drop(socket); + + let timeout = Duration::from_secs(1); + let e = TcpStream::connect_timeout(&addr, timeout).unwrap_err(); + assert!(e.kind() == io::ErrorKind::ConnectionRefused || + e.kind() == io::ErrorKind::TimedOut || + e.kind() == io::ErrorKind::Other, + "bad error: {} {:?}", e, e.kind()); + } + + #[test] fn connect_timeout_valid() { let listener = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = listener.local_addr().unwrap(); |
