Bruno Jesus : ws2_32: Handle SO_ERROR manually in getsockopt().

Alexandre Julliard julliard at wine.codeweavers.com
Wed Apr 8 10:40:45 CDT 2015


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

Author: Bruno Jesus <00cpxxx at gmail.com>
Date:   Wed Apr  8 02:02:55 2015 -0300

ws2_32: Handle SO_ERROR manually in getsockopt().

As soon as SO_ERROR is read from getsockopt it is reset in the kernel,
when attempting a non-blocking connection the wine server reads
SO_ERROR first so when the application tries to read the value it will
end with zero.

---

 dlls/ws2_32/socket.c     | 31 ++++++++++++++++++++++++++++++-
 dlls/ws2_32/tests/sock.c |  1 -
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index ad75a75..6903909 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -3286,7 +3286,6 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
          * alphabetically */
         case WS_SO_BROADCAST:
         case WS_SO_DEBUG:
-        case WS_SO_ERROR:
         case WS_SO_KEEPALIVE:
         case WS_SO_OOBINLINE:
         case WS_SO_RCVBUF:
@@ -3450,6 +3449,36 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
             *optlen = sizeof(BOOL);
             return 0;
 
+        case WS_SO_ERROR:
+        {
+            if ( (fd = get_sock_fd( s, 0, NULL )) == -1)
+                return SOCKET_ERROR;
+            if (getsockopt(fd, SOL_SOCKET, SO_ERROR, optval, (socklen_t *)optlen) != 0 )
+            {
+                SetLastError((errno == EBADF) ? WSAENOTSOCK : wsaErrno());
+                ret = SOCKET_ERROR;
+            }
+            release_sock_fd( s, fd );
+
+            /* The wineserver may have swallowed the error before us */
+            if (!ret && *(int*) optval == 0)
+            {
+                int i, events[FD_MAX_EVENTS];
+                _get_sock_errors(s, events);
+                for (i = 0; i < FD_MAX_EVENTS; i++)
+                {
+                    if(events[i])
+                    {
+                        events[i] = NtStatusToWSAError(events[i]);
+                        TRACE("returning SO_ERROR %d from wine server\n", events[i]);
+                        *(int*) optval = events[i];
+                        break;
+                    }
+                }
+            }
+            return ret;
+        }
+
         case WS_SO_LINGER:
         {
             struct linger lingval;
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 2b4daae..5f25471 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -3788,7 +3788,6 @@ static void test_select(void)
     len = sizeof(id);
     id = 0xdeadbeef;
     ok(!getsockopt(fdWrite, SOL_SOCKET, SO_ERROR, (char*)&id, &len), "getsockopt failed with %d\n",WSAGetLastError());
-todo_wine
     ok(id == WSAECONNREFUSED, "expected 10061, got %d\n", id);
     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");




More information about the wine-cvs mailing list