[PATCH 5/7] winhttp: Don't queue socket_close() in WinHttpWebSocketClose() if close frame is already received.

Paul Gofman pgofman at codeweavers.com
Thu Jan 27 17:06:29 CST 2022


Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
 dlls/winhttp/request.c            |  7 +++++++
 dlls/winhttp/tests/notification.c | 10 ++++++++++
 2 files changed, 17 insertions(+)

diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c
index 5568f04d0d0..04df90f74d7 100644
--- a/dlls/winhttp/request.c
+++ b/dlls/winhttp/request.c
@@ -3959,6 +3959,13 @@ DWORD WINAPI WinHttpWebSocketClose( HINTERNET hsocket, USHORT status, void *reas
     if (prev_state < SOCKET_STATE_SHUTDOWN
         && (ret = send_socket_shutdown( socket, status, reason, len, FALSE ))) goto done;
 
+    if (!pending_receives && socket->close_frame_received)
+    {
+        if (socket->request->connect->hdr.flags & WINHTTP_FLAG_ASYNC)
+            socket_close_complete( socket, socket->close_frame_receive_err );
+        goto done;
+    }
+
     if (socket->request->connect->hdr.flags & WINHTTP_FLAG_ASYNC)
     {
         struct socket_shutdown *s;
diff --git a/dlls/winhttp/tests/notification.c b/dlls/winhttp/tests/notification.c
index 1ae1bb537b0..3dc94a909b4 100644
--- a/dlls/winhttp/tests/notification.c
+++ b/dlls/winhttp/tests/notification.c
@@ -728,6 +728,8 @@ static const struct notification websocket_test3[] =
 
     { winhttp_websocket_shutdown,         WINHTTP_CALLBACK_STATUS_SHUTDOWN_COMPLETE, NF_MAIN_THREAD },
     { winhttp_websocket_shutdown,         WINHTTP_CALLBACK_STATUS_READ_COMPLETE, NF_SAVE_BUFFER | NF_SIGNAL },
+    { winhttp_websocket_close,            WINHTTP_CALLBACK_STATUS_CLOSE_COMPLETE,
+                                                                 NF_MAIN_THREAD| NF_SAVE_BUFFER | NF_SIGNAL },
     { winhttp_close_handle,               WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING },
     { winhttp_close_handle,               WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION, NF_WINE_ALLOW },
     { winhttp_close_handle,               WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, NF_WINE_ALLOW },
@@ -1130,6 +1132,14 @@ static void test_websocket(BOOL secure)
     ok( close_status == 1000, "got %u\n", close_status );
     ok( size <= sizeof(buffer), "got %u\n", size );
 
+    info.buflen = 0xdeadbeef;
+    setup_test( &info, winhttp_websocket_close, __LINE__ );
+    err = pWinHttpWebSocketClose( socket, 1000, (void *)"success", sizeof("success") );
+    ok( err == ERROR_SUCCESS, "got %u\n", err );
+
+    WaitForSingleObject( info.wait, INFINITE );
+    ok( !info.buflen, "Got unexpected buflen %u.\n", info.buflen );
+
     setup_test( &info, winhttp_close_handle, __LINE__ );
 
     WinHttpCloseHandle( socket );
-- 
2.34.1




More information about the wine-devel mailing list