[4/7] ws2_32: Ensure sockets in exceptfds get set when an error occurs

Bruno Jesus 00cpxxx at gmail.com
Sat Mar 28 22:53:43 CDT 2015


This patch is basically changing code introduced in 1996 [1] to deal
with select() problems. When poll returns POLLHUP that is a clear sign
that there was an error in the socket.

The todo's added will be removed in the next patch.

Fixes https://bugs.winehq.org/show_bug.cgi?id=38294 and part of
https://bugs.winehq.org/show_bug.cgi?id=9425

[1] http://source.winehq.org/git/wine.git/commitdiff/7e6ae4ba5eaae3cf2df509b56f6314c0103c49a9#patch30
-------------- next part --------------

---
 dlls/ws2_32/socket.c     | 16 +---------------
 dlls/ws2_32/tests/sock.c |  4 ++--
 2 files changed, 3 insertions(+), 17 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 0b8e2cb..26ac305 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -1124,15 +1124,6 @@ static char *strdup_lower(const char *str)
     return ret;
 }
 
-static inline int sock_error_p(int s)
-{
-    unsigned int optval;
-    socklen_t optlen = sizeof(optval);
-    getsockopt(s, SOL_SOCKET, SO_ERROR, (void *) &optval, &optlen);
-    if (optval) WARN("\t[%i] error: %d\n", s, optval);
-    return optval != 0;
-}
-
 /* Utility: get the SO_RCVTIMEO or SO_SNDTIMEO socket option
  * from an fd and return the value converted to milli seconds
  * or -1 if there is an infinite time out */
@@ -4545,12 +4536,7 @@ static void release_poll_fds( const WS_fd_set *readfds, const WS_fd_set *writefd
     if (exceptfds)
     {
         for (i = 0; i < exceptfds->fd_count; i++, j++)
-            if (fds[j].fd != -1)
-            {
-                /* make sure we have a real error before releasing the fd */
-                if (!sock_error_p( fds[j].fd )) fds[j].revents = 0;
-                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 );
     }
 }
 
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 638a767..87511aa 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -3437,8 +3437,10 @@ static void test_select(void)
     }
     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);
@@ -3683,9 +3685,7 @@ todo_wine
     FD_SET(fdWrite, &exceptfds);
     select_timeout.tv_sec = 2; /* requires more time to realize it will not connect */
     ret = select(0, &readfds, &writefds, &exceptfds, &select_timeout);
-todo_wine
     ok(ret == 1, "expected 1, got %d\n", ret);
-todo_wine
     ok(FD_ISSET(fdWrite, &exceptfds), "fdWrite socket is not in the set\n");
     ok(select_timeout.tv_usec == 250000, "select timeout should not have changed\n");
     closesocket(fdWrite);
-- 
2.1.4



More information about the wine-patches mailing list