Skip to content

Commit

Permalink
In connect timeout, read readiness of socket for vxworks. Check pollh…
Browse files Browse the repository at this point in the history
…up or pollerr for refused connections in linux
  • Loading branch information
B I Mohammed Abbas committed Jul 25, 2024
1 parent 5b0d82f commit 3a18110
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions std/src/sys/pal/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,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(());
Expand Down

0 comments on commit 3a18110

Please sign in to comment.