From: Andreas Mair Date: Wed, 31 Jul 2024 11:59:45 +0000 (+0200) Subject: Use poll() in BIO_socket_wait() if available X-Git-Tag: openssl-3.5.0-alpha1~1014 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=38e8392ba0c8dcd975de47a3119d0051cf5e44a1;p=thirdparty%2Fopenssl.git Use poll() in BIO_socket_wait() if available Reviewed-by: Tom Cosgrove Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/25055) --- diff --git a/crypto/bio/bio_sock.c b/crypto/bio/bio_sock.c index a4c479503fc..3ea122e2b95 100644 --- a/crypto/bio/bio_sock.c +++ b/crypto/bio/bio_sock.c @@ -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) */ diff --git a/include/internal/sockets.h b/include/internal/sockets.h index 5feec0eab8c..11e21508fe0 100644 --- a/include/internal/sockets.h +++ b/include/internal/sockets.h @@ -97,6 +97,7 @@ typedef size_t socklen_t; /* Currently appears to be missing on VMS */ # include # include # else +# include # include # if !defined(NO_SYS_UN_H) && defined(AF_UNIX) && !defined(OPENSSL_NO_UNIX_SOCK) # include