pidgin: 1e866e4a: jabber: Better inactivity timer logic.

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sun Aug 2 01:40:45 EDT 2009


-----------------------------------------------------------------
Revision: 1e866e4a2cdda6a142af03546517d09500ce7176
Ancestor: 60067e3aed3e464ae90ea34b5aba54e7f8ae065f
Author: darkrain42 at pidgin.im
Date: 2009-08-01T04:24:39
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/1e866e4a2cdda6a142af03546517d09500ce7176

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

ChangeLog: 

jabber: Better inactivity timer logic.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c	040a1918c4df2b2b8f7846e26d8a5e6e65519c19
+++ libpurple/protocols/jabber/bosh.c	6c36dc9311eb247c7d60e5ae3298ff2601f9e440
@@ -400,6 +400,21 @@ bosh_inactivity_cb(gpointer data)
 	return TRUE;
 }
 
+static void
+restart_inactivity_timer(PurpleBOSHConnection *conn)
+{
+	if (conn->inactivity_timer != 0) {
+		purple_timeout_remove(conn->inactivity_timer);
+		conn->inactivity_timer = 0;
+	}
+
+	if (conn->max_inactivity != 0) {
+		conn->inactivity_timer =
+			purple_timeout_add_seconds(conn->max_inactivity - 5 /* rounding */,
+			                           bosh_inactivity_cb, conn);
+	}
+}
+
 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) {
 	xmlnode *child;
 	JabberStream *js = conn->js;
@@ -500,12 +515,12 @@ static void boot_response_cb(PurpleBOSHC
 			conn->max_inactivity = 0;
 		} else {
 			/* TODO: Integrate this with jabber.c keepalive checks... */
+			/* TODO: Can this check fail? It shouldn't */
 			if (conn->inactivity_timer == 0) {
-				purple_debug_misc("jabber", "Starting BOSH inactivity timer for %d secs (compensating for rounding)\n",
+				purple_debug_misc("jabber", "Starting BOSH inactivity timer "
+						"for %d secs (compensating for rounding)\n",
 						conn->max_inactivity - 5);
-				conn->inactivity_timer = purple_timeout_add_seconds(
-						conn->max_inactivity - 5 /* rounding */,
-						bosh_inactivity_cb, conn);
+				restart_inactivity_timer(conn);
 			}
 		}
 	}
@@ -919,6 +934,9 @@ http_connection_send_request(PurpleHTTPC
 	int ret;
 	size_t len;
 
+	/* Sending something to the server, restart the inactivity timer */
+	restart_inactivity_timer(conn->bosh);
+
 	data = g_strdup_printf("POST %s HTTP/1.1\r\n"
 	                       "Host: %s\r\n"
 	                       "User-Agent: %s\r\n"


More information about the Commits mailing list