Mercurial > pidgin
comparison libpurple/protocols/jabber/bosh.c @ 27788:46e80810b095
jabber: Better inactivity timer logic.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sat, 01 Aug 2009 04:24:39 +0000 |
parents | 53f0956f76dc |
children | 1ff7de15d856 |
comparison
equal
deleted
inserted
replaced
27787:53f0956f76dc | 27788:46e80810b095 |
---|---|
398 | 398 |
399 jabber_bosh_connection_send(bosh, PACKET_NORMAL, NULL); | 399 jabber_bosh_connection_send(bosh, PACKET_NORMAL, NULL); |
400 return TRUE; | 400 return TRUE; |
401 } | 401 } |
402 | 402 |
403 static void | |
404 restart_inactivity_timer(PurpleBOSHConnection *conn) | |
405 { | |
406 if (conn->inactivity_timer != 0) { | |
407 purple_timeout_remove(conn->inactivity_timer); | |
408 conn->inactivity_timer = 0; | |
409 } | |
410 | |
411 if (conn->max_inactivity != 0) { | |
412 conn->inactivity_timer = | |
413 purple_timeout_add_seconds(conn->max_inactivity - 5 /* rounding */, | |
414 bosh_inactivity_cb, conn); | |
415 } | |
416 } | |
417 | |
403 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) { | 418 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) { |
404 xmlnode *child; | 419 xmlnode *child; |
405 JabberStream *js = conn->js; | 420 JabberStream *js = conn->js; |
406 | 421 |
407 g_return_if_fail(node != NULL); | 422 g_return_if_fail(node != NULL); |
498 purple_debug_warning("jabber", "Ignoring bogusly small inactivity: %s\n", | 513 purple_debug_warning("jabber", "Ignoring bogusly small inactivity: %s\n", |
499 inactivity); | 514 inactivity); |
500 conn->max_inactivity = 0; | 515 conn->max_inactivity = 0; |
501 } else { | 516 } else { |
502 /* TODO: Integrate this with jabber.c keepalive checks... */ | 517 /* TODO: Integrate this with jabber.c keepalive checks... */ |
518 /* TODO: Can this check fail? It shouldn't */ | |
503 if (conn->inactivity_timer == 0) { | 519 if (conn->inactivity_timer == 0) { |
504 purple_debug_misc("jabber", "Starting BOSH inactivity timer for %d secs (compensating for rounding)\n", | 520 purple_debug_misc("jabber", "Starting BOSH inactivity timer " |
521 "for %d secs (compensating for rounding)\n", | |
505 conn->max_inactivity - 5); | 522 conn->max_inactivity - 5); |
506 conn->inactivity_timer = purple_timeout_add_seconds( | 523 restart_inactivity_timer(conn); |
507 conn->max_inactivity - 5 /* rounding */, | |
508 bosh_inactivity_cb, conn); | |
509 } | 524 } |
510 } | 525 } |
511 } | 526 } |
512 | 527 |
513 if (requests) | 528 if (requests) |
917 { | 932 { |
918 char *data; | 933 char *data; |
919 int ret; | 934 int ret; |
920 size_t len; | 935 size_t len; |
921 | 936 |
937 /* Sending something to the server, restart the inactivity timer */ | |
938 restart_inactivity_timer(conn->bosh); | |
939 | |
922 data = g_strdup_printf("POST %s HTTP/1.1\r\n" | 940 data = g_strdup_printf("POST %s HTTP/1.1\r\n" |
923 "Host: %s\r\n" | 941 "Host: %s\r\n" |
924 "User-Agent: %s\r\n" | 942 "User-Agent: %s\r\n" |
925 "Content-Encoding: text/xml; charset=utf-8\r\n" | 943 "Content-Encoding: text/xml; charset=utf-8\r\n" |
926 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n" | 944 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n" |