WS2_32: Proper WSACleanup implementation using wineserver help (try 2)

Matt Durgavich mattdurgavich at gmail.com
Sun Aug 30 10:04:08 CDT 2015


Fixes some tests and also bug 32910

From 6b34d1b9f6cfa491a26b9c36e395c3b180b5ceea Mon Sep 17 00:00:00 2001
From: Matt <matt at wymzee.com>
Date: Thu, 27 Aug 2015 23:43:59 -0400
Subject: [PATCH] WS2_32: Proper WSACleanup implementation using wineserver
 help

---
 dlls/ws2_32/socket.c     |  9 +++++++++
 dlls/ws2_32/tests/sock.c |  5 ++---
 server/protocol.def      |  3 +++
 server/sock.c            | 10 ++++++++++
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index ca82ec9..4e6f0e1 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -1471,6 +1471,15 @@ INT WINAPI WSACleanup(void)
 {
     if (num_startup) {
         num_startup--;
+        if (num_startup == 0) 
+        {
+            SERVER_START_REQ(socket_cleanup) 
+            {
+                wine_server_call( req );
+            }
+            SERVER_END_REQ;
+        }
+        
         TRACE("pending cleanups: %d\n", num_startup);
         return 0;
     }
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index 2d14496..c26d5b1 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -1119,20 +1119,19 @@ static void test_WithWSAStartup(void)
     ok(res == 0, "WSAStartup() failed unexpectedly: %d\n", res);
 
     /* show that sockets are destroyed automatically after WSACleanup */
-    todo_wine {
     SetLastError(0xdeadbeef);
     res = send(src, "TEST", 4, 0);
     error = WSAGetLastError();
     ok(res == SOCKET_ERROR, "send should have failed\n");
+    todo_wine
     ok(error == WSAENOTSOCK, "expected 10038, got %d\n", error);
 
     SetLastError(0xdeadbeef);
     res = closesocket(dst);
     error = WSAGetLastError();
     ok(res == SOCKET_ERROR, "closesocket should have failed\n");
+    todo_wine 
     ok(error == WSAENOTSOCK, "expected 10038, got %d\n", error);
-    }
-
     closesocket(src);
     closesocket(dst);
 
diff --git a/server/protocol.def b/server/protocol.def
index c313006..2dccb9a 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -942,6 +942,9 @@ struct rawinput_device
     obj_handle_t handle;       /* handle to close */
 @END
 
+/* Close all sockets for the current process */
+ at REQ(socket_cleanup)
+ at END
 
 /* Set a handle information */
 @REQ(set_handle_info)
diff --git a/server/sock.c b/server/sock.c
index 67d6416..c5c5083 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -1383,3 +1383,13 @@ DECL_HANDLER(get_socket_info)
 
     release_object( &sock->obj );
 }
+
+DECL_HANDLER(socket_cleanup)
+{
+    obj_handle_t sock;
+    unsigned int index = 0;
+    while ( (sock = enumerate_handles(current->process, &sock_ops, &index)) ) 
+    {
+        close_handle(current->process, sock);
+    }
+}
-- 
2.3.2 (Apple Git-55)




More information about the wine-patches mailing list