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 => {}
|
||||
_ => {
|
||||
// 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::const_io_error!(
|
||||
io::ErrorKind::Uncategorized,
|
||||
"no error set after POLLHUP",
|
||||
)
|
||||
});
|
||||
return Err(e);
|
||||
if cfg!(target_os = "vxworks") {
|
||||
// VxWorks poll does not return POLLHUP or POLLERR in revents. Check if the
|
||||
// connnection actually succeeded and return ok only when the socket is
|
||||
// ready and no errors were found.
|
||||
if let Some(e) = self.take_error()? {
|
||||
return Err(e);
|
||||
}
|
||||
} else {
|
||||
// linux returns POLLOUT|POLLERR|POLLHUP for refused connections (!), so look
|
||||
// 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(());
|
||||
|
Loading…
x
Reference in New Issue
Block a user