[libsoup] connection: move reusable handling to message io implementation



commit 0b7d913d95fb7a72223a5de2e1752d5f8443582f
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Fri May 21 11:32:23 2021 +0200

    connection: move reusable handling to message io implementation

 libsoup/http1/soup-client-message-io-http1.c |  9 +++++----
 libsoup/soup-connection.c                    | 29 ++++------------------------
 libsoup/soup-connection.h                    |  3 ---
 libsoup/soup-session.c                       | 10 ++--------
 4 files changed, 11 insertions(+), 40 deletions(-)
---
diff --git a/libsoup/http1/soup-client-message-io-http1.c b/libsoup/http1/soup-client-message-io-http1.c
index 6a74318b..dec32106 100644
--- a/libsoup/http1/soup-client-message-io-http1.c
+++ b/libsoup/http1/soup-client-message-io-http1.c
@@ -50,6 +50,7 @@ typedef struct {
         GOutputStream *ostream;
 
         SoupMessageIOHTTP1 *msg_io;
+        gboolean is_reusable;
 } SoupClientMessageIOHTTP1;
 
 #define RESPONSE_BLOCK_SIZE 8192
@@ -651,6 +652,7 @@ io_read (SoupClientMessageIOHTTP1 *client_io,
         case SOUP_MESSAGE_IO_STATE_BODY_DONE:
                 io->read_state = SOUP_MESSAGE_IO_STATE_FINISHING;
                 soup_message_set_metrics_timestamp (msg, SOUP_MESSAGE_METRICS_RESPONSE_END);
+                client_io->is_reusable = soup_message_is_keepalive (msg);
                 soup_message_got_body (msg);
                 break;
 
@@ -1032,6 +1034,7 @@ soup_client_message_io_http1_send_item (SoupClientMessageIO       *iface,
 #endif
 
         io->msg_io = msg_io;
+        io->is_reusable = FALSE;
 }
 
 static void
@@ -1112,10 +1115,7 @@ soup_client_message_io_http1_is_reusable (SoupClientMessageIO *iface)
 {
         SoupClientMessageIOHTTP1 *io = (SoupClientMessageIOHTTP1 *)iface;
 
-        if (!io->msg_io)
-                return TRUE;
-
-        return soup_message_is_keepalive (io->msg_io->item->msg);
+        return io->is_reusable;
 }
 
 static const SoupClientMessageIOFuncs io_funcs = {
@@ -1145,6 +1145,7 @@ soup_client_message_io_http1_new (GIOStream *stream)
         io->iostream = g_object_ref (stream);
         io->istream = g_io_stream_get_input_stream (io->iostream);
         io->ostream = g_io_stream_get_output_stream (io->iostream);
+        io->is_reusable = TRUE;
 
         io->iface.funcs = &io_funcs;
 
diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c
index d3925fba..47fea4a5 100644
--- a/libsoup/soup-connection.c
+++ b/libsoup/soup-connection.c
@@ -41,7 +41,6 @@ typedef struct {
        time_t       unused_timeout;
        GSource     *idle_timeout_src;
         guint        in_use;
-       gboolean     reusable;
         SoupHTTPVersion http_version;
 
        GCancellable *cancellable;
@@ -378,8 +377,6 @@ current_msg_got_body (SoupMessage *msg, gpointer user_data)
                /* We're now effectively no longer proxying */
                g_clear_pointer (&priv->proxy_uri, g_uri_unref);
        }
-
-       priv->reusable = soup_client_message_io_is_reusable (priv->io_data);
 }
 
 static void
@@ -402,18 +399,14 @@ set_current_msg (SoupConnection *conn, SoupMessage *msg)
 
        g_return_if_fail (priv->state == SOUP_CONNECTION_IN_USE);
 
-        /* With HTTP/1.x we keep track of the current message both for
-         * proxying and to find out later if the connection is reusable
-         * with keep-alive. With HTTP/2 we don't support proxying and
-         * we assume its reusable by default and detect a closed connection
-         * elsewhere */
+        /* With HTTP/1.x we keep track of the current message for proxying.
+         * With HTTP/2 we don't support proxying. */
         switch (priv->http_version) {
         case SOUP_HTTP_1_0:
         case SOUP_HTTP_1_1:
                 break;
         case SOUP_HTTP_2_0:
                 // FIXME: stop_idle_timer() needs to be handled
-                priv->reusable = TRUE;
                 return;
         }
 
@@ -427,7 +420,6 @@ set_current_msg (SoupConnection *conn, SoupMessage *msg)
        stop_idle_timer (priv);
 
        priv->current_msg = g_object_ref (msg);
-       priv->reusable = FALSE;
 
        g_signal_connect (msg, "got-body",
                          G_CALLBACK (current_msg_got_body), conn);
@@ -1078,23 +1070,12 @@ soup_connection_set_in_use (SoupConnection *conn,
         if (priv->current_msg)
                 clear_current_msg (conn);
 
-        if (priv->reusable)
+        if (soup_connection_is_reusable (conn))
                 soup_connection_set_state (conn, SOUP_CONNECTION_IDLE);
         else
                 soup_connection_disconnect (conn);
 }
 
-void
-soup_connection_set_reusable (SoupConnection *conn,
-                              gboolean        reusable)
-{
-        SoupConnectionPrivate *priv = soup_connection_get_instance_private (conn);
-
-        g_return_if_fail (SOUP_IS_CONNECTION (conn));
-
-        priv->reusable = TRUE;
-}
-
 gboolean
 soup_connection_get_ever_used (SoupConnection *conn)
 {
@@ -1116,8 +1097,6 @@ soup_connection_setup_message_io (SoupConnection *conn,
 
         if (priv->current_msg != msg)
                 set_current_msg (conn, msg);
-        else
-                priv->reusable = FALSE;
 
         if (!soup_client_message_io_is_reusable (priv->io_data)) {
                 g_clear_pointer (&priv->io_data, soup_client_message_io_destroy);
@@ -1186,5 +1165,5 @@ soup_connection_is_reusable (SoupConnection *conn)
 {
         SoupConnectionPrivate *priv = soup_connection_get_instance_private (conn);
 
-        return priv->reusable;
+        return priv->io_data && soup_client_message_io_is_reusable (priv->io_data);
 }
diff --git a/libsoup/soup-connection.h b/libsoup/soup-connection.h
index 4f7c7d14..8428e67d 100644
--- a/libsoup/soup-connection.h
+++ b/libsoup/soup-connection.h
@@ -59,9 +59,6 @@ SoupConnectionState soup_connection_get_state  (SoupConnection   *conn);
 void            soup_connection_set_in_use     (SoupConnection   *conn,
                                                 gboolean          in_use);
 gboolean        soup_connection_is_idle_open   (SoupConnection   *conn);
-void            soup_connection_set_reusable   (SoupConnection   *conn,
-                                                gboolean          reusable);
-
 gboolean        soup_connection_get_ever_used  (SoupConnection   *conn);
 
 SoupClientMessageIO *soup_connection_setup_message_io    (SoupConnection *conn,
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index f2ac9876..32d3ec04 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -3889,16 +3889,10 @@ preconnect_async_complete (SoupMessage *msg,
 {
         SoupMessageQueueItem *item = g_task_get_task_data (task);
 
-        if (item->error) {
+        if (item->error)
                 g_task_return_error (task, g_error_copy (item->error));
-        } else {
-                SoupConnection *conn;
-
-                conn = soup_message_get_connection (item->msg);
-                if (conn)
-                        soup_connection_set_reusable (conn, TRUE);
+        else
                 g_task_return_boolean (task, TRUE);
-        }
         g_object_unref (task);
 }
 


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