[libsoup] Replace setsockopt() usage with g_socket_set_option()



commit 55d928b6cab01a96295e7d3da86942a3bfb29847
Author: Patrick Griffis <pgriffis igalia com>
Date:   Wed Mar 25 02:47:45 2020 -0700

    Replace setsockopt() usage with g_socket_set_option()

 libsoup/soup-server.c |  5 +++--
 libsoup/soup-socket.c | 14 ++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c
index 208b0086..8994ba66 100644
--- a/libsoup/soup-server.c
+++ b/libsoup/soup-server.c
@@ -1390,7 +1390,7 @@ soup_server_listen (SoupServer *server, GSocketAddress *address,
 {
        SoupServerPrivate *priv;
        SoupSocket *listener;
-       gboolean success;
+       gboolean success, ipv6_only;
 
        g_return_val_if_fail (SOUP_IS_SERVER (server), FALSE);
        g_return_val_if_fail (!(options & SOUP_SERVER_LISTEN_IPV4_ONLY) &&
@@ -1399,8 +1399,9 @@ soup_server_listen (SoupServer *server, GSocketAddress *address,
        priv = soup_server_get_instance_private (server);
        g_return_val_if_fail (priv->disposed == FALSE, FALSE);
 
+        ipv6_only = g_socket_address_get_family (address) == G_SOCKET_FAMILY_IPV6;
        listener = soup_socket_new (SOUP_SOCKET_LOCAL_ADDRESS, address,
-                                   SOUP_SOCKET_IPV6_ONLY, TRUE,
+                                   SOUP_SOCKET_IPV6_ONLY, ipv6_only,
                                    NULL);
 
        success = soup_server_listen_internal (server, listener, options, error);
diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c
index 2dead3c4..b7b41b5d 100644
--- a/libsoup/soup-socket.c
+++ b/libsoup/soup-socket.c
@@ -1209,16 +1209,14 @@ soup_socket_listen_full (SoupSocket *sock,
                goto cant_listen;
        finish_socket_setup (sock);
 
-#if defined (IPPROTO_IPV6) && defined (IPV6_V6ONLY)
        if (priv->ipv6_only) {
-               int fd, v6_only;
-
-               fd = g_socket_get_fd (priv->gsock);
-               v6_only = TRUE;
-               setsockopt (fd, IPPROTO_IPV6, IPV6_V6ONLY,
-                           &v6_only, sizeof (v6_only));
+                GError *error = NULL;
+                g_socket_set_option (priv->gsock, IPPROTO_IPV6, IPV6_V6ONLY, TRUE, &error);
+                if (error) {
+                        g_warning ("Failed to set IPv6 only on socket: %s", error->message);
+                        g_error_free (error);
+                }
        }
-#endif
 
        /* Bind */
        if (!g_socket_bind (priv->gsock, G_SOCKET_ADDRESS (priv->local_addr), TRUE, error))


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