cpw.darkrain42.xmpp.bosh: 30bb050a: Clean up BOSH reading and disconnection ...

paul at darkrain42.org paul at darkrain42.org
Sun Mar 22 23:10:42 EDT 2009


-----------------------------------------------------------------
Revision: 30bb050ab53b27773ea02b00208843265f0487a9
Ancestor: 975da21cb04e3590ec37c00567b79b4a5ef0f64f
Author: paul at darkrain42.org
Date: 2009-03-16T02:45:53
Branch: im.pidgin.cpw.darkrain42.xmpp.bosh
URL: http://d.pidgin.im/viewmtn/revision/info/30bb050ab53b27773ea02b00208843265f0487a9

Modified files:
        libpurple/protocols/jabber/bosh.c

ChangeLog: 

Clean up BOSH reading and disconnection handling.

In particular, notice we've disconnected _before_ we process what we read,
so that, if processing ends up trying to send a new packet, this connection
will be marked as closed.

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c	69f3bc20a0763f5beab7cde1f3a6b2d474a911d5
+++ libpurple/protocols/jabber/bosh.c	9c2f61a237f834bc23317b1dc3d5ff91963ac392
@@ -498,7 +498,15 @@ static void http_connection_connected(Pu
 
 static void http_connection_connected(PurpleHTTPConnection *conn)
 {
+	/* Indicate we're ready and reset some variables */
 	conn->ready = TRUE;
+	conn->requests = 0;
+	if (conn->buf) {
+		g_string_free(conn->buf, TRUE);
+		conn->buf = NULL;
+	}
+	conn->headers_done = FALSE;
+	conn->handled_len = conn->body_len = 0;
 
 	if (conn->bosh->ready) {
 		purple_debug_info("jabber", "BOSH session already exists. Trying to reuse it.\n");
@@ -528,6 +536,8 @@ static void http_connection_disconnected
 	 */
 	conn->ready = FALSE;
 	conn->fd = -1;
+	purple_input_remove(conn->ie_handle);
+	conn->ie_handle = 0;
 
 	if (conn->bosh->pipelining)
 		/* Hmmmm, fall back to multiple connections */
@@ -605,38 +615,29 @@ jabber_bosh_http_connection_read(gpointe
 {
 	PurpleHTTPConnection *conn = data;
 	char buffer[1025];
-	int perrno;
 	int cnt, count = 0;
 
-	purple_debug_info("jabber", "jabber_bosh_http_connection_read\n");
-
 	if (!conn->buf)
 		conn->buf = g_string_new("");
 
 	while ((cnt = read(fd, buffer, sizeof(buffer))) > 0) {
-		purple_debug_info("jabber", "bosh read %d bytes\n", cnt);
 		count += cnt;
 		g_string_append_len(conn->buf, buffer, cnt);
 	}
 
-	perrno = errno;
-	if (cnt == 0 && count) {
-		/* TODO: process should know this response ended with a closed socket
-		 * and throw an error if it's not a complete response. */
-		jabber_bosh_http_connection_process(conn);
-	}
-
-	if (cnt == 0 || (cnt < 0 && perrno != EAGAIN)) {
+	if (cnt == 0 || (cnt < 0 && errno != EAGAIN)) {
 		if (cnt < 0)
-			purple_debug_info("jabber", "bosh read: %d\n", cnt);
+			purple_debug_info("jabber", "bosh read=%d, errno=%d\n", cnt, errno);
 		else
-			purple_debug_info("jabber", "bosh socket closed\n");
-	
-		purple_input_remove(conn->ie_handle);
-		conn->ie_handle = 0;
+			purple_debug_info("jabber", "bosh server closed connection\n");
 
+		/*
+		 * If the socket is closed, the processing really needs to know about
+		 * it. Handle that now (it will be handled again post-processing).
+		 */
 		http_connection_disconnected(conn);
-		return;
+
+		/* Process what we do have */
 	}
 
 	jabber_bosh_http_connection_process(conn);
@@ -694,7 +695,6 @@ http_connection_send_request(PurpleHTTPC
 
 	packet = g_string_append(packet, req->str);
 
-	purple_debug_misc("jabber", "BOSH out: %s\n", packet->str);
 	/* TODO: Better error handling, circbuffer or possible integration with
 	 * low-level code in jabber.c */
 	ret = write(conn->fd, packet->str, packet->len);
@@ -704,7 +704,7 @@ http_connection_send_request(PurpleHTTPC
 	g_string_free(packet, TRUE);
 
 	if (ret < 0 && errno == EAGAIN)
-		purple_debug_warning("jabber", "BOSH write would have blocked\n");
+		purple_debug_error("jabber", "BOSH write would have blocked\n");
 
 	if (ret <= 0) {
 		purple_connection_error_reason(conn->bosh->js->gc,


More information about the Commits mailing list