[master] fd0ff2b Be more systematic about the returns from VGZ_Unzip() and pay attention to the VGZ_STUCK indication.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Mar 28 23:42:23 CEST 2011
commit fd0ff2b08aeb5dfe0f25cc2503f39fc8f287f230
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Mar 28 21:41:35 2011 +0000
Be more systematic about the returns from VGZ_Unzip() and pay attention
to the VGZ_STUCK indication.
Hopefully helps with #869
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 66a4de7..9bb84e6 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -690,6 +690,12 @@ int VGZ_Gunzip(struct vgz *, const void **, size_t *len);
void VGZ_Destroy(struct vgz **);
void VGZ_UpdateObj(const struct vgz*, struct object *);
+/* Return values */
+#define VGZ_ERROR -1
+#define VGZ_OK 0
+#define VGZ_END 1
+#define VGZ_STUCK 2
+
/* cache_http.c */
unsigned HTTP_estimate(unsigned nhttp);
void HTTP_Copy(struct http *to, const struct http * const fm);
diff --git a/bin/varnishd/cache_esi_deliver.c b/bin/varnishd/cache_esi_deliver.c
index 22cb765..509649f 100644
--- a/bin/varnishd/cache_esi_deliver.c
+++ b/bin/varnishd/cache_esi_deliver.c
@@ -274,7 +274,7 @@ ESI_Deliver(struct sess *sp)
VGZ_Ibuf(vgz, gzip_hdr, sizeof gzip_hdr);
VGZ_Obuf(vgz, obuf, sizeof obuf);
i = VGZ_Gunzip(vgz, &dp, &dl);
- assert(i == Z_OK || i == Z_STREAM_END);
+ assert(i == VGZ_OK);
assert(VGZ_IbufEmpty(vgz));
assert(dl == 0);
@@ -321,16 +321,20 @@ ESI_Deliver(struct sess *sp)
AN(vgz);
VGZ_Ibuf(vgz, st->ptr + off, l);
do {
- if (obufl == sizeof obuf) {
- WRW_Write(sp->wrk, obuf, obufl);
- obufl = 0;
- }
VGZ_Obuf(vgz, obuf + obufl,
sizeof obuf - obufl);
i = VGZ_Gunzip(vgz, &dp, &dl);
- assert(i == Z_OK || i == Z_STREAM_END);
+ assert(i >= VGZ_OK);
obufl += dl;
+ assert(obufl <= sizeof obuf);
+ if (obufl == sizeof obuf ||
+ i == VGZ_STUCK) {
+ WRW_Write(sp->wrk, obuf, obufl);
+ WRW_Flush(sp->wrk);
+ obufl = 0;
+ }
} while (!VGZ_IbufEmpty(vgz));
+ assert (i == VGZ_OK || i == VGZ_END);
} else {
/*
* Ungzip'ed VEC, ungzip'ed ESI response
diff --git a/bin/varnishd/cache_esi_fetch.c b/bin/varnishd/cache_esi_fetch.c
index b80de68..8c94460 100644
--- a/bin/varnishd/cache_esi_fetch.c
+++ b/bin/varnishd/cache_esi_fetch.c
@@ -39,7 +39,6 @@ SVNID("$Id")
#include "cache.h"
#include "cache_esi.h"
#include "vct.h"
-#include "vgz.h"
#include "stevedore.h"
/*---------------------------------------------------------------------
@@ -120,7 +119,7 @@ vfp_esi_bytes_gu(struct sess *sp, struct http_conn *htc, ssize_t bytes)
if (VGZ_ObufStorage(sp, vg))
return (-1);
i = VGZ_Gunzip(vg, &dp, &dl);
- xxxassert(i == Z_OK || i == Z_STREAM_END);
+ xxxassert(i == VGZ_OK || i == VGZ_END);
VEP_parse(sp, dp, dl);
sp->obj->len += dl;
}
@@ -274,7 +273,7 @@ vfp_esi_bytes_gg(struct sess *sp, struct http_conn *htc, size_t bytes)
VGZ_Obuf(sp->wrk->vgz_rx, ibuf2, sizeof ibuf2);
i = VGZ_Gunzip(sp->wrk->vgz_rx, &dp, &dl);
/* XXX: check i */
- assert(i >= 0);
+ assert(i >= VGZ_OK);
vef->bufp = ibuf2;
if (dl > 0)
VEP_parse(sp, ibuf2, dl);
diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index 61b083c..69fdb44 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -300,13 +300,13 @@ VGZ_Gunzip(struct vgz *vg, const void **pptr, size_t *plen)
vg->obuf->len += l;
}
if (i == Z_OK)
- return (0);
+ return (VGZ_OK);
if (i == Z_STREAM_END)
- return (1);
+ return (VGZ_END);
if (i == Z_BUF_ERROR)
- return (2);
+ return (VGZ_STUCK);
printf("INFLATE=%d (%s)\n", i, vg->vz.msg);
- return (-1);
+ return (VGZ_ERROR);
}
/*--------------------------------------------------------------------*/
@@ -432,7 +432,7 @@ vfp_gunzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
if (VGZ_ObufStorage(sp, vg))
return (-1);
i = VGZ_Gunzip(vg, &dp, &dl);
- assert(i == Z_OK || i == Z_STREAM_END);
+ assert(i == VGZ_OK || i == VGZ_END);
sp->obj->len += dl;
}
if (i == Z_OK || i == Z_STREAM_END)
@@ -584,7 +584,7 @@ vfp_testgzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
while (!VGZ_IbufEmpty(vg)) {
VGZ_Obuf(vg, ibuf, sizeof ibuf);
i = VGZ_Gunzip(vg, &dp, &dl);
- if (i != Z_OK && i != Z_STREAM_END) {
+ if (i != VGZ_OK && i != VGZ_END) {
WSP(sp, SLT_FetchError,
"Invalid Gzip data: %s", vg->vz.msg);
return (-1);
diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index 8098d64..c97ffea 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -266,13 +266,13 @@ res_WriteGunzipObj(struct sess *sp)
do {
VGZ_Obuf(vg, obuf, sizeof obuf);
i = VGZ_Gunzip(vg, &dp, &dl);
+ assert(i >= VGZ_OK);
if (dl != 0) {
(void)WRW_Write(sp->wrk, dp, dl);
if (WRW_Flush(sp->wrk))
break;
}
- assert(i >= 0);
- } while (i == 0);
+ } while (!VGZ_IbufEmpty(vg));
}
VGZ_Destroy(&vg);
assert(u == sp->obj->len);
More information about the varnish-commit
mailing list