]> sourceware.org Git - newlib-cygwin.git/commitdiff
* poll.cc (poll): Return count of fds with events instead of total
authorCorinna Vinschen <corinna@vinschen.de>
Thu, 13 Dec 2007 10:57:08 +0000 (10:57 +0000)
committerCorinna Vinschen <corinna@vinschen.de>
Thu, 13 Dec 2007 10:57:08 +0000 (10:57 +0000)
event count.

winsup/cygwin/ChangeLog
winsup/cygwin/poll.cc

index 8f5116232d6ce28d7054ed7fe8cb5f278d622be1..375167f0048d9aa954a1b0f9ba7c4d634424f72e 100644 (file)
@@ -1,3 +1,9 @@
+2007-12-13  Craig MacGregor  <cmacgreg@gmail.com>
+           Corinna Vinschen  <corinna@vinschen.de>
+
+       * poll.cc (poll): Return count of fds with events instead of total
+       event count.
+
 2007-12-13  Corinna Vinschen  <corinna@vinschen.de>
 
        * string.h: Guard cygwin internal string function definitions with
index 3be689c907f646dfa28aee79618ba3db6d46abf5..eda38ba5b6d6149c128b4af2b6ac37f494b82e8f 100644 (file)
@@ -1,6 +1,6 @@
 /* poll.cc. Implements poll(2) via usage of select(2) call.
 
-   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 Red Hat, Inc.
+   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
 
    This file is part of Cygwin.
 
@@ -76,44 +76,51 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout)
   if (invalid_fds)
     return invalid_fds;
 
-  int ret = cygwin_select (max_fd + 1, read_fds, write_fds, except_fds, timeout < 0 ? NULL : &tv);
-
-  if (ret > 0)
-    for (unsigned int i = 0; i < nfds; ++i)
-      {
-       if (fds[i].fd >= 0)
-         {
-           if (cygheap->fdtab.not_open (fds[i].fd))
-             fds[i].revents = POLLHUP;
-           else
-             {
-               fhandler_socket *sock;
-
-               if (FD_ISSET(fds[i].fd, read_fds))
-                 /* This should be sufficient for sockets, too.  Using
-                    MSG_PEEK, as before, can be considered dangerous at
-                    best.  Quote from W. Richard Stevens: "The presence
-                    of an error can be considered either normal data or
-                    an error (POLLERR).  In either case, a subsequent read
-                    will return -1 with errno set to the appropriate value."
-                    So it looks like there's actually no good reason to
-                    return POLLERR. */
-                 fds[i].revents |= POLLIN;
-               /* Handle failed connect. */
-               if (FD_ISSET(fds[i].fd, write_fds)
-                   && (sock = cygheap->fdtab[fds[i].fd]->is_socket ())
-                   && sock->connect_state () == connect_failed)
-                 fds[i].revents |= (POLLIN | POLLERR);
-               else
-                 {
-                   if (FD_ISSET(fds[i].fd, write_fds))
-                     fds[i].revents |= POLLOUT;
-                   if (FD_ISSET(fds[i].fd, except_fds))
-                     fds[i].revents |= POLLPRI;
-                 }
-             }
-         }
-      }
+  int ret = cygwin_select (max_fd + 1, read_fds, write_fds, except_fds,
+                          timeout < 0 ? NULL : &tv);
+  if (ret <= 0)
+    return ret;
+
+  /* Set revents fields and count fds with non-zero revents fields for
+     return value. */
+  ret = 0;
+  for (unsigned int i = 0; i < nfds; ++i)
+    {
+      if (fds[i].fd >= 0)
+       {
+         if (cygheap->fdtab.not_open (fds[i].fd))
+           fds[i].revents = POLLHUP;
+         else
+           {
+             fhandler_socket *sock;
+
+             if (FD_ISSET(fds[i].fd, read_fds))
+               /* This should be sufficient for sockets, too.  Using
+                  MSG_PEEK, as before, can be considered dangerous at
+                  best.  Quote from W. Richard Stevens: "The presence
+                  of an error can be considered either normal data or
+                  an error (POLLERR).  In either case, a subsequent read
+                  will return -1 with errno set to the appropriate value."
+                  So it looks like there's actually no good reason to
+                  return POLLERR. */
+               fds[i].revents |= POLLIN;
+             /* Handle failed connect. */
+             if (FD_ISSET(fds[i].fd, write_fds)
+                 && (sock = cygheap->fdtab[fds[i].fd]->is_socket ())
+                 && sock->connect_state () == connect_failed)
+               fds[i].revents |= (POLLIN | POLLERR);
+             else
+               {
+                 if (FD_ISSET(fds[i].fd, write_fds))
+                   fds[i].revents |= POLLOUT;
+                 if (FD_ISSET(fds[i].fd, except_fds))
+                   fds[i].revents |= POLLPRI;
+               }
+           }
+         if (fds[i].revents)
+           ++ret;
+       }
+    }
 
   return ret;
 }
This page took 0.034967 seconds and 5 git commands to generate.