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); ...@@ -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); int VGZ_Gunzip(struct vgz *, const void **, size_t *len);
void VGZ_Destroy(struct vgz **); void VGZ_Destroy(struct vgz **);
void VGZ_UpdateObj(const struct vgz*, struct object *); 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 */ /* Return values */
#define VGZ_ERROR -1 #define VGZ_ERROR -1
......
...@@ -320,21 +320,9 @@ ESI_Deliver(struct sess *sp) ...@@ -320,21 +320,9 @@ ESI_Deliver(struct sess *sp)
* A gzip'ed VEC, but ungzip'ed ESI response * A gzip'ed VEC, but ungzip'ed ESI response
*/ */
AN(vgz); AN(vgz);
VGZ_Ibuf(vgz, st->ptr + off, l); i = VGZ_WrwGunzip(sp, vgz,
do { st->ptr + off, l,
VGZ_Obuf(vgz, obuf + obufl, obuf, sizeof 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));
assert (i == VGZ_OK || i == VGZ_END); assert (i == VGZ_OK || i == VGZ_END);
} else { } else {
/* /*
......
...@@ -350,6 +350,40 @@ VGZ_Gzip(struct vgz *vg, const void **pptr, size_t *plen, enum vgz_flag flags) ...@@ -350,6 +350,40 @@ VGZ_Gzip(struct vgz *vg, const void **pptr, size_t *plen, enum vgz_flag flags)
return (-1); 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 void
......
...@@ -245,15 +245,15 @@ res_WriteGunzipObj(struct sess *sp) ...@@ -245,15 +245,15 @@ res_WriteGunzipObj(struct sess *sp)
struct storage *st; struct storage *st;
unsigned u = 0; unsigned u = 0;
struct vgz *vg; struct vgz *vg;
const void *dp;
char obuf[params->gzip_stack_buffer]; char obuf[params->gzip_stack_buffer];
size_t dl; ssize_t obufl = 0;
int i; int i;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
vg = VGZ_NewUngzip(sp, "U D -"); vg = VGZ_NewUngzip(sp, "U D -");
VGZ_Obuf(vg, obuf, sizeof obuf);
VTAILQ_FOREACH(st, &sp->obj->store, list) { VTAILQ_FOREACH(st, &sp->obj->store, list) {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
...@@ -262,17 +262,14 @@ res_WriteGunzipObj(struct sess *sp) ...@@ -262,17 +262,14 @@ res_WriteGunzipObj(struct sess *sp)
sp->acct_tmp.bodybytes += st->len; /* XXX ? */ sp->acct_tmp.bodybytes += st->len; /* XXX ? */
VSC_main->n_objwrite++; VSC_main->n_objwrite++;
VGZ_Ibuf(vg, st->ptr, st->len); i = VGZ_WrwGunzip(sp, vg,
do { st->ptr, st->len,
VGZ_Obuf(vg, obuf, sizeof obuf); obuf, sizeof obuf, &obufl);
i = VGZ_Gunzip(vg, &dp, &dl); /* XXX: error check */
assert(i >= VGZ_OK); }
if (dl != 0) { if (obufl) {
(void)WRW_Write(sp->wrk, dp, dl); (void)WRW_Write(sp->wrk, obuf, obufl);
if (WRW_Flush(sp->wrk)) WRW_Flush(sp->wrk);
break;
}
} while (!VGZ_IbufEmpty(vg));
} }
VGZ_Destroy(&vg); VGZ_Destroy(&vg);
assert(u == sp->obj->len); 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