Mercurial > pidgin
comparison libpurple/protocols/jabber/bosh.c @ 31144:7986f4e5a05f
jabber: Be friendlier to servers when we have nothing to say.
Don't try to reconnect immediately, but do so when we have something
to send. Untested (I'll test it later), but I'm hoping hsitas444 will
test it first. Refs #13008.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 12 Jan 2011 14:31:52 +0000 |
parents | 6826925abd6d |
children | 928335d6461b |
comparison
equal
deleted
inserted
replaced
31139:365ec0996ca0 | 31144:7986f4e5a05f |
---|---|
304 if (conn->connections[i] && | 304 if (conn->connections[i] && |
305 conn->connections[i]->state == HTTP_CONN_CONNECTING) | 305 conn->connections[i]->state == HTTP_CONN_CONNECTING) |
306 return NULL; | 306 return NULL; |
307 } | 307 } |
308 | 308 |
309 /* Third loop, look for one that's NULL and create a new connection */ | 309 /* Third loop, is something offline that we can connect? */ |
310 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { | |
311 if (conn->connections[i] && | |
312 conn->connections[i]->state == HTTP_CONN_OFFLINE) { | |
313 purple_debug_info("jabber", "bosh: Reconnecting httpconn " | |
314 "(%i, %p)\n", i, conn->connections[i]); | |
315 http_connection_connect(conn->connections[i]); | |
316 return NULL; | |
317 } | |
318 } | |
319 | |
320 /* Fourth loop, look for one that's NULL and create a new connection */ | |
310 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { | 321 for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) { |
311 if (!conn->connections[i]) { | 322 if (!conn->connections[i]) { |
312 conn->connections[i] = jabber_bosh_http_connection_init(conn); | 323 conn->connections[i] = jabber_bosh_http_connection_init(conn); |
313 purple_debug_info("jabber", "bosh: Creating and connecting new httpconn " | 324 purple_debug_info("jabber", "bosh: Creating and connecting new httpconn " |
314 "(%i, %p)\n", i, conn->connections[i]); | 325 "(%i, %p)\n", i, conn->connections[i]); |
672 jabber_bosh_connection_boot(conn->bosh); | 683 jabber_bosh_connection_boot(conn->bosh); |
673 } | 684 } |
674 | 685 |
675 static void http_connection_disconnected(PurpleHTTPConnection *conn) | 686 static void http_connection_disconnected(PurpleHTTPConnection *conn) |
676 { | 687 { |
688 gboolean had_requests = FALSE; | |
677 /* | 689 /* |
678 * Well, then. Fine! I never liked you anyway, server! I was cheating on you | 690 * Well, then. Fine! I never liked you anyway, server! I was cheating on you |
679 * with AIM! | 691 * with AIM! |
680 */ | 692 */ |
681 conn->state = HTTP_CONN_OFFLINE; | 693 conn->state = HTTP_CONN_OFFLINE; |
695 if (conn->writeh) { | 707 if (conn->writeh) { |
696 purple_input_remove(conn->writeh); | 708 purple_input_remove(conn->writeh); |
697 conn->writeh = 0; | 709 conn->writeh = 0; |
698 } | 710 } |
699 | 711 |
700 if (conn->requests > 0 && conn->read_buf->len == 0) { | 712 had_requests = (conn->requests > 0); |
713 if (had_requests && conn->read_buf->len == 0) { | |
701 purple_debug_error("jabber", "bosh: Adjusting BOSHconn requests (%d) to %d\n", | 714 purple_debug_error("jabber", "bosh: Adjusting BOSHconn requests (%d) to %d\n", |
702 conn->bosh->requests, conn->bosh->requests - conn->requests); | 715 conn->bosh->requests, conn->bosh->requests - conn->requests); |
703 conn->bosh->requests -= conn->requests; | 716 conn->bosh->requests -= conn->requests; |
704 conn->requests = 0; | 717 conn->requests = 0; |
705 } | 718 } |
706 | 719 |
707 if (conn->bosh->pipelining) { | 720 if (conn->bosh->pipelining) { |
708 /* Hmmmm, fall back to multiple connections */ | 721 /* Hmmmm, fall back to multiple connections */ |
709 jabber_bosh_disable_pipelining(conn->bosh); | 722 jabber_bosh_disable_pipelining(conn->bosh); |
710 } | 723 } |
724 | |
725 if (!had_requests) | |
726 /* If the server disconnected us without any requests, let's | |
727 * just wait until we have something to send before we reconnect | |
728 */ | |
729 return; | |
711 | 730 |
712 if (++conn->bosh->failed_connections == MAX_FAILED_CONNECTIONS) { | 731 if (++conn->bosh->failed_connections == MAX_FAILED_CONNECTIONS) { |
713 purple_connection_error_reason(conn->bosh->js->gc, | 732 purple_connection_error_reason(conn->bosh->js->gc, |
714 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 733 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
715 _("Unable to establish a connection with the server")); | 734 _("Unable to establish a connection with the server")); |