comparison libpurple/protocols/msn/soap.c @ 24532:d70eb6304eae

Use separate variables to keep track of the timer and the watcher. I believe only one of these will be used at any given time, and so while there is no overlap in their usage we need to use different variables so that we can call either purple_input_remove or purple_timeout_remove depending on the usage. I don't think this matters with glib because purple_input_remove and purple_timeout_remove both call g_source_remove, but it could be an issue when using other event loops. There's also the problem in line 673 where we add the watcher, but then if the call to msn_soap_write_cb fails we add a timer using the same variable. That's still going to be a little buggy.
author Mark Doliner <mark@kingant.net>
date Tue, 25 Nov 2008 02:43:56 +0000
parents faff4870f99d
children a9fdc17304d9
comparison
equal deleted inserted replaced
24531:faff4870f99d 24532:d70eb6304eae
54 time_t last_used; 54 time_t last_used;
55 PurpleSslConnection *ssl; 55 PurpleSslConnection *ssl;
56 gboolean connected; 56 gboolean connected;
57 57
58 guint event_handle; 58 guint event_handle;
59 guint run_timer;
59 GString *buf; 60 GString *buf;
60 gsize handled_len; 61 gsize handled_len;
61 gsize body_len; 62 gsize body_len;
62 int response_code; 63 int response_code;
63 gboolean headers_done; 64 gboolean headers_done;
107 if (conn->event_handle) { 108 if (conn->event_handle) {
108 purple_input_remove(conn->event_handle); 109 purple_input_remove(conn->event_handle);
109 conn->event_handle = 0; 110 conn->event_handle = 0;
110 } 111 }
111 112
113 if (conn->run_timer) {
114 purple_timeout_remove(conn->run_timer);
115 conn->run_timer = 0;
116 }
117
112 if (conn->message) { 118 if (conn->message) {
113 msn_soap_message_destroy(conn->message); 119 msn_soap_message_destroy(conn->message);
114 conn->message = NULL; 120 conn->message = NULL;
115 } 121 }
116 122
222 static void 228 static void
223 msn_soap_connection_handle_next(MsnSoapConnection *conn) 229 msn_soap_connection_handle_next(MsnSoapConnection *conn)
224 { 230 {
225 msn_soap_connection_sanitize(conn, FALSE); 231 msn_soap_connection_sanitize(conn, FALSE);
226 232
227 conn->event_handle = purple_timeout_add(0, msn_soap_connection_run, conn); 233 conn->run_timer = purple_timeout_add(0, msn_soap_connection_run, conn);
228 234
229 if (conn->current_request) { 235 if (conn->current_request) {
230 MsnSoapRequest *req = conn->current_request; 236 MsnSoapRequest *req = conn->current_request;
231 conn->current_request = NULL; 237 conn->current_request = NULL;
232 msn_soap_connection_destroy_foreach_cb(req, conn); 238 msn_soap_connection_destroy_foreach_cb(req, conn);
251 g_queue_push_head(conn->queue, req); 257 g_queue_push_head(conn->queue, req);
252 } else { 258 } else {
253 g_queue_push_tail(conn->queue, req); 259 g_queue_push_tail(conn->queue, req);
254 } 260 }
255 261
256 if (conn->event_handle == 0) 262 if (conn->run_timer == 0)
257 conn->event_handle = purple_timeout_add(0, msn_soap_connection_run, 263 conn->run_timer = purple_timeout_add(0, msn_soap_connection_run,
258 conn); 264 conn);
259 } 265 }
260 266
261 void 267 void
262 msn_soap_message_send(MsnSession *session, MsnSoapMessage *message, 268 msn_soap_message_send(MsnSession *session, MsnSoapMessage *message,
593 { 599 {
594 MsnSoapConnection *conn = data; 600 MsnSoapConnection *conn = data;
595 601
596 conn->connected = TRUE; 602 conn->connected = TRUE;
597 603
598 if (conn->event_handle == 0) 604 if (conn->run_timer == 0)
599 conn->event_handle = purple_timeout_add(0, msn_soap_connection_run, conn); 605 conn->run_timer = purple_timeout_add(0, msn_soap_connection_run, conn);
600 } 606 }
601 607
602 MsnSoapMessage * 608 MsnSoapMessage *
603 msn_soap_message_new(const char *action, xmlnode *xml) 609 msn_soap_message_new(const char *action, xmlnode *xml)
604 { 610 {
614 msn_soap_connection_run(gpointer data) 620 msn_soap_connection_run(gpointer data)
615 { 621 {
616 MsnSoapConnection *conn = data; 622 MsnSoapConnection *conn = data;
617 MsnSoapRequest *req = g_queue_peek_head(conn->queue); 623 MsnSoapRequest *req = g_queue_peek_head(conn->queue);
618 624
619 conn->event_handle = 0; 625 conn->run_timer = 0;
620 626
621 if (req) { 627 if (req) {
622 if (conn->ssl == NULL) { 628 if (conn->ssl == NULL) {
623 conn->ssl = purple_ssl_connect(conn->session->account, conn->host, 629 conn->ssl = purple_ssl_connect(conn->session->account, conn->host,
624 443, msn_soap_connected_cb, msn_soap_error_cb, conn); 630 443, msn_soap_connected_cb, msn_soap_error_cb, conn);
671 conn->connected = FALSE; 677 conn->connected = FALSE;
672 conn->current_request = NULL; 678 conn->current_request = NULL;
673 msn_soap_connection_sanitize(conn, FALSE); 679 msn_soap_connection_sanitize(conn, FALSE);
674 680
675 g_queue_push_head(conn->queue, req); 681 g_queue_push_head(conn->queue, req);
676 conn->event_handle = purple_timeout_add(0, msn_soap_connection_run, conn); 682 conn->run_timer = purple_timeout_add(0, msn_soap_connection_run, conn);
677 } 683 }
678 684
679 g_free(body); 685 g_free(body);
680 } 686 }
681 } 687 }