From 10f7265270f1ad4e4e1bfec6fb5f06e494d5f579 Mon Sep 17 00:00:00 2001 From: Bruno Jesus <00cpxxx@gmail.com> Date: Sun, 29 Mar 2015 00:53:48 -0300 Subject: [PATCH] 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 26ac30599ff..717a394cef6 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 87511aa9a8a..1f30fda8b0d 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);