mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Rollup merge of #127300 - biabbas:fix_connect_timeout, r=tgross35
Fix connect timeout for non-linux targets, read readiness of socket connection, Read readiness to detect errors. `Fixes #127018` Fixes #127018 Connect_timeout would call `poll` and check `pollfd.revents` for POLLHUP error, rather that checking readiness. This behavior was meant for Linux as it returns POLLHUP | POLLOUT | POLLERR in case of errors. But on targets that do not return POLLHUP in `pollfd.revents`, this would indicate a false success and result in this issue. To resolve this we will check readiness of socket using `getsockopt():` and return success from connect_timeout when there are no errors. Changes were tested on Linux and an rtos.  Thank you.
This commit is contained in:
commit
d1070df553
@ -214,16 +214,25 @@ impl Socket {
|
|||||||
}
|
}
|
||||||
0 => {}
|
0 => {}
|
||||||
_ => {
|
_ => {
|
||||||
// linux returns POLLOUT|POLLERR|POLLHUP for refused connections (!), so look
|
if cfg!(target_os = "vxworks") {
|
||||||
// for POLLHUP rather than read readiness
|
// VxWorks poll does not return POLLHUP or POLLERR in revents. Check if the
|
||||||
if pollfd.revents & libc::POLLHUP != 0 {
|
// connnection actually succeeded and return ok only when the socket is
|
||||||
let e = self.take_error()?.unwrap_or_else(|| {
|
// ready and no errors were found.
|
||||||
io::const_io_error!(
|
if let Some(e) = self.take_error()? {
|
||||||
io::ErrorKind::Uncategorized,
|
return Err(e);
|
||||||
"no error set after POLLHUP",
|
}
|
||||||
)
|
} else {
|
||||||
});
|
// linux returns POLLOUT|POLLERR|POLLHUP for refused connections (!), so look
|
||||||
return Err(e);
|
// for POLLHUP or POLLERR rather than read readiness
|
||||||
|
if pollfd.revents & (libc::POLLHUP | libc::POLLERR) != 0 {
|
||||||
|
let e = self.take_error()?.unwrap_or_else(|| {
|
||||||
|
io::const_io_error!(
|
||||||
|
io::ErrorKind::Uncategorized,
|
||||||
|
"no error set after POLLHUP",
|
||||||
|
)
|
||||||
|
});
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
Loading…
Reference in New Issue
Block a user