changeset 22149:252b96b6a32c

Don't send keep-alives if we've received data since in the last KEEPALIVE_INTERVAL seconds
author Sean Egan <seanegan@gmail.com>
date Wed, 23 Jan 2008 23:28:38 +0000
parents 80e5eaa8f580
children 6419554aadd9
files ChangeLog.API libpurple/connection.c libpurple/connection.h libpurple/protocols/gg/gg.c libpurple/protocols/irc/irc.c libpurple/protocols/jabber/jabber.c libpurple/protocols/msn/servconn.c libpurple/protocols/msnp9/servconn.c libpurple/protocols/myspace/myspace.c libpurple/protocols/oscar/flap_connection.c libpurple/protocols/sametime/sametime.c libpurple/protocols/simple/simple.c libpurple/protocols/yahoo/yahoo.c
diffstat 13 files changed, 30 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Thu Jan 17 21:08:20 2008 +0000
+++ b/ChangeLog.API	Wed Jan 23 23:28:38 2008 +0000
@@ -30,6 +30,8 @@
 			* purple_attention_type_get_outgoing_desc
 			* purple_attention_type_get_icon_name
 			* purple_attention_type_get_unlocalized_name
+		* last_received to PurpleAccount, the time_t of the last
+		  received packet
 
 	Pidgin:
 		Added:
--- a/libpurple/connection.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/connection.c	Wed Jan 23 23:28:38 2008 +0000
@@ -52,8 +52,19 @@
 	PurpleConnection *gc = data;
 	PurplePluginProtocolInfo *prpl_info = NULL;
 
-	if (gc != NULL && gc->prpl != NULL)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
+	if (gc == NULL)
+		return;
+
+	/* Only send keep-alives if we haven't heard from the
+ 	 * server in a while.
+ 	 */
+	if ((time(NULL) - gc->last_received) < KEEPALIVE_INTERVAL)
+		return;
+
+	if (gc->prpl == NULL)
+		return;
+
+	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl);
 
 	if (prpl_info && prpl_info->keepalive)
 		prpl_info->keepalive(gc);
--- a/libpurple/connection.h	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/connection.h	Wed Jan 23 23:28:38 2008 +0000
@@ -251,6 +251,8 @@
 	gboolean wants_to_die;
 
 	guint disconnect_timeout;    /**< Timer used for nasty stack tricks  */
+	time_t last_received;        /**< When we last received a packet. Set by the
+					  prpl to avoid sending unneeded keepalives */
 };
 
 #ifdef __cplusplus
--- a/libpurple/protocols/gg/gg.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/gg/gg.c	Wed Jan 23 23:28:38 2008 +0000
@@ -1314,7 +1314,7 @@
 			_("Unable to read socket"));
 		return;
 	}
-
+	gc->last_received = time(NULL);
 	switch (ev->type) {
 		case GG_EVENT_NONE:
 			/* Nothing happened. */
--- a/libpurple/protocols/irc/irc.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/irc/irc.c	Wed Jan 23 23:28:38 2008 +0000
@@ -572,6 +572,7 @@
 {
 	char *cur, *end;
 
+	irc->account->gc->last_received = time(NULL);
 	irc->inbufused += len;
 	irc->inbuf[irc->inbufused] = '\0';
 
--- a/libpurple/protocols/jabber/jabber.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Wed Jan 23 23:28:38 2008 +0000
@@ -432,6 +432,7 @@
 	}
 
 	while((len = purple_ssl_read(gsc, buf, sizeof(buf) - 1)) > 0) {
+		gc->last_received = time(NULL);
 		buf[len] = '\0';
 		purple_debug(PURPLE_DEBUG_INFO, "jabber", "Recv (ssl)(%d): %s\n", len, buf);
 		jabber_parser_process(js, buf, len);
@@ -459,6 +460,7 @@
 		return;
 
 	if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) {
+		gc->last_received = time(NULL);
 #ifdef HAVE_CYRUS_SASL
 		if (js->sasl_maxbuf>0) {
 			const char *out;
--- a/libpurple/protocols/msn/servconn.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/msn/servconn.c	Wed Jan 23 23:28:38 2008 +0000
@@ -391,6 +391,7 @@
 	session = servconn->session;
 
 	len = read(servconn->fd, buf, sizeof(buf) - 1);
+	servconn->session->account->gc->last_connected = time(NULL);
 
 	if (len <= 0) {
 		switch (errno) {
--- a/libpurple/protocols/msnp9/servconn.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/msnp9/servconn.c	Wed Jan 23 23:28:38 2008 +0000
@@ -387,6 +387,7 @@
 	session = servconn->session;
 
 	len = read(servconn->fd, buf, sizeof(buf) - 1);
+	servconn->session->account->gc->last_received = time(NULL);
 
 	if (len < 0 && errno == EAGAIN)
 		return;
--- a/libpurple/protocols/myspace/myspace.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Wed Jan 23 23:28:38 2008 +0000
@@ -2452,6 +2452,7 @@
 	 * the file descriptor, but it sometimes differs from the 'source' parameter.
 	 */
 	n = recv(session->fd, session->rxbuf + session->rxoff, MSIM_READ_BUF_SIZE - session->rxoff, 0);
+	gc->last_received = time(NULL);
 
 	if (n < 0 && errno == EAGAIN) {
 		return;
--- a/libpurple/protocols/oscar/flap_connection.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/oscar/flap_connection.c	Wed Jan 23 23:28:38 2008 +0000
@@ -817,6 +817,7 @@
 						OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno));
 				break;
 			}
+			conn->od->gc->last_received = time(NULL);
 
 			/* If we don't even have a complete FLAP header then do nothing */
 			conn->header_received += read;
--- a/libpurple/protocols/sametime/sametime.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/sametime/sametime.c	Wed Jan 23 23:28:38 2008 +0000
@@ -1695,7 +1695,9 @@
   int len;
 
   len = read(sock, buf, BUF_LEN);
-  if(len > 0) mwSession_recv(session, buf, len);
+  if(len > 0) {
+    mwSession_recv(session, buf, len);
+  }
 
   return len;
 }
--- a/libpurple/protocols/simple/simple.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/simple/simple.c	Wed Jan 23 23:28:38 2008 +0000
@@ -1675,7 +1675,7 @@
 		if(sip->fd == source) sip->fd = -1;
 		return;
 	}
-
+	gc->last_received = time(NULL);
 	conn->inbufused += len;
 	conn->inbuf[conn->inbufused] = '\0';
 
--- a/libpurple/protocols/yahoo/yahoo.c	Thu Jan 17 21:08:20 2008 +0000
+++ b/libpurple/protocols/yahoo/yahoo.c	Wed Jan 23 23:28:38 2008 +0000
@@ -2506,7 +2506,7 @@
 				_("Server closed the connection."));
 		return;
 	}
-
+	gc->last_received = time(NULL);
 	yd->rxqueue = g_realloc(yd->rxqueue, len + yd->rxlen);
 	memcpy(yd->rxqueue + yd->rxlen, buf, len);
 	yd->rxlen += len;