Mercurial > pidgin
comparison src/protocols/msn/httpmethod.c @ 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 | ef881489396e |
| children | 7402101c0319 |
comparison
equal
deleted
inserted
replaced
| 8297:a6e8ef48c7a4 | 8298:c719f9a181d4 |
|---|---|
| 46 } MsnHttpQueueData; | 46 } MsnHttpQueueData; |
| 47 | 47 |
| 48 static gboolean | 48 static gboolean |
| 49 http_poll(gpointer data) | 49 http_poll(gpointer data) |
| 50 { | 50 { |
| 51 MsnServConn *servconn = data; | 51 MsnSession *session = data; |
| 52 | 52 MsnServConn *servconn; |
| 53 gaim_debug_info("msn", "Polling server %s.\n", | 53 GList *l; |
| 54 servconn->http_data->gateway_ip); | 54 |
| 55 msn_http_servconn_poll(servconn); | 55 for (l = session->servconns; l != NULL; l = l->next) |
| 56 | 56 { |
| 57 servconn->http_data->timer = 0; | 57 servconn = (MsnServConn *)l->data; |
| 58 | 58 |
| 59 gaim_debug(GAIM_DEBUG_INFO, "msn", "Returning from http_poll\n"); | 59 if (servconn->http_data->dirty) |
| 60 | 60 { |
| 61 return FALSE; | 61 gaim_debug_info("msn", "Polling server %s.\n", |
| 62 servconn->http_data->gateway_ip); | |
| 63 msn_http_servconn_poll(servconn); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 return TRUE; | |
| 62 } | 68 } |
| 63 | 69 |
| 64 static void | 70 static void |
| 65 stop_timer(MsnServConn *servconn) | 71 stop_timer(MsnSession *session) |
| 66 { | 72 { |
| 67 if (servconn->http_data->timer) | 73 if (session->http_poll_timer) |
| 68 { | 74 { |
| 69 gaim_debug(GAIM_DEBUG_INFO, "msn", "Stopping timer\n"); | 75 gaim_debug(GAIM_DEBUG_INFO, "msn", "Stopping timer\n"); |
| 70 gaim_timeout_remove(servconn->http_data->timer); | 76 gaim_timeout_remove(session->http_poll_timer); |
| 71 servconn->http_data->timer = 0; | 77 session->http_poll_timer = 0; |
| 72 } | 78 } |
| 73 } | 79 } |
| 74 | 80 |
| 75 static void | 81 static void |
| 76 start_timer(MsnServConn *servconn) | 82 start_timer(MsnSession *session) |
| 77 { | 83 { |
| 78 stop_timer(servconn); | 84 stop_timer(session); |
| 79 | 85 |
| 80 gaim_debug(GAIM_DEBUG_INFO, "msn", "Starting timer\n"); | 86 gaim_debug(GAIM_DEBUG_INFO, "msn", "Starting timer\n"); |
| 81 servconn->http_data->timer = gaim_timeout_add(5000, http_poll, servconn); | 87 session->http_poll_timer = gaim_timeout_add(5000, http_poll, session); |
| 88 } | |
| 89 | |
| 90 void | |
| 91 msn_http_session_init(MsnSession *session) | |
| 92 { | |
| 93 g_return_if_fail(session != NULL); | |
| 94 | |
| 95 start_timer(session); | |
| 96 } | |
| 97 | |
| 98 void | |
| 99 msn_http_session_uninit(MsnSession *session) | |
| 100 { | |
| 101 g_return_if_fail(session != NULL); | |
| 102 | |
| 103 stop_timer(session); | |
| 82 } | 104 } |
| 83 | 105 |
| 84 size_t | 106 size_t |
| 85 msn_http_servconn_write(MsnServConn *servconn, const char *buf, size_t size, | 107 msn_http_servconn_write(MsnServConn *servconn, const char *buf, size_t size, |
| 86 const char *server_type) | 108 const char *server_type) |
| 178 } while (s < needed); | 200 } while (s < needed); |
| 179 | 201 |
| 180 g_free(temp); | 202 g_free(temp); |
| 181 | 203 |
| 182 servconn->http_data->waiting_response = TRUE; | 204 servconn->http_data->waiting_response = TRUE; |
| 183 | |
| 184 servconn->http_data->virgin = FALSE; | 205 servconn->http_data->virgin = FALSE; |
| 185 | 206 servconn->http_data->dirty = FALSE; |
| 186 stop_timer(servconn); | |
| 187 | 207 |
| 188 return s; | 208 return s; |
| 189 } | 209 } |
| 190 | 210 |
| 191 void | 211 void |
| 224 s = write(servconn->fd, temp, strlen(temp)); | 244 s = write(servconn->fd, temp, strlen(temp)); |
| 225 | 245 |
| 226 g_free(temp); | 246 g_free(temp); |
| 227 | 247 |
| 228 servconn->http_data->waiting_response = TRUE; | 248 servconn->http_data->waiting_response = TRUE; |
| 229 | 249 servconn->http_data->dirty = FALSE; |
| 230 stop_timer(servconn); | |
| 231 | 250 |
| 232 if (s <= 0) | 251 if (s <= 0) |
| 233 gaim_connection_error(servconn->session->account->gc, | 252 gaim_connection_error(servconn->session->account->gc, |
| 234 _("Write error")); | 253 _("Write error")); |
| 235 } | 254 } |
| 414 | 433 |
| 415 g_free(queue_data->buffer); | 434 g_free(queue_data->buffer); |
| 416 g_free(queue_data); | 435 g_free(queue_data); |
| 417 } | 436 } |
| 418 else | 437 else |
| 419 start_timer(servconn); | 438 servconn->http_data->dirty = TRUE; |
| 420 | 439 |
| 421 return TRUE; | 440 return TRUE; |
| 422 } | 441 } |
| 423 | 442 |
