From f150de213989639da3f8cfd7d5760ab4060df410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Mon, 11 Feb 2019 23:44:55 +0000 Subject: [PATCH] socket test: Bind Windows UDP sockets before calling recv() Winsock can't recv() on unbound UDP sockets. Bind the socket to loopback before trying to receive data on it. --- gio/tests/socket.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gio/tests/socket.c b/gio/tests/socket.c index 064202d11..a3f3c43cb 100644 --- a/gio/tests/socket.c +++ b/gio/tests/socket.c @@ -829,6 +829,10 @@ test_ip_sync_dgram_timeouts (GSocketFamily family) GCancellable *cancellable = NULL; GThread *cancellable_thread = NULL; gssize len; +#ifdef G_OS_WIN32 + GInetAddress *iaddr; + GSocketAddress *addr; +#endif client = g_socket_new (family, G_SOCKET_TYPE_DATAGRAM, @@ -840,6 +844,16 @@ test_ip_sync_dgram_timeouts (GSocketFamily family) g_assert_cmpint (g_socket_get_socket_type (client), ==, G_SOCKET_TYPE_DATAGRAM); g_assert_cmpint (g_socket_get_protocol (client), ==, G_SOCKET_PROTOCOL_DEFAULT); +#ifdef G_OS_WIN32 + /* Winsock can't recv() on unbound udp socket */ + iaddr = g_inet_address_new_loopback (family); + addr = g_inet_socket_address_new (iaddr, 0); + g_object_unref (iaddr); + g_socket_bind (client, addr, TRUE, &error); + g_object_unref (addr); + g_assert_no_error (error); +#endif + /* No overall timeout: test the per-operation timeouts instead. */ g_socket_set_timeout (client, 0);