pidgin: 0c2f5448: Timeout switchboard connections at 60 se...

khc at pidgin.im khc at pidgin.im
Sun Jul 19 13:45:21 EDT 2009


-----------------------------------------------------------------
Revision: 0c2f544829df2f3a369504315f8b3a6cc325749a
Ancestor: 2b00c590408e01c635ca1c95f47709fc28458de0
Author: khc at pidgin.im
Date: 2009-07-19T17:41:38
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/0c2f544829df2f3a369504315f8b3a6cc325749a

Modified files:
        ChangeLog libpurple/protocols/msn/servconn.c
        libpurple/protocols/msn/servconn.h
        libpurple/protocols/msn/switchboard.c

ChangeLog: 

Timeout switchboard connections at 60 seconds, should Fixes #3330 for most
people.


-------------- next part --------------
============================================================
--- ChangeLog	3507f8e35697864e194d4db520996c866fd4637f
+++ ChangeLog	488513d5d5cbd9ed9991141e5ca772661138a12e
@@ -130,6 +130,7 @@ version 2.6.0 (??/??/2009):
 	  from you on MSN.
 	* Support sending an invite message to buddies when requesting authorization
 	  from them on MSN.
+	* Timeout switchboard connections aggressively
 
 	Pidgin:
 	* Added -f command line option to tell Pidgin to ignore NetworkManager
============================================================
--- libpurple/protocols/msn/servconn.c	dc419e3c0bc48b9b56e6a1e6a70ffb1b1245a13f
+++ libpurple/protocols/msn/servconn.c	10329bede882b5b6f7802e37a32770b0b900b6a8
@@ -26,6 +26,7 @@ static void read_cb(gpointer data, gint 
 #include "error.h"
 
 static void read_cb(gpointer data, gint source, PurpleInputCondition cond);
+static void servconn_timeout_renew(MsnServConn *servconn);
 
 /**************************************************************************
  * Main
@@ -52,6 +53,8 @@ msn_servconn_new(MsnSession *session, Ms
 
 	servconn->tx_buf = purple_circ_buffer_new(MSN_BUF_LEN);
 	servconn->tx_handler = 0;
+	servconn->timeout_sec = 0;
+	servconn->timeout_handle = 0;
 
 	servconn->fd = -1;
 
@@ -82,6 +85,8 @@ msn_servconn_destroy(MsnServConn *servco
 	purple_circ_buffer_destroy(servconn->tx_buf);
 	if (servconn->tx_handler > 0)
 		purple_input_remove(servconn->tx_handler);
+	if (servconn->timeout_handle > 0)
+		purple_input_remove(servconn->timeout_handle);
 
 	msn_cmdproc_destroy(servconn->cmdproc);
 	g_free(servconn);
@@ -184,6 +189,7 @@ connect_cb(gpointer data, gint source, c
 		servconn->connect_cb(servconn);
 		servconn->inpa = purple_input_add(servconn->fd, PURPLE_INPUT_READ,
 			read_cb, data);
+		servconn_timeout_renew(servconn);
 	}
 	else
 	{
@@ -219,6 +225,7 @@ msn_servconn_connect(MsnServConn *servco
 
 		servconn->connected = TRUE;
 		servconn->httpconn->virgin = TRUE;
+		servconn_timeout_renew(servconn);
 
 		/* Someone wants to know we connected. */
 		servconn->connect_cb(servconn);
@@ -267,6 +274,12 @@ msn_servconn_disconnect(MsnServConn *ser
 		servconn->inpa = 0;
 	}
 
+	if (servconn->timeout_handle > 0)
+	{
+		purple_input_remove(servconn->timeout_handle);
+		servconn->timeout_handle = 0;
+	}
+
 	close(servconn->fd);
 
 	servconn->rx_buf = NULL;
@@ -279,7 +292,36 @@ msn_servconn_disconnect(MsnServConn *ser
 		servconn->disconnect_cb(servconn);
 }
 
+static gboolean
+servconn_idle_timeout_cb(MsnServConn *servconn)
+{
+	msn_servconn_disconnect(servconn);
+	return FALSE;
+}
+
 static void
+servconn_timeout_renew(MsnServConn *servconn)
+{
+	if (servconn->timeout_handle) {
+		purple_input_remove(servconn->timeout_handle);
+		servconn->timeout_handle = 0;
+	}
+
+	if (servconn->connected && servconn->timeout_sec) {
+		servconn->timeout_handle = purple_timeout_add_seconds(
+			servconn->timeout_sec, servconn_idle_timeout_cb, servconn);
+	}
+}
+
+void
+msn_servconn_set_idle_timeout(MsnServConn *servconn, guint seconds)
+{
+	servconn->timeout_sec = seconds;
+	if (servconn->connected)
+		servconn_timeout_renew(servconn);
+}
+
+static void
 servconn_write_cb(gpointer data, gint source, PurpleInputCondition cond)
 {
 	MsnServConn *servconn = data;
@@ -304,6 +346,7 @@ servconn_write_cb(gpointer data, gint so
 	}
 
 	purple_circ_buffer_mark_read(servconn->tx_buf, ret);
+	servconn_timeout_renew(servconn);
 }
 
 gssize
@@ -358,6 +401,7 @@ msn_servconn_write(MsnServConn *servconn
 		msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE);
 	}
 
+	servconn_timeout_renew(servconn);
 	return ret;
 }
 
@@ -392,6 +436,7 @@ read_cb(gpointer data, gint source, Purp
 	servconn->rx_len += len;
 
 	msn_servconn_process_data(servconn);
+	servconn_timeout_renew(servconn);
 }
 
 void msn_servconn_process_data(MsnServConn *servconn)
============================================================
--- libpurple/protocols/msn/servconn.h	c2b6a2bd8b086027fc6547a16aefe8677fc5a499
+++ libpurple/protocols/msn/servconn.h	d03c10a54ddb0563c68837b1f00c2beb610d57f6
@@ -88,6 +88,8 @@ struct _MsnServConn
 
 	PurpleCircBuffer *tx_buf;
 	guint tx_handler;
+	guint timeout_sec;
+	guint timeout_handle;
 
 	void (*connect_cb)(MsnServConn *); /**< The callback to call when connecting. */
 	void (*disconnect_cb)(MsnServConn *); /**< The callback to call when disconnecting. */
@@ -178,4 +180,12 @@ void msn_servconn_process_data(MsnServCo
  */
 void msn_servconn_process_data(MsnServConn *servconn);
 
+/**
+ * Set a idle timeout fot this servconn
+ *
+ * @param servconn The servconn
+ * @param seconds The idle timeout in seconds
+ */
+void msn_servconn_set_idle_timeout(MsnServConn *servconn, guint seconds);
+
 #endif /* _MSN_SERVCONN_H_ */
============================================================
--- libpurple/protocols/msn/switchboard.c	a9a7ce992850f83f303ada60f8a41d027f47f6d8
+++ libpurple/protocols/msn/switchboard.c	1ba93cad398d9fdb1c5b54daf506665de8702829
@@ -42,15 +42,15 @@ msn_switchboard_new(MsnSession *session)
 msn_switchboard_new(MsnSession *session)
 {
 	MsnSwitchBoard *swboard;
-	MsnServConn *servconn;
 
 	g_return_val_if_fail(session != NULL, NULL);
 
 	swboard = g_new0(MsnSwitchBoard, 1);
 
 	swboard->session = session;
-	swboard->servconn = servconn = msn_servconn_new(session, MSN_SERVCONN_SB);
-	swboard->cmdproc = servconn->cmdproc;
+	swboard->servconn = msn_servconn_new(session, MSN_SERVCONN_SB);
+	msn_servconn_set_idle_timeout(swboard->servconn, 60);
+	swboard->cmdproc = swboard->servconn->cmdproc;
 
 	swboard->msg_queue = g_queue_new();
 	swboard->empty = TRUE;


More information about the Commits mailing list