ws2_32: WSACleanup cleans up open sockets (OSX only)

Matt Durgavich mattdurgavich at gmail.com
Fri Aug 28 17:28:05 CDT 2015


Ok, here  we go. Feedback in place.


 dlls/ws2_32/socket.c | 18 ++++++++----------
 server/handle.c      | 11 -----------
 server/protocol.def  |  2 +-
 server/sock.c        | 12 +++++++++++-
 4 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 66d5b2b..a4c442f 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -1473,16 +1473,14 @@ INT WINAPI WSACleanup(void)
         num_startup--;
         if (num_startup == 0) 
         {
-            SERVER_START_REQ(close_all_sockets) 
-            {
-                wine_server_call( req );
-            }
-            SERVER_END_REQ;
-        }
-        else
-        {
-            TRACE("pending cleanups: %d\n", num_startup);
-        }
+          SERVER_START_REQ(close_process_sockets) 
+          {
+            wine_server_call( req );
+          }
+          SERVER_END_REQ;
+        }
+        
+        TRACE("pending cleanups: %d\n", num_startup);
         return 0;
     }
     SetLastError(WSANOTINITIALISED);
diff --git a/server/handle.c b/server/handle.c
index b4b5ecb..53bf50a 100644
--- a/server/handle.c
+++ b/server/handle.c
@@ -39,8 +39,6 @@
 #include "security.h"
 #include "request.h"
 
-extern struct object_ops sock_ops;
-
 struct handle_entry
 {
     struct object *ptr;       /* object */
@@ -610,15 +608,6 @@ DECL_HANDLER(set_handle_info)
     reply->old_flags = set_handle_flags( current->process, req->handle, req->mask, req->flags );
 }
 
-DECL_HANDLER(close_all_sockets)
-{
-    obj_handle_t sock;
-    UINT index = 0;
-    while ( (sock = enumerate_handles(current->process, &sock_ops, &index)) ) 
-    {
-        close_handle(current->process, sock);
-    }
-}
 
 /* duplicate a handle */
 DECL_HANDLER(dup_handle)
diff --git a/server/protocol.def b/server/protocol.def
index 651af47..fb63da1 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -943,7 +943,7 @@ struct rawinput_device
 @END
 
 /* Close all sockets for the current process */
- at REQ(close_all_sockets)
+ at REQ(close_process_sockets)
 @END
 
 /* Set a handle information */
diff --git a/server/sock.c b/server/sock.c
index 2a9f444..c077755 100644
--- a/server/sock.c
+++ b/server/sock.c
@@ -138,7 +138,7 @@ static int sock_get_ntstatus( int err );
 static int sock_get_error( int err );
 static void sock_set_error(void);
 
-const struct object_ops sock_ops =
+static const struct object_ops sock_ops =
 {
     sizeof(struct sock),          /* size */
     sock_dump,                    /* dump */
@@ -1383,3 +1383,13 @@ DECL_HANDLER(get_socket_info)
 
     release_object( &sock->obj );
 }
+
+DECL_HANDLER(close_process_sockets)
+{
+    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)

> On Aug 28, 2015, at 10:37 AM, Bruno Jesus <00cpxxx at gmail.com> wrote:
> 
> On Fri, Aug 28, 2015 at 8:30 PM, Henri Verbeet <hverbeet at gmail.com> wrote:
>> On 28 August 2015 at 05:46, Matt Durgavich <mattdurgavich at gmail.com> wrote:
>>> +DECL_HANDLER(close_all_sockets)
>> You'll want to just move this to sock.c and avoid making sock_ops
>> available outside sock.c. You may want to change the request name to
>> something along the lines of "close_process_sockets", since it only
>> closes sockets for the current process, not all sockets the server
>> knows about.
> 
> I think a better name would be winsock_cleanup or socket_cleanup
> because closing the sockets may not be the only action required to
> proper implement WSACleanup.
> 
>> +        }
>> +        else
>> +        {
>> +            TRACE("pending cleanups: %d\n", num_startup);
>> +        }
> 
> Please just drop the else and let the message be printed so the amount
> of cleanups and starts is always displayed in the log.




More information about the wine-devel mailing list