]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Use poll() in BIO_socket_wait() if available
authorAndreas Mair <amair.sob@googlemail.com>
Wed, 31 Jul 2024 11:59:45 +0000 (13:59 +0200)
committerMatt Caswell <matt@openssl.org>
Fri, 11 Oct 2024 09:21:07 +0000 (10:21 +0100)
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25055)

crypto/bio/bio_sock.c
include/internal/sockets.h

index a4c479503fcb550edb6d7792a8d4e97d118672c6..3ea122e2b95934a8d7595cc0de239302b9a45e3b 100644 (file)
@@ -430,15 +430,16 @@ int BIO_sock_info(int sock,
  */
 int BIO_socket_wait(int fd, int for_read, time_t max_time)
 {
+# if defined(OPENSSL_SYS_WINDOWS) || !defined(POLLIN)
     fd_set confds;
     struct timeval tv;
     time_t now;
 
-#ifdef _WIN32
+#  ifdef _WIN32
     if ((SOCKET)fd == INVALID_SOCKET)
-#else
+#  else
     if (fd < 0 || fd >= FD_SETSIZE)
-#endif
+#  endif
         return -1;
     if (max_time == 0)
         return 1;
@@ -453,5 +454,22 @@ int BIO_socket_wait(int fd, int for_read, time_t max_time)
     tv.tv_sec = (long)(max_time - now); /* might overflow */
     return select(fd + 1, for_read ? &confds : NULL,
                   for_read ? NULL : &confds, NULL, &tv);
+# else
+    struct pollfd confds;
+    time_t now;
+
+    if (fd < 0)
+        return -1;
+    if (max_time == 0)
+        return 1;
+
+    now = time(NULL);
+    if (max_time < now)
+        return 0;
+
+    confds.fd = fd;
+    confds.events = for_read ? POLLIN : POLLOUT;
+    return poll(&confds, 1, (int)(max_time - now) * 1000);
+# endif
 }
 #endif /* !defined(OPENSSL_NO_SOCK) */
index 5feec0eab8cfc316159cfa50b3c4427dc99f1d57..11e21508fe0f6590f4ee3c7b650cc121f75949e5 100644 (file)
@@ -97,6 +97,7 @@ typedef size_t socklen_t;        /* Currently appears to be missing on VMS */
 #   include <in.h>
 #   include <inet.h>
 #  else
+#   include <poll.h>
 #   include <sys/socket.h>
 #   if !defined(NO_SYS_UN_H) && defined(AF_UNIX) && !defined(OPENSSL_NO_UNIX_SOCK)
 #    include <sys/un.h>