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>
This commit is contained in:
Francesco Tamagni 2021-01-21 20:38:05 +01:00 committed by Ole André Vadla Ravnås
parent 3791add329
commit f6ce5739f8
2 changed files with 28 additions and 1 deletions

View File

@ -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)

View File

@ -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);