From 7d6e487a268387da96b7998c1790bdced938d691 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Fri, 8 Sep 2023 14:22:43 -0400 Subject: [PATCH] Fix other instances of code that looked for HAVE_POLL - poll() is always available. --- cups/dest.c | 20 ++------------- cups/http-addrlist.c | 39 +--------------------------- cups/http.c | 60 ++++++-------------------------------------- cups/sidechannel.c | 58 +++++------------------------------------- cups/snmp.c | 29 ++++++--------------- scheduler/main.c | 5 ---- scheduler/select.c | 7 ++++++ 7 files changed, 30 insertions(+), 188 deletions(-) diff --git a/cups/dest.c b/cups/dest.c index 82cbbe0041..72f0b8e2c6 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -21,9 +21,9 @@ # include #endif /* HAVE_NOTIFY_H */ -#ifdef HAVE_POLL +#ifndef _WIN32 # include -#endif /* HAVE_POLL */ +#endif /* !_WIN32 */ #ifdef HAVE_MDNSRESPONDER # include @@ -3410,12 +3410,7 @@ cups_enum_dests( main_fd; /* File descriptor for lookups */ DNSServiceRef ipp_ref = NULL; /* IPP browser */ DNSServiceRef ipps_ref = NULL; /* IPPS browser */ -# ifdef HAVE_POLL struct pollfd pfd; /* Polling data */ -# else - fd_set input; /* Input set for select() */ - struct timeval timeout; /* Timeout for select() */ -# endif /* HAVE_POLL */ # else /* HAVE_AVAHI */ int error; /* Error value */ AvahiServiceBrowser *ipp_ref = NULL; /* IPP browser */ @@ -3732,22 +3727,11 @@ cups_enum_dests( cups_elapsed(&curtime); # ifdef HAVE_MDNSRESPONDER -# ifdef HAVE_POLL pfd.fd = main_fd; pfd.events = POLLIN; nfds = poll(&pfd, 1, remaining > _CUPS_DNSSD_MAXTIME ? _CUPS_DNSSD_MAXTIME : remaining); -# else - FD_ZERO(&input); - FD_SET(main_fd, &input); - - timeout.tv_sec = 0; - timeout.tv_usec = 1000 * (remaining > _CUPS_DNSSD_MAXTIME ? _CUPS_DNSSD_MAXTIME : remaining); - - nfds = select(main_fd + 1, &input, NULL, NULL, &timeout); -# endif /* HAVE_POLL */ - if (nfds > 0) DNSServiceProcessResult(data.main_ref); else if (nfds < 0 && errno != EINTR && errno != EAGAIN) diff --git a/cups/http-addrlist.c b/cups/http-addrlist.c index 0dd7fa42a8..81adfbcbf6 100644 --- a/cups/http-addrlist.c +++ b/cups/http-addrlist.c @@ -18,10 +18,8 @@ #ifdef HAVE_RESOLV_H # include #endif /* HAVE_RESOLV_H */ -#ifdef HAVE_POLL -# include -#endif /* HAVE_POLL */ #ifndef _WIN32 +# include # include #endif /* _WIN32 */ @@ -67,18 +65,9 @@ httpAddrConnect2( int nfds, /* Number of file descriptors */ fds[100]; /* Socket file descriptors */ http_addrlist_t *addrs[100]; /* Addresses */ -#ifndef HAVE_POLL int max_fd = -1; /* Highest file descriptor */ -#endif /* !HAVE_POLL */ #ifdef O_NONBLOCK -# ifdef HAVE_POLL struct pollfd pfds[100]; /* Polled file descriptors */ -# else - fd_set input_set, /* select() input set */ - output_set, /* select() output set */ - error_set; /* select() error set */ - struct timeval timeout; /* Timeout */ -# endif /* HAVE_POLL */ #endif /* O_NONBLOCK */ #ifdef DEBUG # ifndef _WIN32 @@ -230,10 +219,8 @@ httpAddrConnect2( fcntl(fds[nfds], F_SETFL, flags); #endif /* !_WIN32 */ -#ifndef HAVE_POLL if (fds[nfds] > max_fd) max_fd = fds[nfds]; -#endif /* !HAVE_POLL */ addrs[nfds] = addrlist; nfds ++; @@ -278,7 +265,6 @@ httpAddrConnect2( return (NULL); } -# ifdef HAVE_POLL for (i = 0; i < nfds; i ++) { pfds[i].fd = fds[i]; @@ -288,21 +274,6 @@ httpAddrConnect2( result = poll(pfds, (nfds_t)nfds, addrlist ? 100 : remaining > 250 ? 250 : remaining); DEBUG_printf("1httpAddrConnect2: poll() returned %d (%d)", result, errno); - -# else - FD_ZERO(&input_set); - for (i = 0; i < nfds; i ++) - FD_SET(fds[i], &input_set); - output_set = input_set; - error_set = input_set; - - timeout.tv_sec = 0; - timeout.tv_usec = (addrlist ? 100 : remaining > 250 ? 250 : remaining) * 1000; - - result = select(max_fd + 1, &input_set, &output_set, &error_set, &timeout); - - DEBUG_printf("1httpAddrConnect2: select() returned %d (%d)", result, errno); -# endif /* HAVE_POLL */ } # ifdef _WIN32 while (result < 0 && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEWOULDBLOCK)); @@ -316,12 +287,8 @@ httpAddrConnect2( for (i = 0; i < nfds; i ++) { -# ifdef HAVE_POLL DEBUG_printf("pfds[%d].revents=%x\n", i, pfds[i].revents); if (pfds[i].revents && !(pfds[i].revents & (POLLERR | POLLHUP))) -# else - if (FD_ISSET(fds[i], &input_set) && !FD_ISSET(fds[i], &error_set)) -# endif /* HAVE_POLL */ { *sock = fds[i]; connaddr = addrs[i]; @@ -334,11 +301,7 @@ httpAddrConnect2( break; } -# ifdef HAVE_POLL else if (pfds[i].revents & (POLLERR | POLLHUP)) -# else - else if (FD_ISSET(fds[i], &error_set)) -# endif /* HAVE_POLL */ { # ifdef __sun // Solaris incorrectly returns errors when you poll() a socket that is diff --git a/cups/http.c b/cups/http.c index cde5f09b1a..0058db5dfe 100644 --- a/cups/http.c +++ b/cups/http.c @@ -2754,12 +2754,7 @@ _httpWait(http_t *http, // I - HTTP connection int msec, // I - Milliseconds to wait int usessl) // I - Use TLS context? { -#ifdef HAVE_POLL struct pollfd pfd; // Polled file descriptor -#else - fd_set input_set; // select() input set - struct timeval timeout; // Timeout -#endif // HAVE_POLL int nfds; // Result from select()/poll() @@ -2779,7 +2774,6 @@ _httpWait(http_t *http, // I - HTTP connection } // Then try doing a select() or poll() to poll the socket... -#ifdef HAVE_POLL pfd.fd = http->fd; pfd.events = POLLIN; @@ -2787,34 +2781,11 @@ _httpWait(http_t *http, // I - HTTP connection { nfds = poll(&pfd, 1, msec); } - while (nfds < 0 && (errno == EINTR || errno == EAGAIN)); - -#else - do - { - FD_ZERO(&input_set); - FD_SET(http->fd, &input_set); - - DEBUG_printf("6_httpWait: msec=%d, http->fd=%d", msec, http->fd); - - if (msec >= 0) - { - timeout.tv_sec = msec / 1000; - timeout.tv_usec = (msec % 1000) * 1000; - - nfds = select(http->fd + 1, &input_set, NULL, NULL, &timeout); - } - else - nfds = select(http->fd + 1, &input_set, NULL, NULL, NULL); - - DEBUG_printf("6_httpWait: select() returned %d...", nfds); - } -# ifdef _WIN32 +#ifdef _WIN32 while (nfds < 0 && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEWOULDBLOCK)); -# else +#else while (nfds < 0 && (errno == EINTR || errno == EAGAIN)); -# endif // _WIN32 -#endif // HAVE_POLL +#endif // _WIN32 DEBUG_printf("5_httpWait: returning with nfds=%d, errno=%d...", nfds, errno); @@ -4276,40 +4247,23 @@ http_write(http_t *http, // I - HTTP connection if (http->timeout_value > 0.0) { -#ifdef HAVE_POLL struct pollfd pfd; // Polled file descriptor -#else - fd_set output_set; // Output ready for write? - struct timeval timeout; // Timeout value -#endif // HAVE_POLL int nfds; // Result from select()/poll() do { -#ifdef HAVE_POLL pfd.fd = http->fd; pfd.events = POLLOUT; - while ((nfds = poll(&pfd, 1, http->wait_value)) < 0 && (errno == EINTR || errno == EAGAIN)) - // Repeat as needed... - -#else - do - { - FD_ZERO(&output_set); - FD_SET(http->fd, &output_set); - - timeout.tv_sec = http->wait_value / 1000; - timeout.tv_usec = 1000 * (http->wait_value % 1000); - - nfds = select(http->fd + 1, NULL, &output_set, NULL, &timeout); - } + do + { + nfds = poll(&pfd, 1, http->wait_value); + } # ifdef _WIN32 while (nfds < 0 && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEWOULDBLOCK)); # else while (nfds < 0 && (errno == EINTR || errno == EAGAIN)); # endif // _WIN32 -#endif // HAVE_POLL if (nfds < 0) { diff --git a/cups/sidechannel.c b/cups/sidechannel.c index 10b8a5c9cf..e180f716d0 100644 --- a/cups/sidechannel.c +++ b/cups/sidechannel.c @@ -21,10 +21,8 @@ # include # include # include -#endif /* _WIN32 */ -#ifdef HAVE_POLL # include -#endif /* HAVE_POLL */ +#endif /* _WIN32 */ /* @@ -102,12 +100,7 @@ cupsSideChannelRead( ssize_t bytes; /* Bytes read */ int templen; /* Data length from message */ int nfds; /* Number of file descriptors */ -#ifdef HAVE_POLL struct pollfd pfd; /* Poll structure for poll() */ -#else /* select() */ - fd_set input_set; /* Input set for select() */ - struct timeval stimeout; /* Timeout value for select() */ -#endif /* HAVE_POLL */ DEBUG_printf("cupsSideChannelRead(command=%p, status=%p, data=%p, datalen=%p(%d), timeout=%.3f)", command, status, data, datalen, datalen ? *datalen : -1, timeout); @@ -123,28 +116,14 @@ cupsSideChannelRead( * See if we have pending data on the side-channel socket... */ -#ifdef HAVE_POLL pfd.fd = CUPS_SC_FD; pfd.events = POLLIN; - while ((nfds = poll(&pfd, 1, - timeout < 0.0 ? -1 : (int)(timeout * 1000))) < 0 && - (errno == EINTR || errno == EAGAIN)) - ; - -#else /* select() */ - FD_ZERO(&input_set); - FD_SET(CUPS_SC_FD, &input_set); - - stimeout.tv_sec = (int)timeout; - stimeout.tv_usec = (int)(timeout * 1000000) % 1000000; - - while ((nfds = select(CUPS_SC_FD + 1, &input_set, NULL, NULL, - timeout < 0.0 ? NULL : &stimeout)) < 0 && - (errno == EINTR || errno == EAGAIN)) - ; - -#endif /* HAVE_POLL */ + do + { + nfds = poll(&pfd, 1, timeout < 0.0 ? -1 : (int)(timeout * 1000)); + } + while (nfds < 0 && (errno == EINTR || errno == EAGAIN)); if (nfds < 1) { @@ -520,12 +499,7 @@ cupsSideChannelWrite( { char *buffer; /* Message buffer */ ssize_t bytes; /* Bytes written */ -#ifdef HAVE_POLL struct pollfd pfd; /* Poll structure for poll() */ -#else /* select() */ - fd_set output_set; /* Output set for select() */ - struct timeval stimeout; /* Timeout value for select() */ -#endif /* HAVE_POLL */ /* @@ -540,7 +514,6 @@ cupsSideChannelWrite( * See if we can safely write to the side-channel socket... */ -#ifdef HAVE_POLL pfd.fd = CUPS_SC_FD; pfd.events = POLLOUT; @@ -552,25 +525,6 @@ cupsSideChannelWrite( else if (poll(&pfd, 1, (int)(timeout * 1000)) < 1) return (-1); -#else /* select() */ - FD_ZERO(&output_set); - FD_SET(CUPS_SC_FD, &output_set); - - if (timeout < 0.0) - { - if (select(CUPS_SC_FD + 1, NULL, &output_set, NULL, NULL) < 1) - return (-1); - } - else - { - stimeout.tv_sec = (int)timeout; - stimeout.tv_usec = (int)(timeout * 1000000) % 1000000; - - if (select(CUPS_SC_FD + 1, NULL, &output_set, NULL, &stimeout) < 1) - return (-1); - } -#endif /* HAVE_POLL */ - /* * Write a side-channel message in the format: * diff --git a/cups/snmp.c b/cups/snmp.c index e81579deba..71bde4aded 100644 --- a/cups/snmp.c +++ b/cups/snmp.c @@ -15,9 +15,9 @@ #include "cups-private.h" #include "snmp-private.h" -#ifdef HAVE_POLL +#ifndef _WIN32 # include -#endif /* HAVE_POLL */ +#endif /* !_WIN32 */ /* @@ -365,35 +365,20 @@ _cupsSNMPRead(int fd, /* I - SNMP socket file descriptor */ if (timeout >= 0.0) { int ready; /* Data ready on socket? */ -#ifdef HAVE_POLL struct pollfd pfd; /* Polled file descriptor */ pfd.fd = fd; pfd.events = POLLIN; - while ((ready = poll(&pfd, 1, (int)(timeout * 1000.0))) < 0 && - (errno == EINTR || errno == EAGAIN)); - -#else - fd_set input_set; /* select() input set */ - struct timeval stimeout; /* select() timeout */ - do { - FD_ZERO(&input_set); - FD_SET(fd, &input_set); - - stimeout.tv_sec = (int)timeout; - stimeout.tv_usec = (int)((timeout - stimeout.tv_sec) * 1000000); - - ready = select(fd + 1, &input_set, NULL, NULL, &stimeout); + ready = poll(&pfd, 1, (int)(timeout * 1000.0)); } -# ifdef _WIN32 - while (ready < 0 && WSAGetLastError() == WSAEINTR); -# else +#ifdef _WIN32 + while (ready < 0 && (WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEAGAIN)); +#else while (ready < 0 && (errno == EINTR || errno == EAGAIN)); -# endif /* _WIN32 */ -#endif /* HAVE_POLL */ +#endif /* _WIN32 */ /* * If we don't have any data ready, return right away... diff --git a/scheduler/main.c b/scheduler/main.c index d94cf31083..12bade0f9e 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -508,11 +508,6 @@ main(int argc, /* I - Number of command-line args */ getrlimit(RLIMIT_NOFILE, &limit); -#if !defined(HAVE_POLL) && !defined(HAVE_EPOLL) && !defined(HAVE_KQUEUE) - if (limit.rlim_max > FD_SETSIZE) - MaxFDs = FD_SETSIZE; - else -#endif /* !HAVE_POLL && !HAVE_EPOLL && !HAVE_KQUEUE */ #ifdef RLIM_INFINITY if (limit.rlim_max == RLIM_INFINITY) MaxFDs = 16384; diff --git a/scheduler/select.c b/scheduler/select.c index a87985aaa2..5c085944a8 100644 --- a/scheduler/select.c +++ b/scheduler/select.c @@ -301,6 +301,8 @@ cupsdDoSelect(long timeout) // I - Timeout in seconds else nfds = poll(cupsd_pollfds, (nfds_t)count, -1); + cupsdLogMessage(CUPSD_LOG_DEBUG, "poll(nfds=%d, timeout=%ld) returned %d", count, timeout < 86400 ? timeout * 1000 : -1, nfds); + if (nfds > 0) { // Do callbacks for each file descriptor... @@ -310,7 +312,12 @@ cupsdDoSelect(long timeout) // I - Timeout in seconds continue; if ((fdptr = find_fd(pfd->fd)) == NULL) + { + cupsdLogMessage(CUPSD_LOG_DEBUG, "cups_pollfds[%d] not found", pfd->fd); continue; + } + + cupsdLogMessage(CUPSD_LOG_DEBUG, "cups_pollfds[%d].revents=%d", pfd->fd, pfd->revents); retain_fd(fdptr); -- 2.47.2