[2/2] ws2_32/tests: Add a test to show what happens when the listen socket is closed after an AcceptEx call.

Hans Leidekker hans at codeweavers.com
Mon Dec 19 08:42:39 CST 2011


---
 dlls/ws2_32/tests/sock.c |   64 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 2cb56a6..3efed68 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -5203,6 +5203,66 @@ static void test_WSAAsyncGetServByPort(void)
     DestroyWindow(hwnd);
 }
 
+static void test_acceptex_closed_listen_socket(void)
+{
+    static GUID acceptex_guid = WSAID_ACCEPTEX;
+    LPFN_ACCEPTEX pAcceptEx;
+    OVERLAPPED overlapped, *ovl;
+    int res, sa_len;
+    struct sockaddr_in sa;
+    SOCKET s1, s2;
+    HANDLE c1, c2;
+    DWORD num_bytes;
+    ULONG_PTR key;
+    char buffer[512];
+    BOOL ret;
+
+    c1 = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, ~0u);
+    ok(c1 != NULL, "CreateIoCompletionPort failed %u\n", GetLastError());
+
+    s1 = WSASocketW(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
+    ok(s1 != INVALID_SOCKET, "WSASocketW failed %d\n", WSAGetLastError());
+
+    c2 = CreateIoCompletionPort((HANDLE)s1, c1, 0, 0);
+    ok(c2 != NULL, "CreateIoCompletionPort failed %u\n", GetLastError());
+
+    memset(&sa, 0, sizeof(sa));
+    sa.sin_family = AF_INET;
+    sa_len = sizeof(sa);
+    res = bind(s1, (struct sockaddr *)&sa, sa_len);
+    ok(!res, "bind failed %d\n", WSAGetLastError());
+
+    res = getsockname(s1, (struct sockaddr *)&sa, &sa_len);
+    ok(!res, "getsockname failed %d\n", WSAGetLastError());
+
+    res = listen(s1, 5);
+    ok(!res, "listen failed %d\n", WSAGetLastError());
+
+    s2 = WSASocketW(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
+    ok(s2 != INVALID_SOCKET, "WSASocketW failed %d", WSAGetLastError());
+
+    res = WSAIoctl(s2, SIO_GET_EXTENSION_FUNCTION_POINTER, &acceptex_guid, sizeof(acceptex_guid),
+                   &pAcceptEx, sizeof(pAcceptEx), &num_bytes, NULL, NULL);
+    ok(!res, "WSAIoctl failed %d\n", WSAGetLastError());
+
+    memset(&overlapped, 0, sizeof(overlapped));
+    WSASetLastError(0xdeadbeef);
+    res = pAcceptEx(s1, s2, buffer, 0, 144, 144, &num_bytes, &overlapped);
+    ok(!res, "AcceptEx failed %d\n", WSAGetLastError());
+    ok(WSAGetLastError() == ERROR_IO_PENDING, "got %u\n", WSAGetLastError());
+
+    closesocket(s1);
+
+    SetLastError(0xdeadbeef);
+    ret = GetQueuedCompletionStatus(c1, &num_bytes, &key, &ovl, 1000);
+    ok(!ret, "GetQueuedCompletionStatus succeeded\n");
+    todo_wine ok(GetLastError() == ERROR_OPERATION_ABORTED, "got %u\n", GetLastError());
+
+    closesocket(s2);
+    CloseHandle(c1);
+    CloseHandle(c2);
+}
+
 /**************** Main program  ***************/
 
 START_TEST( sock )
@@ -5263,12 +5323,12 @@ START_TEST( sock )
     test_ConnectEx();
 
     test_sioRoutingInterfaceQuery();
-
     test_WSAAsyncGetServByPort();
+    test_synchronous_WSAIoctl();
+    test_acceptex_closed_listen_socket();
 
     /* this is a io heavy test, do it at the end so the kernel doesn't start dropping packets */
     test_send();
-    test_synchronous_WSAIoctl();
 
     Exit();
 }
-- 
1.7.7.3






More information about the wine-patches mailing list