1
Fork 0

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.
This commit is contained in:
Steven Fackler 2017-10-13 19:22:33 -07:00
parent 02a24dbdd8
commit cab99a3f8c
2 changed files with 24 additions and 4 deletions

View file

@ -176,11 +176,16 @@ impl Socket {
}
0 => {}
_ => {
if pollfd.revents & libc::POLLOUT == 0 {
if let Some(e) = self.take_error()? {
return Err(e);
}
// linux returns POLLOUT|POLLERR|POLLHUP for refused connections (!), so look
// for POLLHUP rather than read readiness
if pollfd.revents & libc::POLLHUP != 0 {
let e = self.take_error()?
.unwrap_or_else(|| {
io::Error::new(io::ErrorKind::Other, "no error set after POLLHUP")
});
return Err(e);
}
return Ok(());
}
}