[glib: 1/2] gio/tests: DuplicateHandle() is inappropriate for SOCKET




commit 2a925f273b4b79e81ee7346e334b1554c2b372e8
Author: Marc-André Lureau <marcandre lureau gmail com>
Date:   Thu Apr 7 11:22:55 2022 +0000

    gio/tests: DuplicateHandle() is inappropriate for SOCKET

 gio/tests/socket.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/gio/tests/socket.c b/gio/tests/socket.c
index d1aa3ec45e..747ddfd1f6 100644
--- a/gio/tests/socket.c
+++ b/gio/tests/socket.c
@@ -1187,23 +1187,25 @@ test_timed_wait (void)
 }
 
 static int
-duplicate_fd (int fd)
+duplicate_socket_fd (int fd)
 {
 #ifdef G_OS_WIN32
-  HANDLE newfd;
-
-  if (!DuplicateHandle (GetCurrentProcess (),
-                        (HANDLE)fd,
-                        GetCurrentProcess (),
-                        &newfd,
-                        0,
-                        FALSE,
-                        DUPLICATE_SAME_ACCESS))
+  WSAPROTOCOL_INFO info;
+
+  if (WSADuplicateSocket ((SOCKET)fd,
+                          GetCurrentProcessId (),
+                          &info))
     {
+      gchar *emsg = g_win32_error_message (WSAGetLastError ());
+      g_test_message ("Error duplicating socket: %s", emsg);
+      g_free (emsg);
       return -1;
     }
 
-  return (int)(gintptr)newfd;
+  return (int)WSASocket (FROM_PROTOCOL_INFO,
+                         FROM_PROTOCOL_INFO,
+                         FROM_PROTOCOL_INFO,
+                         &info, 0, 0);
 #else
   return dup (fd);
 #endif
@@ -1249,7 +1251,7 @@ test_fd_reuse (void)
   g_object_unref (addr);
 
   /* we have to dup otherwise the fd gets closed twice on unref */
-  fd = duplicate_fd (g_socket_get_fd (client));
+  fd = duplicate_socket_fd (g_socket_get_fd (client));
   client2 = g_socket_new_from_fd (fd, &error);
   g_assert_no_error (error);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]