[libsoup/http2] move cleanup/abort code from session to host



commit dc6840d4e6ccabd93c7d7a086a2b413811c82242
Author: Dan Winship <danw gnome org>
Date:   Tue Dec 10 12:18:37 2013 +0100

    move cleanup/abort code from session to host

 libsoup/soup-session-host.c |   53 +++++++++++++++++++++++++++++++
 libsoup/soup-session-host.h |    5 +++
 libsoup/soup-session.c      |   72 +++++++++++++++---------------------------
 3 files changed, 84 insertions(+), 46 deletions(-)
---
diff --git a/libsoup/soup-session-host.c b/libsoup/soup-session-host.c
index e959ddc..5645ca4 100644
--- a/libsoup/soup-session-host.c
+++ b/libsoup/soup-session-host.c
@@ -274,6 +274,59 @@ soup_session_host_get_connections (SoupSessionHost *host)
 }
 
 gboolean
+soup_session_host_cleanup_connections (SoupSessionHost *host,
+                                      gboolean         cleanup_idle)
+{
+       SoupSessionHostPrivate *priv = SOUP_SESSION_HOST_GET_PRIVATE (host);
+       GSList *conns, *c, *next;
+       SoupConnection *conn;
+       SoupConnectionState state;
+
+       g_mutex_lock (&priv->mutex);
+       conns = NULL;
+       for (c = priv->connections; c; c = next) {
+               conn = c->data;
+               next = c->next;
+
+               state = soup_connection_get_state (conn);
+               if (state == SOUP_CONNECTION_REMOTE_DISCONNECTED ||
+                   (cleanup_idle && state == SOUP_CONNECTION_IDLE)) {
+                       conns = g_slist_remove (conns, conn);
+                       conns = g_slist_prepend (conns, g_object_ref (conn));
+               }
+       }
+       g_mutex_unlock (&priv->mutex);
+
+       if (!conns)
+               return FALSE;
+
+       for (c = conns; c; c = c->next) {
+               conn = c->data;
+               soup_connection_disconnect (conn);
+               g_object_unref (conn);
+       }
+       g_slist_free (conns);
+
+       return TRUE;
+}
+
+void
+soup_session_host_abort (SoupSessionHost *host)
+{
+       SoupSessionHostPrivate *priv = SOUP_SESSION_HOST_GET_PRIVATE (host);
+       GSList *conns, *c;
+
+       g_mutex_lock (&priv->mutex);
+       conns = priv->connections;
+       priv->connections = NULL;
+       g_mutex_unlock (&priv->mutex);
+
+       for (c = conns; c; c = c->next)
+               soup_connection_disconnect (c->data);
+       g_slist_free (conns);
+}
+
+gboolean
 soup_session_host_get_ssl_fallback (SoupSessionHost *host)
 {
        return SOUP_SESSION_HOST_GET_PRIVATE (host)->ssl_fallback;
diff --git a/libsoup/soup-session-host.h b/libsoup/soup-session-host.h
index 4f27b50..4e5694d 100644
--- a/libsoup/soup-session-host.h
+++ b/libsoup/soup-session-host.h
@@ -47,6 +47,11 @@ SoupConnection  *soup_session_host_get_connection      (SoupSessionHost      *ho
 int              soup_session_host_get_num_connections (SoupSessionHost      *host);
 GSList          *soup_session_host_get_connections     (SoupSessionHost      *host);
 
+gboolean         soup_session_host_cleanup_connections (SoupSessionHost      *host,
+                                                       gboolean              cleanup_idle);
+
+void             soup_session_host_abort               (SoupSessionHost      *host);
+
 gboolean         soup_session_host_get_ssl_fallback    (SoupSessionHost      *host);
 void             soup_session_host_set_ssl_fallback    (SoupSessionHost      *host,
                                                        gboolean              ssl_fallback);
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 1f4db04..5c38222 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -1241,25 +1241,21 @@ soup_session_send_queue_item (SoupSession *session,
 
 /* Requires conn_lock to be locked */
 static GSList *
-get_all_connections (SoupSession *session)
+get_all_hosts (SoupSession *session)
 {
        SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
-       GSList *conns = NULL, *host_conns;
+       GSList *hosts = NULL;
        GHashTableIter iter;
        gpointer host;
 
        g_hash_table_iter_init (&iter, priv->http_hosts);
-       while (g_hash_table_iter_next (&iter, NULL, &host)) {
-               host_conns = soup_session_host_get_connections (host);
-               conns = g_slist_concat (host_conns, conns);
-       }
+       while (g_hash_table_iter_next (&iter, NULL, &host))
+               hosts = g_slist_prepend (hosts, g_object_ref (host));
        g_hash_table_iter_init (&iter, priv->https_hosts);
-       while (g_hash_table_iter_next (&iter, NULL, &host)) {
-               host_conns = soup_session_host_get_connections (host);
-               conns = g_slist_concat (host_conns, conns);
-       }
+       while (g_hash_table_iter_next (&iter, NULL, &host))
+               hosts = g_slist_prepend (hosts, g_object_ref (host));
 
-       return conns;
+       return hosts;
 }
 
 static gboolean
@@ -1267,38 +1263,23 @@ soup_session_cleanup_connections (SoupSession *session,
                                  gboolean     cleanup_idle)
 {
        SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
-       GSList *conns, *disconnect_conns, *c;
-       SoupConnection *conn;
-       SoupConnectionState state;
+       GSList *hosts, *h;
+       SoupSessionHost *host;
+       gboolean cleaned_any = FALSE;
 
        g_mutex_lock (&priv->conn_lock);
-
-       conns = get_all_connections (session);
-       disconnect_conns = NULL;
-       for (c = conns; c; c = c->next) {
-               conn = c->data;
-               state = soup_connection_get_state (conn);
-               if (state == SOUP_CONNECTION_REMOTE_DISCONNECTED ||
-                   (cleanup_idle && state == SOUP_CONNECTION_IDLE)) {
-                       disconnect_conns = g_slist_prepend (disconnect_conns, conn);
-                       drop_connection (session, conn);
-               } else
-                       g_object_unref (conn);
-       }
-       g_slist_free (conns);
+       hosts = get_all_hosts (session);
        g_mutex_unlock (&priv->conn_lock);
 
-       if (!disconnect_conns)
-               return FALSE;
-
-       for (c = disconnect_conns; c; c = c->next) {
-               conn = c->data;
-               soup_connection_disconnect (conn);
-               g_object_unref (conn);
+       for (h = hosts; h; h = h->next) {
+               host = h->data;
+               if (soup_session_host_cleanup_connections (host, cleanup_idle))
+                       cleaned_any = TRUE;
+               g_object_unref (host);
        }
-       g_slist_free (disconnect_conns);
+       g_slist_free (hosts);
 
-       return TRUE;
+       return cleaned_any;
 }
 
 static void
@@ -2350,7 +2331,8 @@ void
 soup_session_abort (SoupSession *session)
 {
        SoupSessionPrivate *priv;
-       GSList *conns, *c;
+       GSList *hosts, *h;
+       SoupSessionHost *host;
 
        g_return_if_fail (SOUP_IS_SESSION (session));
        priv = SOUP_SESSION_GET_PRIVATE (session);
@@ -2359,17 +2341,15 @@ soup_session_abort (SoupSession *session)
 
        /* Close all connections */
        g_mutex_lock (&priv->conn_lock);
-       conns = get_all_connections (session);
-       for (c = conns; c; c = c->next)
-               drop_connection (session, c->data);
+       hosts = get_all_hosts (session);
        g_mutex_unlock (&priv->conn_lock);
 
-       for (c = conns; c; c = c->next) {
-               soup_connection_disconnect (c->data);
-               g_object_unref (c->data);
+       for (h = hosts; h; h = h->next) {
+               host = h->data;
+               soup_session_host_abort (host);
+               g_object_unref (host);
        }
-
-       g_slist_free (conns);
+       g_slist_free (hosts);
 }
 
 static void


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