[master] abc5dd2 Go over this code once more, and fix various nits.

Poul-Henning Kamp phk at varnish-cache.org
Wed Sep 21 00:00:34 CEST 2011


commit abc5dd2a72249fe49d3f1071d8268d3708d7fd3e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Sep 20 22:00:12 2011 +0000

    Go over this code once more, and fix various nits.

diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 8f96577..e6aaf33 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -107,7 +107,7 @@ synth_body(const char *len, int rnd)
 	AN(len);
 	i = strtoul(len, NULL, 0);
 	assert(i > 0);
-	b = malloc(i + 1);
+	b = malloc(i + 1L);
 	AN(b);
 	l = k = '!';
 	for (j = 0; j < i; j++) {
@@ -333,7 +333,7 @@ http_splitheader(struct http *hp, int req)
  */
 
 static int
-http_rxchar_eof(struct http *hp, int n)
+http_rxchar(struct http *hp, int n, int eof)
 {
 	int i;
 	struct pollfd pfd[1];
@@ -343,21 +343,25 @@ http_rxchar_eof(struct http *hp, int n)
 		pfd[0].events = POLLIN;
 		pfd[0].revents = 0;
 		i = poll(pfd, 1, hp->timeout);
-		if (i < 0)
+		if (i == 0)
 			vtc_log(hp->vl, 0, "HTTP rx timeout (fd:%d %u ms)",
 			    hp->fd, hp->timeout);
 		if (i < 0)
 			vtc_log(hp->vl, 0, "HTTP rx failed (fd:%d poll: %s)",
 			    hp->fd, strerror(errno));
 		assert(i > 0);
-		if (pfd[0].revents & ~POLLIN)
-			vtc_log(hp->vl, 4, "HTTP rx poll (fd:%d revents: %x)",
-			    hp->fd, pfd[0].revents);
 		assert(hp->prxbuf + n < hp->nrxbuf);
 		i = read(hp->fd, hp->rxbuf + hp->prxbuf, n);
-		if (i == 0)
+		if (!(pfd[0].revents & POLLIN))
+			vtc_log(hp->vl, 4,
+			    "HTTP rx poll (fd:%d revents: %x n=%d, i=%d)",
+			    hp->fd, pfd[0].revents, n, i);
+		if (i == 0 && eof)
 			return (i);
-		if (i <= 0)
+		if (i == 0)
+			vtc_log(hp->vl, 0, "HTTP rx EOF (fd:%d read: %s)",
+			    hp->fd, strerror(errno));
+		if (i < 0)
 			vtc_log(hp->vl, 0, "HTTP rx failed (fd:%d read: %s)",
 			    hp->fd, strerror(errno));
 		hp->prxbuf += i;
@@ -367,17 +371,6 @@ http_rxchar_eof(struct http *hp, int n)
 	return (1);
 }
 
-static void
-http_rxchar(struct http *hp, int n)
-{
-	int i;
-
-	i = http_rxchar_eof(hp, n);
-	if (i <= 0)
-		vtc_log(hp->vl, 0, "HTTP rx failed (%s)", strerror(errno));
-	assert(i > 0);
-}
-
 static int
 http_rxchunk(struct http *hp)
 {
@@ -386,7 +379,7 @@ http_rxchunk(struct http *hp)
 
 	l = hp->prxbuf;
 	do
-		http_rxchar(hp, 1);
+		(void)http_rxchar(hp, 1, 0);
 	while (hp->rxbuf[hp->prxbuf - 1] != '\n');
 	vtc_dump(hp->vl, 4, "len", hp->rxbuf + l, -1);
 	i = strtoul(hp->rxbuf + l, &q, 16);
@@ -400,12 +393,12 @@ http_rxchunk(struct http *hp)
 	assert(*q == '\0' || vct_islws(*q));
 	hp->prxbuf = l;
 	if (i > 0) {
-		http_rxchar(hp, i);
+		(void)http_rxchar(hp, i, 0);
 		vtc_dump(hp->vl, 4, "chunk",
 		    hp->rxbuf + l, i);
 	}
 	l = hp->prxbuf;
-	http_rxchar(hp, 2);
+	(void)http_rxchar(hp, 2, 0);
 	if(!vct_iscrlf(hp->rxbuf[l]))
 		vtc_log(hp->vl, 0,
 		    "Wrong chunk tail[0] = %02x",
@@ -433,7 +426,7 @@ http_swallow_body(struct http *hp, char * const *hh, int body)
 	p = http_find_header(hh, "content-length");
 	if (p != NULL) {
 		l = strtoul(p, NULL, 0);
-		http_rxchar(hp, l);
+		(void)http_rxchar(hp, l, 0);
 		vtc_dump(hp->vl, 4, "body", hp->body, l);
 		hp->bodyl = l;
 		sprintf(hp->bodylen, "%d", l);
@@ -452,7 +445,7 @@ http_swallow_body(struct http *hp, char * const *hh, int body)
 	if (body) {
 		hp->body = hp->rxbuf + hp->prxbuf;
 		do  {
-			i = http_rxchar_eof(hp, 1);
+			i = http_rxchar(hp, 1, 1);
 			ll += i;
 		} while (i > 0);
 		vtc_dump(hp->vl, 4, "rxeof", hp->body, ll);
@@ -475,7 +468,7 @@ http_rxhdr(struct http *hp)
 	hp->prxbuf = 0;
 	hp->body = NULL;
 	while (1) {
-		http_rxchar(hp, 1);
+		(void)http_rxchar(hp, 1, 0);
 		p = hp->rxbuf + hp->prxbuf - 1;
 		for (i = 0; p > hp->rxbuf; p--) {
 			if (*p != '\n')
@@ -533,7 +526,7 @@ cmd_http_rxresp(CMD_ARGS)
 
 #define TRUST_ME(ptr)   ((void*)(uintptr_t)(ptr))
 
-#define OVERHEAD 64
+#define OVERHEAD 64L
 
 
 static void
@@ -942,7 +935,7 @@ cmd_http_sendhex(CMD_ARGS)
 		if (!vct_ishex(buf[0]) || !vct_ishex(buf[1]))
 			vtc_log(hp->vl, 0, "Illegal Hex char \"%c%c\"",
 			    buf[0], buf[1]);
-		p[i] = strtoul(buf, NULL, 16);
+		p[i] = (uint8_t)strtoul(buf, NULL, 16);
 	}
 	vtc_hexdump(hp->vl, 4, "sendhex", (void*)p, i);
 	j = write(hp->fd, p, i);



More information about the varnish-commit mailing list