[patch] Update to libfetch

Kelly Yancey kbyanc at posi.net
Mon Feb 21 14:37:11 PST 2005


  Attached is a patch to address concerns raised by Pawel Worach with
regards to the recent change to set TCP_NOPUSH when sending HTTP
requests from libfetch.  The previous revision also introduced a call
to shutdown(2) to close the write half of the socket in order to force
the queued request to be sent.  While this should be perfectly
acceptable behavior for a TCP client, it appears that squid provides a
configuration option to disallow half-closed clients (which Pawel is
currently using).  As such, after introducing the shutdown(2) call,
fetch(1) can no longer fetch files via HTTP through such proxies.
  To address this issue, the attached patch replaces the call to
shutdown(2) with some socket option fiddling (clearing TCP_NOPUSH and
setting TCP_NODELAY) which does the same job of forcing the client to
write the queued request to the network without closing the write half
of the socket.  This feels a bit hackish to me, but gets the job done.
Anyway, I would appreciate any feedback.  Thanks,

  Kelly

--
Kelly Yancey  -  kbyanc@{posi.net,FreeBSD.org}  -  kelly at nttmcl.com
-------------- next part --------------
? fetch.3.gz
? ftperr.h
? httperr.h
? libfetch.so.3
? ~fetch-nodelay.diff
Index: http.c
===================================================================
RCS file: /home/ncvs/src/lib/libfetch/http.c,v
retrieving revision 1.75
diff -u -p -r1.75 http.c
--- http.c	16 Feb 2005 00:22:20 -0000	1.75
+++ http.c	21 Feb 2005 22:29:16 -0000
@@ -792,7 +792,7 @@ _http_request(struct url *URL, const cha
 	conn_t *conn;
 	struct url *url, *new;
 	int chunked, direct, need_auth, noredirect, verbose;
-	int e, i, n;
+	int e, i, n, val;
 	off_t offset, clength, length, size;
 	time_t mtime;
 	const char *p;
@@ -913,7 +913,20 @@ _http_request(struct url *URL, const cha
 			_http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset);
 		_http_cmd(conn, "Connection: close");
 		_http_cmd(conn, "");
-		shutdown(conn->sd, SHUT_WR);
+
+		/*
+		 * Force the queued request to be dispatched.  Normally, one
+		 * would do this with shutdown(2) but squid proxies can be
+		 * configured to disallow such half-closed connections.  To
+		 * be compatible with such configurations, fiddle with socket
+		 * options to force the pending data to be written.
+		 */
+		val = 0;
+		setsockopt(conn->sd, IPPROTO_TCP, TCP_NOPUSH, &val,
+			   sizeof(val));
+		val = 1;
+		setsockopt(conn->sd, IPPROTO_TCP, TCP_NODELAY, &val,
+			   sizeof(val));
 
 		/* get reply */
 		switch (_http_get_reply(conn)) {


More information about the freebsd-net mailing list