# include <notify.h>
#endif /* HAVE_NOTIFY_H */
-#ifdef HAVE_POLL
+#ifndef _WIN32
# include <poll.h>
-#endif /* HAVE_POLL */
+#endif /* !_WIN32 */
#ifdef HAVE_MDNSRESPONDER
# include <dns_sd.h>
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 */
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)
#ifdef HAVE_RESOLV_H
# include <resolv.h>
#endif /* HAVE_RESOLV_H */
-#ifdef HAVE_POLL
-# include <poll.h>
-#endif /* HAVE_POLL */
#ifndef _WIN32
+# include <poll.h>
# include <fcntl.h>
#endif /* _WIN32 */
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
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 ++;
return (NULL);
}
-# ifdef HAVE_POLL
for (i = 0; i < nfds; i ++)
{
pfds[i].fd = fds[i];
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));
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];
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
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()
}
// Then try doing a select() or poll() to poll the socket...
-#ifdef HAVE_POLL
pfd.fd = http->fd;
pfd.events = POLLIN;
{
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);
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)
{
# include <unistd.h>
# include <sys/select.h>
# include <sys/time.h>
-#endif /* _WIN32 */
-#ifdef HAVE_POLL
# include <poll.h>
-#endif /* HAVE_POLL */
+#endif /* _WIN32 */
/*
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);
* 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)
{
{
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 */
/*
* See if we can safely write to the side-channel socket...
*/
-#ifdef HAVE_POLL
pfd.fd = CUPS_SC_FD;
pfd.events = POLLOUT;
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:
*
#include "cups-private.h"
#include "snmp-private.h"
-#ifdef HAVE_POLL
+#ifndef _WIN32
# include <poll.h>
-#endif /* HAVE_POLL */
+#endif /* !_WIN32 */
/*
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...
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;
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...
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);