changeset 14082:426a98fa4527

[gaim-migrate @ 16703] Don't use the same callback for both gaim_proxy_connect() and gaim_input_add(). Aside from being a little confusing, it's hindering some changes I want to make to gaim_proxy_connect(). committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 11 Aug 2006 07:15:39 +0000
parents dee8540be099
children 08dbb5912709
files src/util.c
diffstat 1 files changed, 51 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/util.c	Fri Aug 11 06:38:37 2006 +0000
+++ b/src/util.c	Fri Aug 11 07:15:39 2006 +0000
@@ -3202,7 +3202,7 @@
 
 
 static void
-url_fetched_cb(gpointer url_data, gint sock, GaimInputCondition cond)
+url_fetch_recv_cb(gpointer url_data, gint source, GaimInputCondition cond)
 {
 	GaimFetchUrlData *gfud = url_data;
 	int len;
@@ -3210,7 +3210,7 @@
 	char *data_cursor;
 	gboolean got_eof = FALSE;
 
-	while((len = read(sock, buf, sizeof(buf))) > 0) {
+	while((len = read(source, buf, sizeof(buf))) > 0) {
 		/* If we've filled up our butfer, make it bigger */
 		if((gfud->len + len) >= gfud->data_len) {
 			while((gfud->len + len) >= gfud->data_len)
@@ -3240,7 +3240,7 @@
 					header_len, gfud->webdata);
 
 				/* See if we can find a redirect. */
-				if(parse_redirect(gfud->webdata, header_len, sock, gfud))
+				if(parse_redirect(gfud->webdata, header_len, source, gfud))
 					return;
 
 				gfud->got_headers = TRUE;
@@ -3273,7 +3273,7 @@
 						gaim_debug_error("gaim_url_fetch", "Failed to allocate %u bytes: %s\n",
 							content_len, strerror(errno));
 						gaim_input_remove(gfud->inpa);
-						close(sock);
+						close(source);
 						gfud->callback(gfud->user_data, NULL, 0);
 						destroy_fetch_url_data(gfud);
 
@@ -3310,7 +3310,7 @@
 			got_eof = TRUE;
 		} else {
 			gaim_input_remove(gfud->inpa);
-			close(sock);
+			close(source);
 
 			gfud->callback(gfud->user_data, NULL, 0);
 
@@ -3326,7 +3326,7 @@
 		/* gaim_debug_misc("gaim_url_fetch", "Received: '%s'\n", gfud->webdata); */
 
 		gaim_input_remove(gfud->inpa);
-		close(sock);
+		close(source);
 		gfud->callback(gfud->user_data, gfud->webdata, gfud->len);
 
 		destroy_fetch_url_data(gfud);
@@ -3334,17 +3334,54 @@
 }
 
 static void
-url_fetch_connect_cb(gpointer url_data, gint sock, GaimInputCondition cond) {
-	GaimFetchUrlData *gfud = url_data;
+url_fetch_send_cb(gpointer data, gint source, GaimInputCondition cond)
+{
+	GaimFetchUrlData *gfud;
 	int len, total_len;
 
-	if(sock == -1) {
+	gfud = data;
+
+	total_len = strlen(gfud->request);
+
+	len = write(source, gfud->request + gfud->request_written,
+			total_len - gfud->request_written);
+
+	if(len < 0 && errno == EAGAIN)
+		return;
+	else if(len < 0) {
+		gaim_input_remove(gfud->inpa);
+		close(source);
 		gfud->callback(gfud->user_data, NULL, 0);
 		destroy_fetch_url_data(gfud);
 		return;
 	}
-
-	if (!gfud->request) {
+	gfud->request_written += len;
+
+	if(gfud->request_written != total_len)
+		return;
+
+	/* We're done writing, now start reading */
+	gaim_input_remove(gfud->inpa);
+	gfud->inpa = gaim_input_add(source, GAIM_INPUT_READ, url_fetch_recv_cb,
+		gfud);
+}
+
+static void
+url_fetch_connect_cb(gpointer url_data, gint source, GaimInputCondition cond)
+{
+	GaimFetchUrlData *gfud;
+
+	gfud = url_data;
+
+	if (source == -1)
+	{
+		gfud->callback(gfud->user_data, NULL, 0);
+		destroy_fetch_url_data(gfud);
+		return;
+	}
+
+	if (!gfud->request)
+	{
 		if (gfud->user_agent) {
 			/* Host header is not forbidden in HTTP/1.0 requests, and HTTP/1.1
 			 * clients must know how to handle the "chunked" transfer encoding.
@@ -3376,33 +3413,9 @@
 
 	gaim_debug_misc("gaim_url_fetch", "Request: '%s'\n", gfud->request);
 
-	if(!gfud->inpa)
-		gfud->inpa = gaim_input_add(sock, GAIM_INPUT_WRITE,
-			url_fetch_connect_cb, gfud);
-
-	total_len = strlen(gfud->request);
-
-	len = write(sock, gfud->request + gfud->request_written,
-			total_len - gfud->request_written);
-
-	if(len < 0 && errno == EAGAIN)
-		return;
-	else if(len < 0) {
-		gaim_input_remove(gfud->inpa);
-		close(sock);
-		gfud->callback(gfud->user_data, NULL, 0);
-		destroy_fetch_url_data(gfud);
-		return;
-	}
-	gfud->request_written += len;
-
-	if(gfud->request_written != total_len)
-		return;
-
-	gaim_input_remove(gfud->inpa);
-
-	gfud->inpa = gaim_input_add(sock, GAIM_INPUT_READ, url_fetched_cb,
-		gfud);
+	gfud->inpa = gaim_input_add(source, GAIM_INPUT_WRITE,
+								url_fetch_send_cb, gfud);
+	url_fetch_send_cb(gfud, source, GAIM_INPUT_WRITE);
 }
 
 void