changeset 31145:cc282e31e5c8

merge of '50243dd37132d4ae636e94f587bf6a41617ccd0d' and 'e6af6508a94951bfea63caba1fc4f85932cea3a3'
author Paul Aurich <paul@darkrain42.org>
date Wed, 12 Jan 2011 14:32:20 +0000
parents 7986f4e5a05f (diff) 3b8e763fb133 (current diff)
children 2c29fe4757a2
files
diffstat 1 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/bosh.c	Tue Jan 11 05:24:33 2011 +0000
+++ b/libpurple/protocols/jabber/bosh.c	Wed Jan 12 14:32:20 2011 +0000
@@ -306,7 +306,18 @@
 			return NULL;
 	}
 
-	/* Third loop, look for one that's NULL and create a new connection */
+	/* Third loop, is something offline that we can connect? */
+	for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) {
+		if (conn->connections[i] &&
+				conn->connections[i]->state == HTTP_CONN_OFFLINE) {
+			purple_debug_info("jabber", "bosh: Reconnecting httpconn "
+			                            "(%i, %p)\n", i, conn->connections[i]);
+			http_connection_connect(conn->connections[i]);
+			return NULL;
+		}
+	}
+
+	/* Fourth loop, look for one that's NULL and create a new connection */
 	for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) {
 		if (!conn->connections[i]) {
 			conn->connections[i] = jabber_bosh_http_connection_init(conn);
@@ -674,6 +685,7 @@
 
 static void http_connection_disconnected(PurpleHTTPConnection *conn)
 {
+	gboolean had_requests = FALSE;
 	/*
 	 * Well, then. Fine! I never liked you anyway, server! I was cheating on you
 	 * with AIM!
@@ -697,7 +709,8 @@
 		conn->writeh = 0;
 	}
 
-	if (conn->requests > 0 && conn->read_buf->len == 0) {
+	had_requests = (conn->requests > 0);
+	if (had_requests && conn->read_buf->len == 0) {
 		purple_debug_error("jabber", "bosh: Adjusting BOSHconn requests (%d) to %d\n",
 		                   conn->bosh->requests, conn->bosh->requests - conn->requests);
 		conn->bosh->requests -= conn->requests;
@@ -709,6 +722,12 @@
 		jabber_bosh_disable_pipelining(conn->bosh);
 	}
 
+	if (!had_requests)
+		/* If the server disconnected us without any requests, let's
+		 * just wait until we have something to send before we reconnect
+		 */
+		return;
+
 	if (++conn->bosh->failed_connections == MAX_FAILED_CONNECTIONS) {
 		purple_connection_error_reason(conn->bosh->js->gc,
 				PURPLE_CONNECTION_ERROR_NETWORK_ERROR,