cpw.darkrain42.xmpp.bosh: 7c3876ac: Because BOSH works over connections that...

paul at darkrain42.org paul at darkrain42.org
Sun Mar 22 23:11:02 EDT 2009


-----------------------------------------------------------------
Revision: 7c3876acdd47b4677e42ac4d27e86bf1c72122b6
Ancestor: 25026f5a4434830bb15c2235e8a35f13d2de3157
Author: paul at darkrain42.org
Date: 2009-03-23T00:47:46
Branch: im.pidgin.cpw.darkrain42.xmpp.bosh
URL: http://d.pidgin.im/viewmtn/revision/info/7c3876acdd47b4677e42ac4d27e86bf1c72122b6

Modified files:
        libpurple/protocols/jabber/bosh.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c	2cf283725fc1ed33c357c869d9bb0ec05a830255
+++ libpurple/protocols/jabber/bosh.c	2ef839317154c9a20e2ede7f8faf4bb7f876ff20
@@ -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 @@ struct _PurpleBOSHConnection {
 	JabberStream *js;
 	gboolean pipelining;
 	PurpleHTTPConnection *connections[MAX_HTTP_CONNECTIONS];
+	unsigned short failed_connections;
 
 	gboolean ready;
 	gboolean ssl;
@@ -430,6 +432,10 @@ http_received_cb(const char *data, int l
 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 @@ static void http_connection_disconnected
 		/* 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 @@ http_connection_read(PurpleHTTPConnectio
 		/* Process what we do have */
 	}
 
+
 	jabber_bosh_http_connection_process(conn);
 }
 


More information about the Commits mailing list