[vlc-devel] [PATCH 2/3] poll: remove unneeded select() call

Steve Lhomme robux4 at videolabs.io
Thu Nov 26 17:57:01 CET 2015


---
 compat/poll.c | 38 +++++---------------------------------
 1 file changed, 5 insertions(+), 33 deletions(-)

diff --git a/compat/poll.c b/compat/poll.c
index 0b2ae3e..15e98a6 100644
--- a/compat/poll.c
+++ b/compat/poll.c
@@ -131,24 +131,14 @@ int poll(struct pollfd *fds, unsigned nfds, int timeout)
     for (unsigned i = 0; i < nfds; i++)
     {
         long mask = FD_CLOSE;
-        fd_set rdset, wrset, exset;
 
-        FD_ZERO(&rdset);
-        FD_ZERO(&wrset);
-        FD_ZERO(&exset);
-        FD_SET(fd, &exset);
+        if (fds[i].events & (POLLRDNORM|POLLIN))
+            mask |= FD_READ | FD_ACCEPT | FD_OOB;
 
-        if (fds[i].events & POLLRDNORM)
-        {
-            mask |= FD_READ | FD_ACCEPT;
-            FD_SET(fd, &rdset);
-        }
-        if (fds[i].events & POLLWRNORM)
-        {
+        if (fds[i].events & (POLLWRNORM|POLLOUT))
             mask |= FD_WRITE | FD_CONNECT;
-            FD_SET(fd, &wrset);
-        }
-        if (fds[i].events & POLLPRI)
+
+        if (fds[i].events & (POLLRDBAND|POLLPRI))
             mask |= FD_OOB;
 
         /* discard the events we're looking for, keep the other ones */
@@ -168,24 +158,6 @@ int poll(struct pollfd *fds, unsigned nfds, int timeout)
          && WSAGetLastError() == WSAENOTSOCK)
             fds[i].revents |= POLLNVAL;
 
-        struct timeval tv = { 0, 0 };
-        /* By its horrible design, WSAEnumNetworkEvents() only enumerates
-         * events that were not already signaled (i.e. it is edge-triggered).
-         * WSAPoll() would be better in this respect, but worse in others.
-         * So use WSAEnumNetworkEvents() after manually checking for pending
-         * events. */
-        if (select(0, &rdset, &wrset, &exset, &tv) > 0)
-        {
-            if (FD_ISSET(fd, &rdset))
-                fds[i].revents |= fds[i].events & POLLRDNORM;
-            if (FD_ISSET(fd, &wrset))
-                fds[i].revents |= fds[i].events & POLLWRNORM;
-            if (FD_ISSET(fd, &exset))
-                /* To add pain to injury, POLLERR and POLLPRI cannot be
-                 * distinguished here. */
-                fds[i].revents |= POLLERR | (fds[i].events & POLLPRI);
-        }
-
         if (fds[i].revents != 0 && ret == WSA_WAIT_FAILED)
             ret = WSA_WAIT_EVENT_0 + i;
     }
-- 
2.6.3



More information about the vlc-devel mailing list