Hans Leidekker : ws2_32: Return the right value for SO_CONNECT_TIME if the socket is not connected.

Alexandre Julliard julliard at winehq.org
Mon Dec 19 13:39:23 CST 2011


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

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Mon Dec 19 15:42:08 2011 +0100

ws2_32: Return the right value for SO_CONNECT_TIME if the socket is not connected.

---

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

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index b3a79f3..0e9524e 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -2548,14 +2548,21 @@ INT WINAPI WS_getsockopt(SOCKET s, INT level,
         case WS_SO_CONNECT_TIME:
         {
             static int pretendtime = 0;
+            struct WS_sockaddr addr;
+            int len = sizeof(addr);
 
-            if (!pretendtime) FIXME("WS_SO_CONNECT_TIME - faking results\n");
             if (!optlen || *optlen < sizeof(DWORD) || !optval)
             {
                 SetLastError(WSAEFAULT);
                 return SOCKET_ERROR;
             }
-            *(DWORD*)optval = pretendtime++;
+            if (WS_getpeername(s, &addr, &len) == SOCKET_ERROR)
+                *(DWORD *)optval = ~0u;
+            else
+            {
+                if (!pretendtime) FIXME("WS_SO_CONNECT_TIME - faking results\n");
+                *(DWORD *)optval = pretendtime++;
+            }
             *optlen = sizeof(DWORD);
             return ret;
         }
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 4e5bb52..2cb56a6 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -4496,14 +4496,14 @@ static void test_AcceptEx(void)
     SOCKET connector = INVALID_SOCKET;
     SOCKET connector2 = INVALID_SOCKET;
     struct sockaddr_in bindAddress, peerAddress, *readBindAddress, *readRemoteAddress;
-    int socklen;
+    int socklen, optlen;
     GUID acceptExGuid = WSAID_ACCEPTEX, getAcceptExGuid = WSAID_GETACCEPTEXSOCKADDRS;
     LPFN_ACCEPTEX pAcceptEx = NULL;
     LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockaddrs = NULL;
     fd_set fds_accept, fds_send;
     struct timeval timeout = {0,10}; /* wait for 10 milliseconds */
     int got, conn1, i;
-    DWORD bytesReturned;
+    DWORD bytesReturned, connect_time;
     char buffer[1024];
     OVERLAPPED overlapped;
     int iret, localSize = sizeof(struct sockaddr_in), remoteSize = localSize;
@@ -4695,9 +4695,21 @@ static void test_AcceptEx(void)
         &bytesReturned, &overlapped);
     ok(bret == FALSE && WSAGetLastError() == ERROR_IO_PENDING, "AcceptEx returned %d + errno %d\n", bret, WSAGetLastError());
 
+    connect_time = 0xdeadbeef;
+    optlen = sizeof(connect_time);
+    iret = getsockopt(connector, SOL_SOCKET, SO_CONNECT_TIME, (char *)&connect_time, &optlen);
+    ok(!iret, "getsockopt failed %d\n", WSAGetLastError());
+    ok(connect_time == ~0u, "unexpected connect time %u\n", connect_time);
+
     iret = connect(connector, (struct sockaddr*)&bindAddress, sizeof(bindAddress));
     ok(iret == 0, "connecting to accepting socket failed, error %d\n", WSAGetLastError());
 
+    connect_time = 0xdeadbeef;
+    optlen = sizeof(connect_time);
+    iret = getsockopt(connector, SOL_SOCKET, SO_CONNECT_TIME, (char *)&connect_time, &optlen);
+    ok(!iret, "getsockopt failed %d\n", WSAGetLastError());
+    ok(connect_time < 0xdeadbeef, "unexpected connect time %u\n", connect_time);
+
     dwret = WaitForSingleObject(overlapped.hEvent, 0);
     ok(dwret == WAIT_TIMEOUT, "Waiting for accept event timeout failed with %d + errno %d\n", dwret, GetLastError());
 




More information about the wine-cvs mailing list