[master] 73b465a Integrate stream_ctx in struct req
Poul-Henning Kamp
phk at varnish-cache.org
Mon Feb 13 13:53:05 CET 2012
commit 73b465a073968e22ed13c448178594515ac3a6d9
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Feb 13 12:52:49 2012 +0000
Integrate stream_ctx in struct req
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 162cbe9..e76b0de 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -257,21 +257,6 @@ struct wrw {
/*--------------------------------------------------------------------*/
-struct stream_ctx {
- unsigned magic;
-#define STREAM_CTX_MAGIC 0x8213728b
-
- struct vgz *vgz;
-
- /* Next byte we will take from storage */
- ssize_t stream_next;
-
- /* First byte of storage if we free it as we go (pass) */
- ssize_t stream_front;
-};
-
-/*--------------------------------------------------------------------*/
-
struct wrk_accept {
unsigned magic;
#define WRK_ACCEPT_MAGIC 0x8c4b4d59
@@ -335,9 +320,6 @@ struct worker {
struct busyobj *busyobj;
- /* Stream state */
- struct stream_ctx *sctx;
-
/* Timeouts */
double connect_timeout;
double first_byte_timeout;
@@ -626,6 +608,15 @@ struct req {
#define RES_ESI_CHILD (1<<5)
#define RES_GUNZIP (1<<6)
+ /* Stream gunzip instance */
+ struct vgz *stream_vgz;
+
+ /* Next byte we will take from storage */
+ ssize_t stream_next;
+
+ /* First byte of storage if we free it as we go (pass) */
+ ssize_t stream_front;
+
};
/*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 826e1d7..fca55b0 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -940,17 +940,12 @@ static int
cnt_streambody(struct sess *sp, struct worker *wrk, struct req *req)
{
int i;
- struct stream_ctx sctx;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
- memset(&sctx, 0, sizeof sctx);
- sctx.magic = STREAM_CTX_MAGIC;
- AZ(wrk->sctx);
- wrk->sctx = &sctx;
RES_StreamStart(sp);
@@ -978,7 +973,6 @@ cnt_streambody(struct sess *sp, struct worker *wrk, struct req *req)
RES_StreamEnd(sp);
- wrk->sctx = NULL;
assert(WRW_IsReleased(wrk));
assert(wrk->wrw.ciov == wrk->wrw.siov);
(void)HSH_Deref(wrk, NULL, &req->obj);
diff --git a/bin/varnishd/cache/cache_response.c b/bin/varnishd/cache/cache_response.c
index d560211..5e4cab6 100644
--- a/bin/varnishd/cache/cache_response.c
+++ b/bin/varnishd/cache/cache_response.c
@@ -316,23 +316,26 @@ RES_WriteObj(struct sess *sp)
void
RES_StreamStart(struct sess *sp)
{
- struct stream_ctx *sctx;
+ struct req *req;
- sctx = sp->wrk->sctx;
- CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC);
+ req = sp->req;
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- AZ(sp->req->res_mode & RES_ESI_CHILD);
- AN(sp->req->wantbody);
+ AZ(req->res_mode & RES_ESI_CHILD);
+ AN(req->wantbody);
+ AZ(req->stream_vgz);
+ AZ(req->stream_next);
+ AZ(req->stream_front);
WRW_Reserve(sp->wrk, &sp->fd);
- if (sp->req->res_mode & RES_GUNZIP) {
- sctx->vgz = VGZ_NewUngzip(sp->wrk, "U S -");
- AZ(VGZ_WrwInit(sctx->vgz));
- http_Unset(sp->req->resp, H_Content_Encoding);
+ if (req->res_mode & RES_GUNZIP) {
+ req->stream_vgz = VGZ_NewUngzip(sp->wrk, "U S -");
+ AZ(VGZ_WrwInit(req->stream_vgz));
+ http_Unset(req->resp, H_Content_Encoding);
}
- if (!(sp->req->res_mode & RES_CHUNKED) &&
+ if (!(req->res_mode & RES_CHUNKED) &&
sp->wrk->busyobj->h_content_length != NULL)
http_PrintfHeader(sp->wrk, sp->vsl_id, sp->req->resp,
"Content-Length: %s", sp->wrk->busyobj->h_content_length);
@@ -340,57 +343,59 @@ RES_StreamStart(struct sess *sp)
sp->wrk->acct_tmp.hdrbytes +=
http_Write(sp->wrk, sp->vsl_id, sp->req->resp, 1);
- if (sp->req->res_mode & RES_CHUNKED)
+ if (req->res_mode & RES_CHUNKED)
WRW_Chunked(sp->wrk);
}
void
RES_StreamPoll(struct worker *wrk)
{
- struct stream_ctx *sctx;
struct storage *st;
+ struct busyobj *bo;
+ struct req *req;
ssize_t l, l2;
void *ptr;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
- CHECK_OBJ_NOTNULL(wrk->busyobj->fetch_obj, OBJECT_MAGIC);
- sctx = wrk->sctx;
- CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC);
- if (wrk->busyobj->fetch_obj->len == sctx->stream_next)
+ bo = wrk->busyobj;
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+ CHECK_OBJ_NOTNULL(bo->fetch_obj, OBJECT_MAGIC);
+ req = wrk->sp->req;
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ if (bo->fetch_obj->len == req->stream_next)
return;
- assert(wrk->busyobj->fetch_obj->len > sctx->stream_next);
- l = sctx->stream_front;
- VTAILQ_FOREACH(st, &wrk->busyobj->fetch_obj->store, list) {
- if (st->len + l <= sctx->stream_next) {
+ assert(bo->fetch_obj->len > req->stream_next);
+ l = req->stream_front;
+ VTAILQ_FOREACH(st, &bo->fetch_obj->store, list) {
+ if (st->len + l <= req->stream_next) {
l += st->len;
continue;
}
- l2 = st->len + l - sctx->stream_next;
- ptr = st->ptr + (sctx->stream_next - l);
- if (wrk->sp->req->res_mode & RES_GUNZIP) {
- (void)VGZ_WrwGunzip(wrk, sctx->vgz, ptr, l2);
- } else {
+ l2 = st->len + l - req->stream_next;
+ ptr = st->ptr + (req->stream_next - l);
+ if (wrk->sp->req->res_mode & RES_GUNZIP)
+ (void)VGZ_WrwGunzip(wrk, req->stream_vgz, ptr, l2);
+ else
(void)WRW_Write(wrk, ptr, l2);
- }
l += st->len;
- sctx->stream_next += l2;
+ req->stream_next += l2;
}
if (!(wrk->sp->req->res_mode & RES_GUNZIP))
(void)WRW_Flush(wrk);
- if (wrk->busyobj->fetch_obj->objcore == NULL ||
- (wrk->busyobj->fetch_obj->objcore->flags & OC_F_PASS)) {
+ if (bo->fetch_obj->objcore == NULL ||
+ (bo->fetch_obj->objcore->flags & OC_F_PASS)) {
/*
* This is a pass object, release storage as soon as we
* have delivered it.
*/
while (1) {
- st = VTAILQ_FIRST(&wrk->busyobj->fetch_obj->store);
+ st = VTAILQ_FIRST(&bo->fetch_obj->store);
if (st == NULL ||
- sctx->stream_front + st->len > sctx->stream_next)
+ req->stream_front + st->len > req->stream_next)
break;
- VTAILQ_REMOVE(&wrk->busyobj->fetch_obj->store, st, list);
- sctx->stream_front += st->len;
+ VTAILQ_REMOVE(&bo->fetch_obj->store, st, list);
+ req->stream_front += st->len;
STV_free(st);
}
}
@@ -399,19 +404,21 @@ RES_StreamPoll(struct worker *wrk)
void
RES_StreamEnd(struct sess *sp)
{
- struct stream_ctx *sctx;
+ struct req *req;
- sctx = sp->wrk->sctx;
- CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC);
+ req = sp->req;
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- if (sp->req->res_mode & RES_GUNZIP) {
- AN(sctx->vgz);
- VGZ_WrwFlush(sp->wrk, sctx->vgz);
- (void)VGZ_Destroy(&sctx->vgz, sp->vsl_id);
+ if (req->res_mode & RES_GUNZIP) {
+ AN(req->stream_vgz);
+ VGZ_WrwFlush(sp->wrk, req->stream_vgz);
+ (void)VGZ_Destroy(&req->stream_vgz, sp->vsl_id);
}
- if (sp->req->res_mode & RES_CHUNKED &&
- !(sp->req->res_mode & RES_ESI_CHILD))
+ if (req->res_mode & RES_CHUNKED && !(req->res_mode & RES_ESI_CHILD))
WRW_EndChunk(sp->wrk);
if (WRW_FlushRelease(sp->wrk))
SES_Close(sp, "remote closed");
+ req->stream_vgz = NULL;
+ req->stream_next = 0;
+ req->stream_front = 0;
}
More information about the varnish-commit
mailing list