[master] ccf21a3 make VRB_Iterate return the length iterated over

Nils Goroll nils.goroll at uplex.de
Wed Mar 4 16:16:28 CET 2015


commit ccf21a3d0d997d396cb708ee84a2dd1b6d7d769a
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Mar 4 15:49:35 2015 +0100

    make VRB_Iterate return the length iterated over

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 46b410b..d20222c 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -761,7 +761,7 @@ void V1P_Process(struct req *req, struct busyobj *bo, int fd);
 /* cache_req_body.c */
 int VRB_Ignore(struct req *req);
 int VRB_Cache(struct req *req, ssize_t maxsize);
-int VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv);
+ssize_t VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv);
 void VRB_Free(struct req *req);
 
 /* cache_req_fsm.c [CNT] */
diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c
index 5c8f08c..6e77bc8 100644
--- a/bin/varnishd/cache/cache_req_body.c
+++ b/bin/varnishd/cache/cache_req_body.c
@@ -42,13 +42,15 @@
  *
  * This can be done exactly once if uncached, and multiple times if the
  * req.body is cached.
+ *
+ * return length or -1 on error
  */
 
-int
+ssize_t
 VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv)
 {
 	char buf[8192];
-	ssize_t l;
+	ssize_t l, ll = 0;
 	void *p;
 	int i;
 	struct vfp_ctx *vfc;
@@ -65,11 +67,12 @@ VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv)
 		AN(oi);
 		do {
 			ois = ObjIter(req->body_oc, oi, &p, &l);
+			ll += l;
 			if (l > 0 && func(req, priv, p, l))
 				break;
 		} while (ois == OIS_DATA);
 		ObjIterEnd(req->body_oc, &oi);
-		return (ois == OIS_DONE ? 0 : -1);
+		return (ois == OIS_DONE ? ll : -1);
 	case REQ_BODY_NONE:
 		return (0);
 	case REQ_BODY_WITH_LEN:
@@ -116,14 +119,16 @@ VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv)
 		vfps = VFP_Suck(vfc, buf, &l);
 		if (vfps == VFP_ERROR) {
 			req->req_body_status = REQ_BODY_FAIL;
-			l = -1;
+			ll = -1;
 			break;
 		} else if (l > 0) {
 			req->req_bodybytes += l;
 			req->acct.req_bodybytes += l;
+			ll += l;
 			l = func(req, priv, buf, l);
 			if (l) {
 				req->req_body_status = REQ_BODY_FAIL;
+				ll = -1;
 				break;
 			}
 		}
@@ -131,7 +136,7 @@ VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv)
 	VFP_Close(vfc);
 	VSLb_ts_req(req, "ReqBody", VTIM_real());
 
-	return (l);
+	return (ll);
 }
 
 /*----------------------------------------------------------------------
diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c
index 685f2e7..d776430 100644
--- a/bin/varnishd/http1/cache_http1_fetch.c
+++ b/bin/varnishd/http1/cache_http1_fetch.c
@@ -77,7 +77,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host)
 	struct http *hp;
 	enum http1_status_e hs;
 	int retry = 1;
-	int i, j, first;
+	int j, first;
+	ssize_t i;
 	struct http_conn *htc;
 	int do_chunked = 0;
 
@@ -129,7 +130,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host)
 	}
 
 	j = V1L_FlushRelease(wrk);
-	if (j != 0 || i != 0) {
+	if (j != 0 || i < 0) {
 		VSLb(bo->vsl, SLT_FetchError, "backend write error: %d (%s)",
 		    errno, strerror(errno));
 		VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk));



More information about the varnish-commit mailing list