Commit 92d43d17 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add FetchStorage() which will feed storage segments into objects

via sp->wrk->storage.
parent 76c392cc
...@@ -619,6 +619,7 @@ void EXP_Touch(struct object *o, double tnow); ...@@ -619,6 +619,7 @@ void EXP_Touch(struct object *o, double tnow);
int EXP_NukeOne(const struct sess *sp, const struct lru *lru); int EXP_NukeOne(const struct sess *sp, const struct lru *lru);
/* cache_fetch.c */ /* cache_fetch.c */
int FetchStorage(const struct sess *sp);
int FetchHdr(struct sess *sp); int FetchHdr(struct sess *sp);
int FetchBody(struct sess *sp); int FetchBody(struct sess *sp);
int FetchReqBody(struct sess *sp); int FetchReqBody(struct sess *sp);
......
...@@ -55,14 +55,8 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes) ...@@ -55,14 +55,8 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
while (bytes > 0) { while (bytes > 0) {
if (sp->wrk->storage == NULL) { if (FetchStorage(sp))
l = params->fetch_chunksize * 1024LL;
sp->wrk->storage = STV_alloc(sp, l);
}
if (sp->wrk->storage == NULL) {
errno = ENOMEM;
return (-1); return (-1);
}
st = sp->wrk->storage; st = sp->wrk->storage;
l = st->space - st->len; l = st->space - st->len;
if (l > bytes) if (l > bytes)
...@@ -83,12 +77,6 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes) ...@@ -83,12 +77,6 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes)
VEP_parse(sp, (const char *)st->ptr + st->len, w); VEP_parse(sp, (const char *)st->ptr + st->len, w);
st->len += w; st->len += w;
sp->obj->len += w; sp->obj->len += w;
if (st->len == st->space) {
VTAILQ_INSERT_TAIL(&sp->obj->store,
sp->wrk->storage, list);
sp->wrk->storage = NULL;
st = NULL;
}
bytes -= w; bytes -= w;
} }
return (1); return (1);
...@@ -205,14 +193,6 @@ vfp_esi_bytes_ug(struct sess *sp, struct http_conn *htc, size_t bytes) ...@@ -205,14 +193,6 @@ vfp_esi_bytes_ug(struct sess *sp, struct http_conn *htc, size_t bytes)
CHECK_OBJ_NOTNULL(vef, VEF_MAGIC); CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
while (bytes > 0) { while (bytes > 0) {
if (sp->wrk->storage == NULL) {
l = params->fetch_chunksize * 1024LL;
sp->wrk->storage = STV_alloc(sp, l);
}
if (sp->wrk->storage == NULL) {
errno = ENOMEM;
return (-1);
}
l = sizeof ibuf; l = sizeof ibuf;
if (l > bytes) if (l > bytes)
l = bytes; l = bytes;
......
...@@ -91,16 +91,8 @@ vfp_nop_bytes(struct sess *sp, struct http_conn *htc, size_t bytes) ...@@ -91,16 +91,8 @@ vfp_nop_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
struct storage *st; struct storage *st;
while (bytes > 0) { while (bytes > 0) {
if (sp->wrk->storage == NULL) { if (FetchStorage(sp))
l = fetchfrag;
if (l == 0)
l = params->fetch_chunksize * 1024LL;
sp->wrk->storage = STV_alloc(sp, l);
}
if (sp->wrk->storage == NULL) {
errno = ENOMEM;
return (-1); return (-1);
}
st = sp->wrk->storage; st = sp->wrk->storage;
l = st->space - st->len; l = st->space - st->len;
if (l > bytes) if (l > bytes)
...@@ -110,12 +102,6 @@ vfp_nop_bytes(struct sess *sp, struct http_conn *htc, size_t bytes) ...@@ -110,12 +102,6 @@ vfp_nop_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
return (w); return (w);
st->len += w; st->len += w;
sp->obj->len += w; sp->obj->len += w;
if (st->len == st->space) {
VTAILQ_INSERT_TAIL(&sp->obj->store,
sp->wrk->storage, list);
sp->wrk->storage = NULL;
st = NULL;
}
bytes -= w; bytes -= w;
} }
return (1); return (1);
...@@ -156,6 +142,33 @@ static struct vfp vfp_nop = { ...@@ -156,6 +142,33 @@ static struct vfp vfp_nop = {
.end = vfp_nop_end, .end = vfp_nop_end,
}; };
/*--------------------------------------------------------------------
* Fetch Storage
*/
int
FetchStorage(const struct sess *sp)
{
ssize_t l;
if (sp->wrk->storage != NULL &&
sp->wrk->storage->len == sp->wrk->storage->space) {
VTAILQ_INSERT_TAIL(&sp->obj->store, sp->wrk->storage, list);
sp->wrk->storage = NULL;
}
if (sp->wrk->storage == NULL) {
l = fetchfrag;
if (l == 0)
l = params->fetch_chunksize * 1024LL;
sp->wrk->storage = STV_alloc(sp, l);
}
if (sp->wrk->storage == NULL) {
errno = ENOMEM;
return (-1);
}
return (0);
}
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Convert a string to a size_t safely * Convert a string to a size_t safely
*/ */
......
...@@ -231,21 +231,10 @@ VGZ_ObufStorage(const struct sess *sp, struct vgz *vg) ...@@ -231,21 +231,10 @@ VGZ_ObufStorage(const struct sess *sp, struct vgz *vg)
{ {
struct storage *st; struct storage *st;
if (FetchStorage(sp))
return (-1);
st = sp->wrk->storage; st = sp->wrk->storage;
if (st != NULL && st->len == st->space) {
VTAILQ_INSERT_TAIL(&sp->obj->store, st, list);
sp->wrk->storage = NULL;
st = NULL;
vg->obuf = NULL;
}
if (st == NULL) {
st = STV_alloc(sp, params->fetch_chunksize * 1024LL);
if (st == NULL) {
errno = ENOMEM;
return (-1);
}
sp->wrk->storage = st;
}
vg->obuf = st; vg->obuf = st;
VGZ_Obuf(vg, st->ptr + st->len, st->space - st->len); VGZ_Obuf(vg, st->ptr + st->len, st->space - st->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