# HG changeset patch # User Paul Aurich # Date 1294842712 0 # Node ID 7986f4e5a05ffdddd3521a7ac72bc9e5b128ddfa # Parent 365ec0996ca091f59e963cd0221d264d68a4ea65 jabber: Be friendlier to servers when we have nothing to say. Don't try to reconnect immediately, but do so when we have something to send. Untested (I'll test it later), but I'm hoping hsitas444 will test it first. Refs #13008. diff -r 365ec0996ca0 -r 7986f4e5a05f libpurple/protocols/jabber/bosh.c --- a/libpurple/protocols/jabber/bosh.c Mon Jan 10 05:20:06 2011 +0000 +++ b/libpurple/protocols/jabber/bosh.c Wed Jan 12 14:31:52 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,