Mercurial > pidgin
comparison libpurple/protocols/jabber/bosh.c @ 26273:79ca1cf55d9d
Because BOSH works over connections that may die non-fatally, we need to
limit the number of failed re-connection attempts before we declare the
session lost. Reset the failures each time we process a full read from the
server, which is a little hacky, but indicates that we have a *working*
connection.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 23 Mar 2009 00:47:46 +0000 |
parents | fcee93c74230 |
children | d4af753e0e33 |
comparison
equal
deleted
inserted
replaced
26272:fcee93c74230 | 26273:79ca1cf55d9d |
---|---|
28 #include "xmlnode.h" | 28 #include "xmlnode.h" |
29 | 29 |
30 #include "bosh.h" | 30 #include "bosh.h" |
31 | 31 |
32 #define MAX_HTTP_CONNECTIONS 2 | 32 #define MAX_HTTP_CONNECTIONS 2 |
33 #define MAX_FAILED_CONNECTIONS 3 | |
33 | 34 |
34 typedef struct _PurpleHTTPConnection PurpleHTTPConnection; | 35 typedef struct _PurpleHTTPConnection PurpleHTTPConnection; |
35 | 36 |
36 typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn); | 37 typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn); |
37 typedef void (*PurpleBOSHConnectionReceiveFunction)(PurpleBOSHConnection *conn, xmlnode *node); | 38 typedef void (*PurpleBOSHConnectionReceiveFunction)(PurpleBOSHConnection *conn, xmlnode *node); |
46 | 47 |
47 struct _PurpleBOSHConnection { | 48 struct _PurpleBOSHConnection { |
48 JabberStream *js; | 49 JabberStream *js; |
49 gboolean pipelining; | 50 gboolean pipelining; |
50 PurpleHTTPConnection *connections[MAX_HTTP_CONNECTIONS]; | 51 PurpleHTTPConnection *connections[MAX_HTTP_CONNECTIONS]; |
52 unsigned short failed_connections; | |
51 | 53 |
52 gboolean ready; | 54 gboolean ready; |
53 gboolean ssl; | 55 gboolean ssl; |
54 | 56 |
55 /* decoded URL */ | 57 /* decoded URL */ |
428 } | 430 } |
429 | 431 |
430 static void | 432 static void |
431 http_received_cb(const char *data, int len, PurpleBOSHConnection *conn) | 433 http_received_cb(const char *data, int len, PurpleBOSHConnection *conn) |
432 { | 434 { |
435 if (conn->failed_connections) | |
436 /* We've got some data, so reset the number of failed connections */ | |
437 conn->failed_connections = 0; | |
438 | |
433 if (conn->receive_cb) { | 439 if (conn->receive_cb) { |
434 xmlnode *node = xmlnode_from_str(data, len); | 440 xmlnode *node = xmlnode_from_str(data, len); |
435 if (node) { | 441 if (node) { |
436 char *txt = xmlnode_to_formatted_str(node, NULL); | 442 char *txt = xmlnode_to_formatted_str(node, NULL); |
437 printf("\nhttp_received_cb\n%s\n", txt); | 443 printf("\nhttp_received_cb\n%s\n", txt); |
600 | 606 |
601 if (conn->bosh->pipelining) | 607 if (conn->bosh->pipelining) |
602 /* Hmmmm, fall back to multiple connections */ | 608 /* Hmmmm, fall back to multiple connections */ |
603 conn->bosh->pipelining = FALSE; | 609 conn->bosh->pipelining = FALSE; |
604 | 610 |
605 /* No! Please! Take me back. It was me, not you! I was weak! */ | 611 if (++conn->bosh->failed_connections == MAX_FAILED_CONNECTIONS) { |
606 http_connection_connect(conn); | 612 purple_connection_error_reason(conn->bosh->js->gc, |
613 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | |
614 _("Unable to establish a connection with the server")); | |
615 } else { | |
616 /* No! Please! Take me back. It was me, not you! I was weak! */ | |
617 http_connection_connect(conn); | |
618 } | |
607 } | 619 } |
608 | 620 |
609 void jabber_bosh_connection_connect(PurpleBOSHConnection *bosh) { | 621 void jabber_bosh_connection_connect(PurpleBOSHConnection *bosh) { |
610 PurpleHTTPConnection *conn = bosh->connections[0]; | 622 PurpleHTTPConnection *conn = bosh->connections[0]; |
611 http_connection_connect(conn); | 623 http_connection_connect(conn); |
708 */ | 720 */ |
709 http_connection_disconnected(conn); | 721 http_connection_disconnected(conn); |
710 | 722 |
711 /* Process what we do have */ | 723 /* Process what we do have */ |
712 } | 724 } |
725 | |
713 | 726 |
714 jabber_bosh_http_connection_process(conn); | 727 jabber_bosh_http_connection_process(conn); |
715 } | 728 } |
716 | 729 |
717 static void | 730 static void |