changeset 29492:0d3151a41134

jabber: Don't ping more often than once a minute. From rfc3920bis: The length of time between the use of any particular connection test is a matter of implementation and local service policy; however, it is RECOMMENDED that any such test be performed not more than once every 60 seconds.
author Paul Aurich <paul@darkrain42.org>
date Sat, 27 Feb 2010 03:49:32 +0000
parents fddded5ee514
children 7f7ce73365eb 93e8e6331d44
files libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h
diffstat 2 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Fri Feb 26 14:14:43 2010 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat Feb 27 03:49:32 2010 +0000
@@ -70,6 +70,8 @@
 #include "jingle/jingle.h"
 #include "jingle/rtp.h"
 
+#define PING_TIMEOUT 60
+
 GList *jabber_features = NULL;
 GList *jabber_identities = NULL;
 static GSList *jabber_cmds = NULL;
@@ -521,9 +523,12 @@
 
 void jabber_keepalive(PurpleConnection *gc)
 {
-	JabberStream *js = gc->proto_data;
-
-	if (js->keepalive_timeout == 0) {
+	JabberStream *js = purple_connection_get_protocol_data(gc);
+	time_t now = time(NULL);
+
+	if (js->keepalive_timeout == 0 && (now - js->last_ping) >= PING_TIMEOUT) {
+		js->last_ping = now;
+
 		jabber_keepalive_ping(js);
 		js->keepalive_timeout = purple_timeout_add_seconds(120,
 				(GSourceFunc)(jabber_keepalive_timeout), gc);
--- a/libpurple/protocols/jabber/jabber.h	Fri Feb 26 14:14:43 2010 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Sat Feb 27 03:49:32 2010 +0000
@@ -166,6 +166,11 @@
 	time_t idle;
 	time_t old_idle;
 
+	/** When we last pinged the server, so we don't ping more
+	 *  often than once every minute.
+	 */
+	time_t last_ping;
+
 	JabberID *user;
 	JabberBuddy *user_jb;