From 08379a8194295db8cbe530c859a0a3268bee927d Mon Sep 17 00:00:00 2001 From: B I Mohammed Abbas Date: Thu, 4 Jul 2024 10:41:23 +0530 Subject: [PATCH] Fix connect timeout for non-linux targets, read readiness of socket connection before returning success --- library/std/src/sys/pal/unix/net.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/library/std/src/sys/pal/unix/net.rs b/library/std/src/sys/pal/unix/net.rs index b8dc1538a6378..7a53bde36c888 100644 --- a/library/std/src/sys/pal/unix/net.rs +++ b/library/std/src/sys/pal/unix/net.rs @@ -213,15 +213,9 @@ 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", - ) - }); + // 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); }