Merge branch 'dup-socket' into 'main'

gio/tests: DuplicateHandle() is inappropriate for SOCKET

See merge request GNOME/glib!2592
This commit is contained in:
Philip Withnall 2022-04-07 11:22:55 +00:00
commit a7aa029a11

View File

@ -1187,23 +1187,25 @@ test_timed_wait (void)
} }
static int static int
duplicate_fd (int fd) duplicate_socket_fd (int fd)
{ {
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
HANDLE newfd; WSAPROTOCOL_INFO info;
if (!DuplicateHandle (GetCurrentProcess (), if (WSADuplicateSocket ((SOCKET)fd,
(HANDLE)fd, GetCurrentProcessId (),
GetCurrentProcess (), &info))
&newfd,
0,
FALSE,
DUPLICATE_SAME_ACCESS))
{ {
gchar *emsg = g_win32_error_message (WSAGetLastError ());
g_test_message ("Error duplicating socket: %s", emsg);
g_free (emsg);
return -1; return -1;
} }
return (int)(gintptr)newfd; return (int)WSASocket (FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO,
&info, 0, 0);
#else #else
return dup (fd); return dup (fd);
#endif #endif
@ -1249,7 +1251,7 @@ test_fd_reuse (void)
g_object_unref (addr); g_object_unref (addr);
/* we have to dup otherwise the fd gets closed twice on unref */ /* 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); client2 = g_socket_new_from_fd (fd, &error);
g_assert_no_error (error); g_assert_no_error (error);