]> git.sesse.net Git - vlc/blobdiff - compat/poll.c
decoder: remove unnecessary special case
[vlc] / compat / poll.c
index ef00fa592488f6408c088ebade4e4a8686ceb610..b88f7fd278a57f6a52e658985045f58cdc38515c 100644 (file)
@@ -26,7 +26,7 @@
 #include <string.h>
 #include <errno.h>
 
-#ifdef WIN32
+#ifdef _WIN32
 # ifdef FD_SETSIZE
 /* Too late for #undef FD_SETSIZE to work: fd_set is already defined. */
 #  error Header inclusion order compromised!
 #else
 # include <sys/time.h>
 # include <sys/select.h>
+# include <fcntl.h>
 #endif
 
 int (poll) (struct pollfd *fds, unsigned nfds, int timeout)
 {
-#ifdef WIN32
+#ifdef _WIN32
     size_t setsize = sizeof (fd_set) + nfds * sizeof (SOCKET);
     fd_set *rdset = malloc (setsize);
     fd_set *wrset = malloc (setsize);
@@ -89,7 +90,7 @@ int (poll) (struct pollfd *fds, unsigned nfds, int timeout)
          * Note that Vista has a much nicer WSAPoll(), but Mingw does not
          * support it yet.
          */
-#ifndef WIN32
+#ifndef _WIN32
         if ((unsigned)fd >= FD_SETSIZE)
         {
             errno = EINVAL;
@@ -114,7 +115,32 @@ int (poll) (struct pollfd *fds, unsigned nfds, int timeout)
     val = select (val + 1, rdset, wrset, exset,
                   (timeout >= 0) ? &tv : NULL);
     if (val == -1)
-        return -1;
+    {
+#ifndef _WIN32
+        if (errno != EBADF)
+#else
+        if (WSAGetLastError () != WSAENOTSOCK)
+#endif
+            return -1;
+
+        val = 0;
+
+        for (unsigned i = 0; i < nfds; i++)
+#ifndef _WIN32
+            if (fcntl (fds[i].fd, F_GETFD) == -1)
+#else
+            if (getsockopt (fds[i].fd, SOL_SOCKET, SO_REUSEADDR,
+                            &(DWORD){ 0 }, &(int){ sizeof (DWORD) }) != 0)
+#endif
+            {
+                fds[i].revents = POLLNVAL;
+                val++;
+            }
+            else
+                fds[i].revents = 0;
+
+        return val ? val : -1;
+    }
 
     for (unsigned i = 0; i < nfds; i++)
     {
@@ -123,7 +149,7 @@ int (poll) (struct pollfd *fds, unsigned nfds, int timeout)
                        | (FD_ISSET (fd, wrset) ? POLLOUT : 0)
                        | (FD_ISSET (fd, exset) ? POLLPRI : 0);
     }
-#ifdef WIN32
+#ifdef _WIN32
     free (exset);
     free (wrset);
     free (rdset);