X-Git-Url: https://git.donarmstrong.com/?p=deb_pkgs%2Fspamass-milter.git;a=blobdiff_plain;f=poll.c;fp=poll.c;h=3b26888e74fe7aeb754996f6023fcb5df4ee6a81;hp=0000000000000000000000000000000000000000;hb=8ad6e90591e0369fc6b2955a1fc687f840277eeb;hpb=b7c1bcb26ee594de6aa0a75516fed9c0b4d2ed5f diff --git a/poll.c b/poll.c new file mode 100644 index 0000000..3b26888 --- /dev/null +++ b/poll.c @@ -0,0 +1,65 @@ +#include "config.h" +#include +#include +#include +#include +#ifdef HAVE_SYS_SELECT_H +#include +#endif + +#include "subst_poll.h" + +/* This function pulled from Markus Gutschke's "wy60" package */ + +/* $Id: poll.c,v 1.4 2003/06/09 15:57:35 dnelson Exp $ */ + +int poll(struct pollfd *fds, unsigned long nfds, int timeout) { + // This emulation function is somewhat limited. Most notably, it will never + // report POLLERR, POLLHUP, or POLLNVAL. The calling code has to detect + // these error conditions by some other means (typically by read() or write() + // reporting end-of-file). + fd_set readFds, writeFds, exceptionFds; + struct timeval *timeoutPtr, timeoutStruct; + int i, rc, fd; + + FD_ZERO(&readFds); + FD_ZERO(&writeFds); + FD_ZERO(&exceptionFds); + fd = -1; + for (i = nfds; i--; ) { + if (fds[i].events & POLLIN) + FD_SET(fds[i].fd, &readFds); + if (fds[i].events & POLLOUT) + FD_SET(fds[i].fd, &writeFds); + if (fds[i].events & POLLPRI) + FD_SET(fds[i].fd, &exceptionFds); + if (fds[i].fd > fd) + fd = fds[i].fd; + fds[i].revents = 0; + } + if (timeout < 0) + timeoutPtr = NULL; + else { + timeoutStruct.tv_sec = timeout/1000; + timeoutStruct.tv_usec = (timeout%1000) * 1000; + timeoutPtr = &timeoutStruct; + } + i = select(fd + 1, &readFds, &writeFds, &exceptionFds, + timeoutPtr); + if (i <= 0) + rc = i; + else { + rc = 0; + for (i = nfds; i--; ) { + if (FD_ISSET(fds[i].fd, &readFds)) + fds[i].revents |= POLLIN; + if (FD_ISSET(fds[i].fd, &writeFds)) + fds[i].revents |= POLLOUT; + if (FD_ISSET(fds[i].fd, &exceptionFds)) + fds[i].revents |= POLLPRI; + if (fds[i].revents) + rc++; + } + } + return(rc); +}