X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpoll.c;h=ed81dbaafb85f4feb82533833c9480251e857fa9;hb=fa662f811f9a6dda54f64639b107b1637c3ba2e5;hp=cda022c64a574abd6bc9500155f974998b6d7f2f;hpb=ceb9fb5512d62846bf8c281c3ee110297f9e0446;p=gnulib.git diff --git a/lib/poll.c b/lib/poll.c index cda022c64..ed81dbaaf 100644 --- a/lib/poll.c +++ b/lib/poll.c @@ -36,16 +36,8 @@ #include #endif -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif +#include +#include #ifndef INFTIM #define INFTIM (-1) @@ -55,6 +47,11 @@ #define EOVERFLOW EINVAL #endif +/* BeOS does not have MSG_PEEK. */ +#ifndef MSG_PEEK +#define MSG_PEEK 0 +#endif + int poll (pfd, nfd, timeout) struct pollfd *pfd; @@ -133,11 +130,16 @@ poll (pfd, nfd, timeout) | POLLWRNORM | POLLWRBAND))) { maxfd = pfd[i].fd; + + /* Windows use a linear array of sockets (of size FD_SETSIZE). The + descriptor value is not used to address the array. */ +#if defined __CYGWIN__ || (!defined _WIN32 && !defined __WIN32__) if (maxfd > FD_SETSIZE) { errno = EOVERFLOW; return -1; } +#endif } } @@ -157,7 +159,7 @@ poll (pfd, nfd, timeout) if (FD_ISSET (pfd[i].fd, &rfds)) { int r; - + #if defined __MACH__ && defined __APPLE__ /* There is a bug in Mac OS X that causes it to ignore MSG_PEEK for some kinds of descriptors. Detect if this descriptor is a @@ -172,27 +174,27 @@ poll (pfd, nfd, timeout) #endif if (r == 0) happened |= POLLHUP; - + /* If the event happened on an unconnected server socket, that's fine. */ else if (r > 0 || ( /* (r == -1) && */ errno == ENOTCONN)) happened |= (POLLIN | POLLRDNORM) & sought; - + /* Distinguish hung-up sockets from other errors. */ else if (errno == ESHUTDOWN || errno == ECONNRESET || errno == ECONNABORTED || errno == ENETRESET) happened |= POLLHUP; - + else happened |= POLLERR; } - + if (FD_ISSET (pfd[i].fd, &wfds)) happened |= (POLLOUT | POLLWRNORM | POLLWRBAND) & sought; - + if (FD_ISSET (pfd[i].fd, &efds)) happened |= (POLLPRI | POLLRDBAND) & sought; - + if (happened) { pfd[i].revents = happened;