[libsoup] SoupSession: move all connection tracking into the base class



commit 95396a8b447160781f7db8b5ab9bb4bb95fad32b
Author: Dan Winship <danw gnome org>
Date:   Tue Aug 14 20:57:00 2012 -0400

    SoupSession: move all connection tracking into the base class
    
    Since SoupConnection:state is more reliable now, SoupSession can keep
    track of when connections are available itself, rather than the
    subclasses trying to guess when connections are available.

 libsoup/soup-session-async.c |   19 +++----------------
 libsoup/soup-session-sync.c  |    3 ---
 libsoup/soup-session.c       |   15 +++++++++++++++
 3 files changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/libsoup/soup-session-async.c b/libsoup/soup-session-async.c
index 90534e3..46dac50 100644
--- a/libsoup/soup-session-async.c
+++ b/libsoup/soup-session-async.c
@@ -106,15 +106,6 @@ soup_session_async_new_with_options (const char *optname1, ...)
 }
 
 static void
-connection_closed (SoupConnection *conn, gpointer session)
-{
-	/* Run the queue in case anyone was waiting for a connection
-	 * to be closed.
-	 */
-	do_idle_run_queue (session);
-}
-
-static void
 message_completed (SoupMessage *msg, gpointer user_data)
 {
 	SoupMessageQueueItem *item = user_data;
@@ -148,11 +139,9 @@ ssl_tunnel_completed (SoupConnection *conn, guint status, gpointer user_data)
 	SoupMessageQueueItem *tunnel_item = user_data;
 	SoupMessageQueueItem *item = tunnel_item->related;
 
-	if (SOUP_STATUS_IS_SUCCESSFUL (status)) {
-		g_signal_connect (item->conn, "disconnected",
-				  G_CALLBACK (connection_closed), item->session);
+	if (SOUP_STATUS_IS_SUCCESSFUL (status))
 		item->state = SOUP_MESSAGE_READY;
-	} else {
+	else {
 		if (item->conn)
 			soup_connection_disconnect (item->conn);
 		soup_message_set_status (item->msg, SOUP_STATUS_SSL_FAILED);
@@ -243,8 +232,6 @@ got_connection (SoupConnection *conn, guint status, gpointer user_data)
 	}
 
 	item->state = SOUP_MESSAGE_READY;
-	g_signal_connect (conn, "disconnected",
-			  G_CALLBACK (connection_closed), session);
 	run_queue ((SoupSessionAsync *)session);
 	soup_message_queue_item_unref (item);
 }
@@ -309,7 +296,7 @@ process_queue_item (SoupMessageQueueItem *item,
 				item->callback (session, item->msg, item->callback_data);
 			else if (item->new_api)
 				send_request_finished (session, item);
-			do_idle_run_queue (session);
+
 			soup_message_queue_item_unref (item);
 			return;
 
diff --git a/libsoup/soup-session-sync.c b/libsoup/soup-session-sync.c
index 81410c5..987d55d 100644
--- a/libsoup/soup-session-sync.c
+++ b/libsoup/soup-session-sync.c
@@ -277,7 +277,6 @@ process_queue_item (SoupMessageQueueItem *item)
 			item->state = SOUP_MESSAGE_FINISHED;
 			soup_message_finished (item->msg);
 			soup_session_unqueue_item (session, item);
-			g_cond_broadcast (&priv->cond);
 			break;
 
 		default:
@@ -421,9 +420,7 @@ soup_session_sync_kick (SoupSession *session)
 {
 	SoupSessionSyncPrivate *priv = SOUP_SESSION_SYNC_GET_PRIVATE (session);
 
-	g_mutex_lock (&priv->lock);
 	g_cond_broadcast (&priv->cond);
-	g_mutex_unlock (&priv->lock);
 }
 
 static void
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 865897e..c337c57 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -1167,6 +1167,18 @@ connection_disconnected (SoupConnection *conn, gpointer user_data)
 
 	g_mutex_unlock (&priv->conn_lock);
 	g_object_unref (conn);
+
+	SOUP_SESSION_GET_CLASS (session)->kick (session);
+}
+
+static void
+connection_state_changed (GObject *object, GParamSpec *param, gpointer user_data)
+{
+	SoupSession *session = user_data;
+	SoupConnection *conn = SOUP_CONNECTION (object);
+
+	if (soup_connection_get_state (conn) == SOUP_CONNECTION_IDLE)
+		SOUP_SESSION_GET_CLASS (session)->kick (session);
 }
 
 SoupMessageQueueItem *
@@ -1263,6 +1275,9 @@ soup_session_get_connection (SoupSession *session,
 	g_signal_connect (conn, "disconnected",
 			  G_CALLBACK (connection_disconnected),
 			  session);
+	g_signal_connect (conn, "notify::state",
+			  G_CALLBACK (connection_state_changed),
+			  session);
 
 	g_signal_emit (session, signals[CONNECTION_CREATED], 0, conn);
 



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