[libsoup/carlosgc/server-http2: 3/13] server-message: remove socket, local_addr and remote_addr members




commit 798c44b7417fc4329790f00bf3b9a5d6633edf90
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Fri Jul 1 09:59:50 2022 +0200

    server-message: remove socket, local_addr and remote_addr members
    
    They can just be get from the connection.

 libsoup/server/soup-server-connection.c |  4 ++++
 libsoup/server/soup-server-message.c    | 41 +++++----------------------------
 2 files changed, 10 insertions(+), 35 deletions(-)
---
diff --git a/libsoup/server/soup-server-connection.c b/libsoup/server/soup-server-connection.c
index 8dbaad96..46d7727d 100644
--- a/libsoup/server/soup-server-connection.c
+++ b/libsoup/server/soup-server-connection.c
@@ -466,6 +466,10 @@ soup_server_connection_steal_socket (SoupServerConnection *conn)
 
         priv = soup_server_connection_get_instance_private (conn);
 
+        /* Cache local and remote address */
+        soup_server_connection_get_local_address (conn);
+        soup_server_connection_get_remote_address (conn);
+
         socket = g_steal_pointer (&priv->socket);
         g_clear_object (&priv->conn);
         g_clear_object (&priv->iostream);
diff --git a/libsoup/server/soup-server-message.c b/libsoup/server/soup-server-message.c
index c7943b78..5fe12ba6 100644
--- a/libsoup/server/soup-server-message.c
+++ b/libsoup/server/soup-server-message.c
@@ -38,13 +38,10 @@ struct _SoupServerMessage {
         GObject             parent;
 
         SoupServerConnection *conn;
-        GSocket            *gsock;
         SoupAuthDomain     *auth_domain;
         char               *auth_user;
 
-        GSocketAddress     *remote_addr;
         char               *remote_ip;
-        GSocketAddress     *local_addr;
 
         const char         *method;
         SoupHTTPVersion     http_version;
@@ -126,14 +123,11 @@ soup_server_message_finalize (GObject *object)
 
         g_clear_object (&msg->auth_domain);
         g_clear_pointer (&msg->auth_user, g_free);
-        g_clear_object (&msg->remote_addr);
-        g_clear_object (&msg->local_addr);
 
         if (msg->conn) {
                 g_signal_handlers_disconnect_by_data (msg->conn, msg);
                 g_object_unref (msg->conn);
         }
-        g_clear_object (&msg->gsock);
         g_clear_pointer (&msg->remote_ip, g_free);
 
         g_clear_pointer (&msg->uri, g_uri_unref);
@@ -451,9 +445,6 @@ soup_server_message_new (SoupServerConnection *conn)
 
         msg = g_object_new (SOUP_TYPE_SERVER_MESSAGE, NULL);
         msg->conn = g_object_ref (conn);
-        msg->gsock = soup_server_connection_get_socket (conn);
-        if (msg->gsock)
-                g_object_ref (msg->gsock);
 
         g_signal_connect_object (conn, "disconnected",
                                  G_CALLBACK (connection_disconnected),
@@ -929,7 +920,7 @@ soup_server_message_get_socket (SoupServerMessage *msg)
 {
         g_return_val_if_fail (SOUP_IS_SERVER_MESSAGE (msg), NULL);
 
-        return msg->gsock;
+        return soup_server_connection_get_socket (msg->conn);
 }
 
 /**
@@ -948,14 +939,7 @@ soup_server_message_get_remote_address (SoupServerMessage *msg)
 {
         g_return_val_if_fail (SOUP_IS_SERVER_MESSAGE (msg), NULL);
 
-        if (msg->remote_addr)
-                return msg->remote_addr;
-
-        msg->remote_addr = msg->gsock ?
-                g_socket_get_remote_address (msg->gsock, NULL) :
-                G_SOCKET_ADDRESS (g_object_ref (soup_server_connection_get_remote_address (msg->conn)));
-
-        return msg->remote_addr;
+        return soup_server_connection_get_remote_address (msg->conn);
 }
 
 /**
@@ -974,14 +958,7 @@ soup_server_message_get_local_address (SoupServerMessage *msg)
 {
         g_return_val_if_fail (SOUP_IS_SERVER_MESSAGE (msg), NULL);
 
-        if (msg->local_addr)
-                return msg->local_addr;
-
-        msg->local_addr = msg->gsock ?
-                g_socket_get_local_address (msg->gsock, NULL) :
-                G_SOCKET_ADDRESS (g_object_ref (soup_server_connection_get_local_address (msg->conn)));
-
-        return msg->local_addr;
+        return soup_server_connection_get_local_address (msg->conn);
 }
 
 /**
@@ -1000,21 +977,15 @@ soup_server_message_get_remote_host (SoupServerMessage *msg)
 {
         g_return_val_if_fail (SOUP_IS_SERVER_MESSAGE (msg), NULL);
 
-        if (msg->remote_ip)
-                return msg->remote_ip;
-
-        if (msg->gsock) {
-                GSocketAddress *addr = soup_server_message_get_remote_address (msg);
+        if (!msg->remote_ip) {
+                GSocketAddress *addr = soup_server_connection_get_remote_address (msg->conn);
                 GInetAddress *iaddr;
 
                 if (!addr || !G_IS_INET_SOCKET_ADDRESS (addr))
                         return NULL;
+
                 iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (addr));
                 msg->remote_ip = g_inet_address_to_string (iaddr);
-        } else {
-                GInetSocketAddress *addr = G_INET_SOCKET_ADDRESS (soup_server_connection_get_remote_address 
(msg->conn));
-                GInetAddress *inet_addr = g_inet_socket_address_get_address (addr);
-                msg->remote_ip = g_inet_address_to_string (inet_addr);
         }
 
         return msg->remote_ip;


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