r401 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Jul 10 12:06:21 CEST 2006


Author: phk
Date: 2006-07-10 12:06:21 +0200 (Mon, 10 Jul 2006)
New Revision: 401

Modified:
   trunk/varnish-cache/bin/varnishd/cache_http.c
Log:
Polish HTTP reception a little bit


Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-10 10:05:48 UTC (rev 400)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-10 10:06:21 UTC (rev 401)
@@ -279,10 +279,15 @@
 {
 	char *p;
 
+	assert(hp->v <= hp->e);
+	assert(*hp->v == '\0');
+	/* Skip any leading white space */
 	for (p = hp->s ; p < hp->v && isspace(*p); p++)
 		continue;
-	if (p >= hp->v)
+	if (p >= hp->v) {
+		hp->v = hp->s;
 		return (0);
+	}
 	while (1) {
 		/* XXX: we could save location of all linebreaks for later */
 		p = strchr(p, '\n');
@@ -312,46 +317,42 @@
 {
 	struct http *hp = arg;
 	unsigned l;
-	int i;
+	int i, ret = 0;
 
 	l = hp->e - hp->v;
 	if (l <= 1) {
+		VSL(SLT_HttpError, fd, "Received too much");
 		VSLR(SLT_Debug, fd, hp->s, hp->v);
 		hp->t = NULL;
-		event_del(&hp->ev);
-		if (hp->callback != NULL)
-			hp->callback(hp->arg, 1);
-		return;
+		ret = 1;
+	} else {
+		errno = 0;
+		i = read(fd, hp->v, l - 1);
+		if (i > 0) {
+			hp->v += i;
+			*hp->v = '\0';
+			if (!http_header_complete(hp))
+				return;
+		} else {
+			if (hp->v != hp->s) {
+				VSL(SLT_HttpError, fd,
+				    "Received (only) %d bytes, errno %d",
+				    hp->v - hp->s, errno);
+				VSLR(SLT_Debug, fd, hp->s, hp->v);
+			} else if (errno == 0)
+				VSL(SLT_HttpError, fd, "Received nothing");
+			else
+				VSL(SLT_HttpError, fd,
+				    "Received errno %d", errno);
+			hp->t = NULL;
+			ret = 2;
+		}
 	}
-	assert(l > 1);
-	errno = 0;
-	i = read(fd, hp->v, l - 1);
-	if (i <= 0) {
-		if (hp->v != hp->s)
-			VSL(SLT_HttpError, fd,
-			    "Received (only) %d bytes, errno %d",
-			    hp->v - hp->s, errno);
-		else if (errno == 0)
-			VSL(SLT_HttpError, fd, "Received nothing");
-		else
-			VSL(SLT_HttpError, fd, "Received errno %d", errno);
-		VSLR(SLT_Debug, fd, hp->s, hp->v);
-		hp->t = NULL;
-		event_del(&hp->ev);
-		if (hp->callback != NULL)
-			hp->callback(hp->arg, 2);
-		return;
-	}
 
-	hp->v += i;
-	*hp->v = '\0';
-	if (!http_header_complete(hp))
-		return;
-
-	assert(hp->t != NULL);
+	assert(hp->t != NULL || ret != 0);
 	event_del(&hp->ev);
 	if (hp->callback != NULL)
-		hp->callback(hp->arg, 0);
+		hp->callback(hp->arg, ret);
 }
 
 /*--------------------------------------------------------------------*/




More information about the varnish-commit mailing list