From 2a925f273b4b79e81ee7346e334b1554c2b372e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 7 Apr 2022 11:22:55 +0000 Subject: [PATCH] gio/tests: DuplicateHandle() is inappropriate for SOCKET --- gio/tests/socket.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/gio/tests/socket.c b/gio/tests/socket.c index d1aa3ec45..747ddfd1f 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; + WSAPROTOCOL_INFO info; - if (!DuplicateHandle (GetCurrentProcess (), - (HANDLE)fd, - GetCurrentProcess (), - &newfd, - 0, - FALSE, - DUPLICATE_SAME_ACCESS)) + 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);