[glib: 1/2] gsocket: Fix SO_NOSIGPIPE regression on Darwin




commit f6ce5739f877c69d51fb387ffe1da0c4e550b752
Author: Francesco Tamagni <mrmacete protonmail ch>
Date:   Thu Jan 21 20:38:05 2021 +0100

    gsocket: Fix SO_NOSIGPIPE regression on Darwin
    
    Where the early call to g_socket_set_option() fails because of
    check_socket() failing due to `inited` still being FALSE.
    
    This brings 634b692 back into working order, by fixing the regression
    introduced in 39f047e.
    
    Co-authored-by: Ole André Vadla Ravnås <oleavr gmail com>

 gio/gsocket.c      |  4 +++-
 gio/tests/socket.c | 25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
---
diff --git a/gio/gsocket.c b/gio/gsocket.c
index 52a198378..a4f363f25 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -6243,7 +6243,9 @@ g_socket_set_option (GSocket  *socket,
 
   g_return_val_if_fail (G_IS_SOCKET (socket), FALSE);
 
-  if (!check_socket (socket, error))
+  /* g_socket_set_option() is called during socket init, so skip the init checks
+   * in check_socket() */
+  if (socket->priv->inited && !check_socket (socket, error))
     return FALSE;
 
   if (setsockopt (socket->priv->fd, level, optname, &value, sizeof (gint)) == 0)
diff --git a/gio/tests/socket.c b/gio/tests/socket.c
index 683866ede..ee098c55f 100644
--- a/gio/tests/socket.c
+++ b/gio/tests/socket.c
@@ -1899,6 +1899,28 @@ test_read_write (gconstpointer user_data)
   g_object_unref (client);
 }
 
+#ifdef SO_NOSIGPIPE
+static void
+test_nosigpipe (void)
+{
+  GSocket *sock;
+  GError *error = NULL;
+  gint value;
+
+  sock = g_socket_new (AF_INET,
+                       G_SOCKET_TYPE_STREAM,
+                       G_SOCKET_PROTOCOL_DEFAULT,
+                       &error);
+  g_assert_no_error (error);
+
+  g_socket_get_option (sock, SOL_SOCKET, SO_NOSIGPIPE, &value, &error);
+  g_assert_no_error (error);
+  g_assert_true (value);
+
+  g_object_unref (sock);
+}
+#endif
+
 #if G_CREDENTIALS_SUPPORTED
 static gpointer client_setup_thread (gpointer user_data);
 
@@ -2165,6 +2187,9 @@ main (int   argc,
                         test_read_write);
   g_test_add_data_func ("/socket/read_writev", GUINT_TO_POINTER (TRUE),
                         test_read_write);
+#ifdef SO_NOSIGPIPE
+  g_test_add_func ("/socket/nosigpipe", test_nosigpipe);
+#endif
 #if G_CREDENTIALS_SUPPORTED
   g_test_add_func ("/socket/credentials/tcp_client", test_credentials_tcp_client);
   g_test_add_func ("/socket/credentials/tcp_server", test_credentials_tcp_server);


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