Paul Gofman : ws2_32: Force adding completion for error status in WS2_ConnectEx().

Alexandre Julliard julliard at winehq.org
Fri Nov 13 15:57:52 CST 2020


Module: wine
Branch: master
Commit: 2793bdeb2694b5dc15883773cbabe0300990ffc1
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=2793bdeb2694b5dc15883773cbabe0300990ffc1

Author: Paul Gofman <pgofman at codeweavers.com>
Date:   Fri Nov 13 22:05:52 2020 +0300

ws2_32: Force adding completion for error status in WS2_ConnectEx().

Fixes Paradox launcher hang on start (which happens after commit
0c2f556afe7b5fcc873c737512fae5b9c8c07624).

The referenced commit did not introduce the problem, it just made
getsockopt(..., WS_SO_PROTOCOL_INFOW, ) working and the application
is taking another path after getting XP1_IFS_HANDLES flag for protocol.

Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

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

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 3efa4ebd64f..7d810c6d7b2 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -3485,7 +3485,7 @@ static BOOL WINAPI WS2_ConnectEx(SOCKET s, const struct WS_sockaddr* name, int n
             {
                 ov->Internal = sock_error_to_ntstatus( get_sock_error( s, FD_CONNECT_BIT  ));
                 ov->InternalHigh = 0;
-                if (cvalue) WS_AddCompletion( s, cvalue, ov->Internal, ov->InternalHigh, FALSE );
+                if (cvalue) WS_AddCompletion( s, cvalue, ov->Internal, ov->InternalHigh, TRUE );
                 if (ov->hEvent) NtSetEvent( ov->hEvent, NULL );
                 status = STATUS_PENDING;
             }
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 9357ad0d872..2d69a05aec5 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -7182,11 +7182,13 @@ static void test_ConnectEx(void)
     SOCKET connector = INVALID_SOCKET;
     struct sockaddr_in address, conaddress;
     int addrlen;
-    OVERLAPPED overlapped;
+    OVERLAPPED overlapped, *olp;
     LPFN_CONNECTEX pConnectEx;
     GUID connectExGuid = WSAID_CONNECTEX;
+    HANDLE previous_port, io_port;
     DWORD bytesReturned;
     char buffer[1024];
+    ULONG_PTR key;
     BOOL bret;
     DWORD dwret;
     int iret;
@@ -7305,18 +7307,39 @@ static void test_ConnectEx(void)
 
     address.sin_port = htons(1);
 
+    previous_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
+    ok( previous_port != NULL, "Failed to create completion port %u\n", GetLastError());
+
+    io_port = CreateIoCompletionPort((HANDLE)connector, previous_port, 125, 0);
+    ok(io_port != NULL, "failed to create completion port %u\n", GetLastError());
+
+    bret = SetFileCompletionNotificationModes((HANDLE)connector, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS);
+    ok(bret, "Got unexpected bret %#x, GetLastError() %u.\n", bret, GetLastError());
+
     bret = pConnectEx(connector, (struct sockaddr*)&address, addrlen, NULL, 0, &bytesReturned, &overlapped);
     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());
 
+    bytesReturned = 0xdeadbeef;
+    bret = GetQueuedCompletionStatus( io_port, &bytesReturned, &key, &olp, 200 );
+    ok(!bret && GetLastError() == ERROR_CONNECTION_REFUSED, "Got unexpected bret %#x, GetLastError() %u.\n",
+            bret, GetLastError());
+    ok(key == 125, "Key is %lu\n", key);
+    ok(!bytesReturned, "Number of bytes transferred is %u\n", bytesReturned);
+    ok(olp == &overlapped, "Overlapped structure is at %p\n", olp);
+
     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());
 
+    CloseHandle(io_port);
+
     WSACloseEvent(overlapped.hEvent);
     closesocket(connector);
+
+    CloseHandle(previous_port);
 }
 
 static void test_AcceptEx(void)
@@ -10557,7 +10580,6 @@ START_TEST( sock )
 
     test_WSAAsyncGetServByPort();
     test_WSAAsyncGetServByName();
-
     test_completion_port();
     test_address_list_query();
 




More information about the wine-cvs mailing list