Module: wine Branch: master Commit: 36d7bf9507360fddc3ac86cc9e827ccb2076cd59 URL: https://gitlab.winehq.org/wine/wine/-/commit/36d7bf9507360fddc3ac86cc9e827cc...
Author: Paul Gofman pgofman@codeweavers.com Date: Fri May 26 20:35:57 2023 -0600
ws2_32: Make wait in connect() alertable.
---
dlls/ws2_32/socket.c | 2 +- dlls/ws2_32/tests/sock.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 930a4000b4e..267830cc88c 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -1240,7 +1240,7 @@ int WINAPI connect( SOCKET s, const struct sockaddr *addr, int len ) free( params ); if (status == STATUS_PENDING) { - if (WaitForSingleObject( sync_event, INFINITE ) == WAIT_FAILED) return -1; + if (wait_event_alertable( sync_event ) == WAIT_FAILED) return -1; status = io.u.Status; } if (status) diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 60c029d3580..31e9baf31c8 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -8443,6 +8443,28 @@ static void test_connect(void) WSACloseEvent(overlapped.hEvent); closesocket(connector);
+ if (0) + { + /* Wait in connect() is alertable. This may take a very long time before connection fails, + * so disable the test. Testing with localhost is unreliable as that may avoid waiting in + * accept(). */ + connector = socket(AF_INET, SOCK_STREAM, 0); + ok(connector != INVALID_SOCKET, "failed to create socket, error %u\n", WSAGetLastError()); + address.sin_addr.s_addr = inet_addr("8.8.8.8"); + address.sin_port = htons(255); + + apc_count = 0; + SleepEx(0, TRUE); + ok(apc_count == 0, "got apc_count %d.\n", apc_count); + bret = QueueUserAPC(apc_func, GetCurrentThread(), (ULONG_PTR)&apc_count); + ok(bret, "QueueUserAPC returned %d\n", bret); + iret = connect(connector, (struct sockaddr *)&address, sizeof(address)); + ok(apc_count == 1, "got apc_count %d.\n", apc_count); + ok(iret == -1 && (WSAGetLastError() == WSAECONNREFUSED || WSAGetLastError() == WSAETIMEDOUT), + "unexpected iret %d, error %d.\n", iret, WSAGetLastError()); + closesocket(connector); + } + /* Test connect after previous connect attempt failure. */ connector = socket(AF_INET, SOCK_STREAM, 0); ok(connector != INVALID_SOCKET, "failed to create socket, error %u\n", WSAGetLastError());