changeset 26273:79ca1cf55d9d

Because BOSH works over connections that may die non-fatally, we need to limit the number of failed re-connection attempts before we declare the session lost. Reset the failures each time we process a full read from the server, which is a little hacky, but indicates that we have a *working* connection.
author Paul Aurich <paul@darkrain42.org>
date Mon, 23 Mar 2009 00:47:46 +0000
parents fcee93c74230
children 047e57f88431
files libpurple/protocols/jabber/bosh.c
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/bosh.c	Mon Mar 23 00:38:20 2009 +0000
+++ b/libpurple/protocols/jabber/bosh.c	Mon Mar 23 00:47:46 2009 +0000
@@ -30,6 +30,7 @@
 #include "bosh.h"
 
 #define MAX_HTTP_CONNECTIONS      2
+#define MAX_FAILED_CONNECTIONS    3
 
 typedef struct _PurpleHTTPConnection PurpleHTTPConnection;
 
@@ -48,6 +49,7 @@
 	JabberStream *js;
 	gboolean pipelining;
 	PurpleHTTPConnection *connections[MAX_HTTP_CONNECTIONS];
+	unsigned short failed_connections;
 
 	gboolean ready;
 	gboolean ssl;
@@ -430,6 +432,10 @@
 static void
 http_received_cb(const char *data, int len, PurpleBOSHConnection *conn)
 {
+	if (conn->failed_connections)
+		/* We've got some data, so reset the number of failed connections */
+		conn->failed_connections = 0;
+
 	if (conn->receive_cb) {
 		xmlnode *node = xmlnode_from_str(data, len);
 		if (node) {
@@ -602,8 +608,14 @@
 		/* Hmmmm, fall back to multiple connections */
 		conn->bosh->pipelining = FALSE;
 
-	/* No! Please! Take me back. It was me, not you! I was weak! */
-	http_connection_connect(conn);
+	if (++conn->bosh->failed_connections == MAX_FAILED_CONNECTIONS) {
+		purple_connection_error_reason(conn->bosh->js->gc,
+				PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+				_("Unable to establish a connection with the server"));
+	} else {
+		/* No! Please! Take me back. It was me, not you! I was weak! */
+		http_connection_connect(conn);
+	}
 }
 
 void jabber_bosh_connection_connect(PurpleBOSHConnection *bosh) {
@@ -711,6 +723,7 @@
 		/* Process what we do have */
 	}
 
+
 	jabber_bosh_http_connection_process(conn);
 }