Commit fd0ff2b0 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Be more systematic about the returns from VGZ_Unzip() and pay attention

to the VGZ_STUCK indication.

Hopefully helps with #869
parent 149fde92
......@@ -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);
......
......@@ -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
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment