[glib/backport-2449-2600-mingw-test-fixes-glib-2-72: 2/2] gio/tests: fix socket /socket/credentials/unix_socketpair on win32




commit 25616eb7ee4f38f7208966cbccf188e5f4ada923
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Wed Mar 23 19:12:59 2022 +0400

    gio/tests: fix socket /socket/credentials/unix_socketpair on win32
    
    When I enabled unix socketpair test on win32, I left the existing
    g_close(fds[1]), but _g_win32_socketpair() returns native sockets
    descriptors that must be closed with closesocket() on win32.
    
    Let GSocket handle the socket pair cleanup.
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 gio/tests/socket.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gio/tests/socket.c b/gio/tests/socket.c
index a8bab16df9..4dae36b175 100644
--- a/gio/tests/socket.c
+++ b/gio/tests/socket.c
@@ -2241,7 +2241,7 @@ test_credentials_unix_socketpair (void)
 {
   gint fds[2];
   gint status;
-  GSocket *sock;
+  GSocket *sock[2];
   GError *error = NULL;
   GCredentials *creds;
 
@@ -2257,9 +2257,12 @@ test_credentials_unix_socketpair (void)
 #endif
   g_assert_cmpint (status, ==, 0);
 
-  sock = g_socket_new_from_fd (fds[0], &error);
+  sock[0] = g_socket_new_from_fd (fds[0], &error);
+  g_assert_no_error (error);
+  sock[1] = g_socket_new_from_fd (fds[1], &error);
+  g_assert_no_error (error);
 
-  creds = g_socket_get_credentials (sock, &error);
+  creds = g_socket_get_credentials (sock[0], &error);
   if (creds != NULL)
     {
       gchar *str = g_credentials_to_string (creds);
@@ -2274,8 +2277,8 @@ test_credentials_unix_socketpair (void)
       g_clear_error (&error);
     }
 
-  g_object_unref (sock);
-  g_close (fds[1], NULL);
+  g_object_unref (sock[0]);
+  g_object_unref (sock[1]);
 }
 #endif
 


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