changeset 8298:c719f9a181d4

[gaim-migrate @ 9022] Though it doesn't fix a thing, this is a better timer implementation for HTTP polling. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 20 Feb 2004 21:37:45 +0000
parents a6e8ef48c7a4
children 7402101c0319
files src/protocols/msn/httpmethod.c src/protocols/msn/httpmethod.h src/protocols/msn/msn.c src/protocols/msn/session.h
diffstat 4 files changed, 63 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/httpmethod.c	Fri Feb 20 05:11:55 2004 +0000
+++ b/src/protocols/msn/httpmethod.c	Fri Feb 20 21:37:45 2004 +0000
@@ -48,37 +48,59 @@
 static gboolean
 http_poll(gpointer data)
 {
-	MsnServConn *servconn = data;
+	MsnSession *session = data;
+	MsnServConn *servconn;
+	GList *l;
 
-	gaim_debug_info("msn", "Polling server %s.\n",
-					servconn->http_data->gateway_ip);
-	msn_http_servconn_poll(servconn);
+	for (l = session->servconns; l != NULL; l = l->next)
+	{
+		servconn = (MsnServConn *)l->data;
 
-	servconn->http_data->timer = 0;
+		if (servconn->http_data->dirty)
+		{
+			gaim_debug_info("msn", "Polling server %s.\n",
+							servconn->http_data->gateway_ip);
+			msn_http_servconn_poll(servconn);
+		}
+	}
 
-	gaim_debug(GAIM_DEBUG_INFO, "msn", "Returning from http_poll\n");
-
-	return FALSE;
+	return TRUE;
 }
 
 static void
-stop_timer(MsnServConn *servconn)
+stop_timer(MsnSession *session)
 {
-	if (servconn->http_data->timer)
+	if (session->http_poll_timer)
 	{
 		gaim_debug(GAIM_DEBUG_INFO, "msn", "Stopping timer\n");
-		gaim_timeout_remove(servconn->http_data->timer);
-		servconn->http_data->timer = 0;
+		gaim_timeout_remove(session->http_poll_timer);
+		session->http_poll_timer = 0;
 	}
 }
 
 static void
-start_timer(MsnServConn *servconn)
+start_timer(MsnSession *session)
 {
-	stop_timer(servconn);
+	stop_timer(session);
 
 	gaim_debug(GAIM_DEBUG_INFO, "msn", "Starting timer\n");
-	servconn->http_data->timer = gaim_timeout_add(5000, http_poll, servconn);
+	session->http_poll_timer = gaim_timeout_add(5000, http_poll, session);
+}
+
+void
+msn_http_session_init(MsnSession *session)
+{
+	g_return_if_fail(session != NULL);
+
+	start_timer(session);
+}
+
+void
+msn_http_session_uninit(MsnSession *session)
+{
+	g_return_if_fail(session != NULL);
+
+	stop_timer(session);
 }
 
 size_t
@@ -180,10 +202,8 @@
 	g_free(temp);
 
 	servconn->http_data->waiting_response = TRUE;
-
 	servconn->http_data->virgin = FALSE;
-
-	stop_timer(servconn);
+	servconn->http_data->dirty = FALSE;
 
 	return s;
 }
@@ -226,8 +246,7 @@
 	g_free(temp);
 
 	servconn->http_data->waiting_response = TRUE;
-
-	stop_timer(servconn);
+	servconn->http_data->dirty = FALSE;
 
 	if (s <= 0)
 		gaim_connection_error(servconn->session->account->gc,
@@ -416,7 +435,7 @@
 		g_free(queue_data);
 	}
 	else
-		start_timer(servconn);
+		servconn->http_data->dirty = TRUE;
 
 	return TRUE;
 }
--- a/src/protocols/msn/httpmethod.h	Fri Feb 20 05:11:55 2004 +0000
+++ b/src/protocols/msn/httpmethod.h	Fri Feb 20 21:37:45 2004 +0000
@@ -37,11 +37,26 @@
 
 	gboolean virgin;
 	gboolean waiting_response;
+	gboolean dirty;
 
 	GList *queue;
 };
 
 /**
+ * Initializes the HTTP data for a session.
+ *
+ * @param session The session.
+ */
+void msn_http_session_init(MsnSession *session);
+
+/**
+ * Uninitializes the HTTP data for a session.
+ *
+ * @param session The session.
+ */
+void msn_http_session_uninit(MsnSession *session);
+
+/**
  * Writes data to the server using the HTTP connection method.
  *
  * @param servconn    The server connection.
--- a/src/protocols/msn/msn.c	Fri Feb 20 05:11:55 2004 +0000
+++ b/src/protocols/msn/msn.c	Fri Feb 20 21:37:45 2004 +0000
@@ -271,7 +271,7 @@
 	swboard->chat = serv_got_joined_chat(gc, ++swboard->chat_id, "MSN Chat");
 
 	gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->chat),
-					   gaim_account_get_username(account), NULL);
+							gaim_account_get_username(account), NULL);
 }
 
 /**************************************************************************
@@ -478,6 +478,9 @@
 	session->http_method = http_method;
 	session->prpl = my_protocol;
 
+	if (session->http_method)
+		msn_http_session_init(session);
+
 	gc->proto_data = session;
 
 	gaim_connection_update_progress(gc, _("Connecting"), 0, MSN_CONNECT_STEPS);
@@ -500,6 +503,9 @@
 {
 	MsnSession *session = gc->proto_data;
 
+	if (session->http_method)
+		msn_http_session_uninit(session);
+
 	msn_session_destroy(session);
 
 	gc->proto_data = NULL;
@@ -1667,12 +1673,10 @@
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
 											   option);
 
-#if 0
 	option = gaim_account_option_bool_new(_("Use HTTP Method"), "http_method",
 										  FALSE);
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
 											   option);
-#endif
 
 	my_protocol = plugin;
 
--- a/src/protocols/msn/session.h	Fri Feb 20 05:11:55 2004 +0000
+++ b/src/protocols/msn/session.h	Fri Feb 20 21:37:45 2004 +0000
@@ -53,6 +53,7 @@
 	unsigned int trId;
 
 	gboolean http_method;
+	gint http_poll_timer;
 
 	MsnUsers *users;
 	MsnGroups *groups;