Bruno Jesus : ws2_32: Do not poll unbound descriptors.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Mar 30 10:12:57 CDT 2015


Module: wine
Branch: master
Commit: 10f7265270f1ad4e4e1bfec6fb5f06e494d5f579
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=10f7265270f1ad4e4e1bfec6fb5f06e494d5f579

Author: Bruno Jesus <00cpxxx at gmail.com>
Date:   Sun Mar 29 00:53:48 2015 -0300

ws2_32: Do not poll unbound descriptors.

---

 dlls/ws2_32/socket.c     | 39 +++++++++++++++++++++++++++++++++------
 dlls/ws2_32/tests/sock.c |  5 -----
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 26ac305..717a394 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -4479,24 +4479,51 @@ static struct pollfd *fd_sets_to_poll( const WS_fd_set *readfds, const WS_fd_set
         {
             fds[j].fd = get_sock_fd( readfds->fd_array[i], FILE_READ_DATA, NULL );
             if (fds[j].fd == -1) goto failed;
-            fds[j].events = POLLIN;
             fds[j].revents = 0;
+            if (is_fd_bound(fds[j].fd, NULL, NULL) == 1)
+            {
+                fds[j].events = POLLIN;
+            }
+            else
+            {
+                release_sock_fd( readfds->fd_array[i], fds[j].fd );
+                fds[j].fd = -1;
+                fds[j].events = 0;
+            }
         }
     if (writefds)
         for (i = 0; i < writefds->fd_count; i++, j++)
         {
             fds[j].fd = get_sock_fd( writefds->fd_array[i], FILE_WRITE_DATA, NULL );
             if (fds[j].fd == -1) goto failed;
-            fds[j].events = POLLOUT;
             fds[j].revents = 0;
+            if (is_fd_bound(fds[j].fd, NULL, NULL) == 1)
+            {
+                fds[j].events = POLLOUT;
+            }
+            else
+            {
+                release_sock_fd( readfds->fd_array[i], fds[j].fd );
+                fds[j].fd = -1;
+                fds[j].events = 0;
+            }
         }
     if (exceptfds)
         for (i = 0; i < exceptfds->fd_count; i++, j++)
         {
             fds[j].fd = get_sock_fd( exceptfds->fd_array[i], 0, NULL );
             if (fds[j].fd == -1) goto failed;
-            fds[j].events = POLLHUP;
             fds[j].revents = 0;
+            if (is_fd_bound(fds[j].fd, NULL, NULL) == 1)
+            {
+                fds[j].events = POLLHUP;
+            }
+            else
+            {
+                release_sock_fd( readfds->fd_array[i], fds[j].fd );
+                fds[j].fd = -1;
+                fds[j].events = 0;
+            }
         }
     return fds;
 
@@ -4505,13 +4532,13 @@ failed:
     j = 0;
     if (readfds)
         for (i = 0; i < readfds->fd_count && j < count; i++, j++)
-            release_sock_fd( readfds->fd_array[i], fds[j].fd );
+            if (fds[j].fd != -1) release_sock_fd( readfds->fd_array[i], fds[j].fd );
     if (writefds)
         for (i = 0; i < writefds->fd_count && j < count; i++, j++)
-            release_sock_fd( writefds->fd_array[i], fds[j].fd );
+            if (fds[j].fd != -1) release_sock_fd( writefds->fd_array[i], fds[j].fd );
     if (exceptfds)
         for (i = 0; i < exceptfds->fd_count && j < count; i++, j++)
-            release_sock_fd( exceptfds->fd_array[i], fds[j].fd );
+            if (fds[j].fd != -1) release_sock_fd( exceptfds->fd_array[i], fds[j].fd );
     HeapFree( GetProcessHeap(), 0, fds );
     return NULL;
 }
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 87511aa..1f30fda 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -3430,17 +3430,12 @@ static void test_select(void)
     if (fdWrite > maxfd)
         maxfd = fdWrite;
        
-    todo_wine {
     ret = select(maxfd+1, &readfds, &writefds, &exceptfds, &select_timeout);
     ok ( (ret == 0), "select should not return any socket handles\n");
     ok ( !FD_ISSET(fdRead, &readfds), "FD should not be set\n");
-    }
     ok ( !FD_ISSET(fdWrite, &writefds), "FD should not be set\n");
-
-    todo_wine {
     ok ( !FD_ISSET(fdRead, &exceptfds), "FD should not be set\n");
     ok ( !FD_ISSET(fdWrite, &exceptfds), "FD should not be set\n");
-    }
  
     ok ((listen(fdWrite, SOMAXCONN) == SOCKET_ERROR), "listen did not fail\n");
     ret = closesocket(fdWrite);




More information about the wine-cvs mailing list