New modules unistr/u*-mbsnlen.
[gnulib.git] / lib / poll.c
index cda022c..ed81dba 100644 (file)
 #include <sys/filio.h>
 #endif
 
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
+#include <sys/time.h>
+#include <time.h>
 
 #ifndef INFTIM
 #define INFTIM (-1)
 #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;