Commit 4fac23da authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Unify the task of gunzip'ing a chunk of data and putting it in

a buf to be flushed to WRW.
parent 9434db57
......@@ -689,6 +689,8 @@ int VGZ_Gzip(struct vgz *, const void **, size_t *len, enum vgz_flag);
int VGZ_Gunzip(struct vgz *, const void **, size_t *len);
void VGZ_Destroy(struct vgz **);
void VGZ_UpdateObj(const struct vgz*, struct object *);
int VGZ_WrwGunzip(struct sess *, struct vgz *, void *ibuf, ssize_t ibufl,
char *obuf, ssize_t obufl, ssize_t *obufp);
/* Return values */
#define VGZ_ERROR -1
......
......@@ -320,21 +320,9 @@ ESI_Deliver(struct sess *sp)
* A gzip'ed VEC, but ungzip'ed ESI response
*/
AN(vgz);
VGZ_Ibuf(vgz, st->ptr + off, l);
do {
VGZ_Obuf(vgz, obuf + obufl,
sizeof obuf - obufl);
i = VGZ_Gunzip(vgz, &dp, &dl);
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));
i = VGZ_WrwGunzip(sp, vgz,
st->ptr + off, l,
obuf, sizeof obuf, &obufl);
assert (i == VGZ_OK || i == VGZ_END);
} else {
/*
......
......@@ -350,6 +350,40 @@ VGZ_Gzip(struct vgz *vg, const void **pptr, size_t *plen, enum vgz_flag flags)
return (-1);
}
/*--------------------------------------------------------------------
* Gunzip ibuf into outb, if it runs full, emit it with WRW.
* Leave flushing to caller, more data may be coming.
*/
int
VGZ_WrwGunzip(struct sess *sp, struct vgz *vg, void *ibuf, ssize_t ibufl,
char *obuf, ssize_t obufl, ssize_t *obufp)
{
int i;
size_t dl;
const void *dp;
CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
VGZ_Ibuf(vg, ibuf, ibufl);
VGZ_Obuf(vg, obuf + *obufp, ibufl - *obufp);
do {
i = VGZ_Gunzip(vg, &dp, &dl);
if (i < VGZ_OK) {
/* XXX: VSL ? */
return (-1);
}
*obufp += dl;
if (obufl == *obufp || i == VGZ_STUCK) {
WRW_Write(sp->wrk, obuf, *obufp);
if (WRW_Flush(sp->wrk))
return (-1);
*obufp = 0;
VGZ_Obuf(vg, obuf + *obufp, ibufl - *obufp);
}
} while (!VGZ_IbufEmpty(vg));
return (i);
}
/*--------------------------------------------------------------------*/
void
......
......@@ -245,15 +245,15 @@ res_WriteGunzipObj(struct sess *sp)
struct storage *st;
unsigned u = 0;
struct vgz *vg;
const void *dp;
char obuf[params->gzip_stack_buffer];
size_t dl;
ssize_t obufl = 0;
int i;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
vg = VGZ_NewUngzip(sp, "U D -");
VGZ_Obuf(vg, obuf, sizeof obuf);
VTAILQ_FOREACH(st, &sp->obj->store, list) {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
......@@ -262,17 +262,14 @@ res_WriteGunzipObj(struct sess *sp)
sp->acct_tmp.bodybytes += st->len; /* XXX ? */
VSC_main->n_objwrite++;
VGZ_Ibuf(vg, st->ptr, st->len);
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;
}
} while (!VGZ_IbufEmpty(vg));
i = VGZ_WrwGunzip(sp, vg,
st->ptr, st->len,
obuf, sizeof obuf, &obufl);
/* XXX: error check */
}
if (obufl) {
(void)WRW_Write(sp->wrk, obuf, obufl);
WRW_Flush(sp->wrk);
}
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