[PATCH] ws2_32: Don't return synchronously if the connection is refused.

Huw Davies huw at codeweavers.com
Mon Aug 7 09:39:14 CDT 2017


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/ws2_32/socket.c     |  5 +++++
 dlls/ws2_32/tests/sock.c | 20 ++++++--------------
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 9cae18f5b1..9d254e8281 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -3586,7 +3586,12 @@ static BOOL WINAPI WS2_ConnectEx(SOCKET s, const struct WS_sockaddr* name, int n
 
             /* If the connect already failed */
             if (status == STATUS_PIPE_DISCONNECTED)
+            {
                 status = _get_sock_error(s, FD_CONNECT_BIT);
+                if (cvalue) WS_AddCompletion( s, cvalue, status, 0 );
+                if (ov->hEvent) NtSetEvent( ov->hEvent, NULL );
+                status = STATUS_PENDING;
+            }
             SetLastError( NtStatusToWSAError(status) );
         }
     }
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 43008cf6ca..897839a7a0 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -7915,22 +7915,14 @@ static void test_ConnectEx(void)
     address.sin_port = htons(1);
 
     bret = pConnectEx(connector, (struct sockaddr*)&address, addrlen, NULL, 0, &bytesReturned, &overlapped);
-    ok(bret == FALSE && GetLastError(), "ConnectEx to bad destination failed: "
+    ok(bret == FALSE && GetLastError() == ERROR_IO_PENDING, "ConnectEx to bad destination failed: "
         "returned %d + errno %d\n", bret, GetLastError());
+    dwret = WaitForSingleObject(overlapped.hEvent, 15000);
+    ok(dwret == WAIT_OBJECT_0, "Waiting for connect event failed with %d + errno %d\n", dwret, GetLastError());
 
-    if (GetLastError() == ERROR_IO_PENDING)
-    {
-        dwret = WaitForSingleObject(overlapped.hEvent, 15000);
-        ok(dwret == WAIT_OBJECT_0, "Waiting for connect event failed with %d + errno %d\n", dwret, GetLastError());
-
-        bret = GetOverlappedResult((HANDLE)connector, &overlapped, &bytesReturned, FALSE);
-        ok(bret == FALSE && GetLastError() == ERROR_CONNECTION_REFUSED,
-           "Connecting to a disconnected host returned error %d - %d\n", bret, WSAGetLastError());
-    }
-    else {
-        ok(GetLastError() == WSAECONNREFUSED,
-           "Connecting to a disconnected host returned error %d - %d\n", bret, WSAGetLastError());
-    }
+    bret = GetOverlappedResult((HANDLE)connector, &overlapped, &bytesReturned, FALSE);
+    ok(bret == FALSE && GetLastError() == ERROR_CONNECTION_REFUSED,
+       "Connecting to a disconnected host returned error %d - %d\n", bret, WSAGetLastError());
 
 end:
     if (overlapped.hEvent)
-- 
2.12.0




More information about the wine-patches mailing list