diff --git a/frontend/saned.c b/frontend/saned.c index ecaf4b1cd..fb68c3027 100644 --- a/frontend/saned.c +++ b/frontend/saned.c @@ -32,7 +32,7 @@ #include "../include/lalloca.h" #include "../include/sys/types.h" -#if defined(HAVE_GETADDRINFO) && defined (HAVE_GETNAMEINFO) && defined (HAVE_POLL) +#if defined(HAVE_GETADDRINFO) && defined (HAVE_GETNAMEINFO) # define SANED_USES_AF_INDEP #else # undef ENABLE_IPV6 @@ -63,15 +63,71 @@ #include #include -#ifdef SANED_USES_AF_INDEP -# ifdef HAVE_SYS_POLL_H -# include -# endif /* HAVE_SYS_POLL_H */ -#endif /* SANED_USES_AF_INDEP */ + #include #include #include +#ifdef SANED_USES_AF_INDEP +# if defined(HAVE_SYS_POLL_H) && defined(HAVE_POLL) +# include +# else +/* + * This replacement poll() using select() is only designed to cover + * our needs in main(). It should probably be extended... + */ +struct pollfd +{ + int fd; + short events; + short revents; +}; + +#define POLLIN 0x0001 + +int +poll (struct pollfd *ufds, unsigned int nfds, int timeout) +{ + struct pollfd *fdp; + + fd_set fds; + int maxfd = 0; + unsigned int i; + int ret; + + /* unused */ + timeout = timeout; + + FD_ZERO (&fds); + + for (i = 0, fdp = ufds; i < nfds; i++, fdp++) + { + if (fdp->events & POLLIN) + { + FD_SET (fdp->fd, &fds); + maxfd = (fdp->fd > maxfd) ? fdp->fd : maxfd; + } + } + + maxfd++; + + ret = select (maxfd, &fds, NULL, NULL, NULL); + + if (ret < 0) + return ret; + + for (i = 0, fdp = ufds; i < nfds; i++, fdp++) + { + if (fdp->events & POLLIN) + if (FD_ISSET (fdp->fd, &fds)) + fdp->revents = POLLIN; + } + + return ret; +} +# endif /* HAVE_SYS_POLL_H && HAVE_POLL */ +#endif /* SANED_USES_AF_INDEP */ + #include "../include/sane/sane.h" #include "../include/sane/sanei.h" #include "../include/sane/sanei_net.h"