Zebediah Figura : ws2_32: Cache the synchronous I/O event in the per-thread data.

Alexandre Julliard julliard at winehq.org
Tue May 18 15:42:36 CDT 2021


Module: wine
Branch: master
Commit: 520a84870f300de0422aa815198b3fd5ea6fdab1
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=520a84870f300de0422aa815198b3fd5ea6fdab1

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Mon May 17 21:29:56 2021 -0500

ws2_32: Cache the synchronous I/O event in the per-thread data.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ws2_32/socket.c         | 18 +++++++++++++-----
 dlls/ws2_32/ws2_32_private.h |  1 +
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 2ba1982b1d9..94f3f139c9c 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -1280,6 +1280,8 @@ static void free_per_thread_data(void)
 
     if (!ptb) return;
 
+    CloseHandle( ptb->sync_event );
+
     /* delete scratch buffers */
     HeapFree( GetProcessHeap(), 0, ptb->he_buffer );
     HeapFree( GetProcessHeap(), 0, ptb->se_buffer );
@@ -1290,6 +1292,16 @@ static void free_per_thread_data(void)
     NtCurrentTeb()->WinSockData = NULL;
 }
 
+static HANDLE get_sync_event(void)
+{
+    struct per_thread_data *data;
+
+    if (!(data = get_per_thread_data())) return NULL;
+    if (!data->sync_event)
+        data->sync_event = CreateEventW( NULL, TRUE, FALSE, NULL );
+    return data->sync_event;
+}
+
 /***********************************************************************
  *		DllMain (WS2_32.init)
  */
@@ -2339,19 +2351,15 @@ SOCKET WINAPI WS_accept( SOCKET s, struct WS_sockaddr *addr, int *len )
 
     TRACE("%#lx\n", s);
 
-    if (!(sync_event = CreateEventW( NULL, TRUE, FALSE, NULL ))) return INVALID_SOCKET;
+    if (!(sync_event = get_sync_event())) return INVALID_SOCKET;
     status = NtDeviceIoControlFile( SOCKET2HANDLE(s), (HANDLE)((ULONG_PTR)sync_event | 0), NULL, NULL, &io,
                                     IOCTL_AFD_WINE_ACCEPT, NULL, 0, &accept_handle, sizeof(accept_handle) );
     if (status == STATUS_PENDING)
     {
         if (WaitForSingleObject( sync_event, INFINITE ) == WAIT_FAILED)
-        {
-            CloseHandle( sync_event );
             return SOCKET_ERROR;
-        }
         status = io.u.Status;
     }
-    CloseHandle( sync_event );
     if (status)
     {
         WARN("failed; status %#x\n", status);
diff --git a/dlls/ws2_32/ws2_32_private.h b/dlls/ws2_32/ws2_32_private.h
index e86a3569510..527dbe903b4 100644
--- a/dlls/ws2_32/ws2_32_private.h
+++ b/dlls/ws2_32/ws2_32_private.h
@@ -181,6 +181,7 @@ UINT sock_get_error( int err ) DECLSPEC_HIDDEN;
 
 struct per_thread_data
 {
+    HANDLE sync_event; /* event to wait on for synchronous ioctls */
     int opentype;
     struct WS_hostent *he_buffer;
     struct WS_servent *se_buffer;




More information about the wine-cvs mailing list