r301 - trunk/varnish-tools/fetcher

des at projects.linpro.no des at projects.linpro.no
Tue Jul 4 16:52:54 CEST 2006


Author: des
Date: 2006-07-04 16:52:54 +0200 (Tue, 04 Jul 2006)
New Revision: 301

Modified:
   trunk/varnish-tools/fetcher/fetcher.c
Log:
More iterations, and use fread() instead of getc().

Modified: trunk/varnish-tools/fetcher/fetcher.c
===================================================================
--- trunk/varnish-tools/fetcher/fetcher.c	2006-07-04 14:45:01 UTC (rev 300)
+++ trunk/varnish-tools/fetcher/fetcher.c	2006-07-04 14:52:54 UTC (rev 301)
@@ -13,6 +13,9 @@
 #include <string.h>
 #include <unistd.h>
 
+#define MAX_CTR 5000
+
+static char data[8192];
 static const char HEAD[] = "HEAD";
 static const char GET[] = "GET";
 static const char *method = GET;
@@ -58,7 +61,8 @@
 main(int argc, char *argv[])
 {
 	struct addrinfo hints, *res;
-	int clen, code, ctr, error, opt, sd;
+	int code, ctr, error, opt, sd;
+	size_t clen;
 	const char *line;
 	FILE *f;
 
@@ -90,14 +94,15 @@
 	if ((f = fdopen(sd, "w+")) == NULL)
 		err(1, "fdopen()");
 
-	for (ctr = 0; ctr < 5000; ++ctr) {
+	for (ctr = 0; ctr < 500000; ++ctr) {
 
 		/* send request */
-		fprintf(f, req_pattern, method, ctr);
+		fprintf(f, req_pattern, method, ctr % MAX_CTR);
 #ifdef DEBUG
-		fprintf(stderr, req_pattern, method, ctr);
+		fprintf(stderr, req_pattern, method, ctr % MAX_CTR);
 #else
-		fprintf(stderr, "\r%d ", ctr);
+		if (ctr % 163 == 0)
+			fprintf(stderr, "\r%d ", ctr);
 #endif
 
 		/* get response header */
@@ -109,22 +114,22 @@
 			errx(1, "code %d", code);
 
 		/* get content-length */
-		clen = -1;
+		clen = 0;
 		for (;;) {
 			if ((line = read_line(f)) == NULL)
 				errx(1, "protocol error");
 			if (line[0] == '\0')
 				break;
-			sscanf(line, "Content-Length: %d\n", &clen);
+			sscanf(line, "Content-Length: %zu\n", &clen);
 		}
-		if (clen == -1)
-			errx(1, "no content length");
 
 		/* eat contents */
-		if (method != HEAD)
-			while (clen--)
-				if (getc(f) == EOF)
-					errx(1, "connection prematurely closed");
+		if (method == HEAD)
+			continue;
+		while (clen > 0) {
+			size_t rlen = clen > sizeof(data) ? sizeof(data) : clen;
+			clen -= fread(data, 1, rlen, f);
+		}
 	}
 	fclose(f);
 




More information about the varnish-commit mailing list