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

Buffer the pending bytes until we need them.

parent ee4a4eec
...@@ -138,6 +138,8 @@ struct vef_priv { ...@@ -138,6 +138,8 @@ struct vef_priv {
char *bufp; char *bufp;
ssize_t tot; ssize_t tot;
int error; int error;
char pending[20];
ssize_t npend;
}; };
/*--------------------------------------------------------------------- /*---------------------------------------------------------------------
...@@ -148,7 +150,7 @@ static ssize_t ...@@ -148,7 +150,7 @@ static ssize_t
vfp_vep_callback(const struct sess *sp, ssize_t l, enum vgz_flag flg) vfp_vep_callback(const struct sess *sp, ssize_t l, enum vgz_flag flg)
{ {
struct vef_priv *vef; struct vef_priv *vef;
size_t dl; size_t dl, px;
const void *dp; const void *dp;
int i; int i;
...@@ -162,15 +164,29 @@ vfp_vep_callback(const struct sess *sp, ssize_t l, enum vgz_flag flg) ...@@ -162,15 +164,29 @@ vfp_vep_callback(const struct sess *sp, ssize_t l, enum vgz_flag flg)
return (vef->tot); return (vef->tot);
} }
/* This would just give Z_BUF_ERROR anyway */ /*
* l == 0 is valid when 'flg' calls for action, but in the
* normal case we can just ignore a l==0 request.
* (It would cause Z_BUF_ERROR anyway)
*/
if (l == 0 && flg == VGZ_NORMAL) if (l == 0 && flg == VGZ_NORMAL)
return (vef->tot); return (vef->tot);
printf("xxC %jd\n", l); do {
px = vef->npend;
if (l < px)
px = l;
if (px != 0) {
VGZ_Ibuf(vef->vgz, vef->pending, px);
l -= px;
} else {
VGZ_Ibuf(vef->vgz, vef->bufp, l); VGZ_Ibuf(vef->vgz, vef->bufp, l);
vef->bufp += l;
l = 0;
}
do { do {
if (VGZ_ObufStorage(sp, vef->vgz)) { if (VGZ_ObufStorage(sp, vef->vgz)) {
vef->error = ENOMEM; vef->error = errno;
vef->tot += l; vef->tot += l;
return (vef->tot); return (vef->tot);
} }
...@@ -178,7 +194,12 @@ printf("xxC %jd\n", l); ...@@ -178,7 +194,12 @@ printf("xxC %jd\n", l);
vef->tot += dl; vef->tot += dl;
sp->obj->len += dl; sp->obj->len += dl;
} while (!VGZ_IbufEmpty(vef->vgz)); } while (!VGZ_IbufEmpty(vef->vgz));
vef->bufp += l; if (px != 0) {
memmove(vef->pending, vef->pending + px,
vef->npend - px);
vef->npend -= px;
}
} while (l > 0);
if (flg == VGZ_FINISH) if (flg == VGZ_FINISH)
assert(i == 1); /* XXX */ assert(i == 1); /* XXX */
else else
...@@ -203,13 +224,17 @@ vfp_esi_bytes_ug(struct sess *sp, struct http_conn *htc, ssize_t bytes) ...@@ -203,13 +224,17 @@ vfp_esi_bytes_ug(struct sess *sp, struct http_conn *htc, ssize_t bytes)
return (w); return (w);
bytes -= w; bytes -= w;
vef->bufp = ibuf; vef->bufp = ibuf;
printf("xxP %jd\n", w);
VEP_parse(sp, ibuf, w); VEP_parse(sp, ibuf, w);
if (vef->error) { if (vef->error) {
errno = vef->error; errno = vef->error;
return (-1); return (-1);
} }
assert(vef->bufp == ibuf + w); if (vef->bufp < ibuf + w) {
w = (ibuf + w) - vef->bufp;
assert(w + vef->npend < sizeof vef->pending);
memcpy(vef->pending + vef->npend, vef->bufp, w);
vef->npend += w;
}
} }
return (1); return (1);
} }
......
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