[master] fdbb6f0 Add a stream_context structure to hold the state for streaming when we need it.
Poul-Henning Kamp
phk at varnish-cache.org
Mon May 2 10:57:54 CEST 2011
commit fdbb6f0347c5d31aa81254aae9ca938e7bd5a731
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon May 2 08:40:00 2011 +0000
Add a stream_context structure to hold the state for streaming
when we need it.
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 7e9c0d9..adc76f3 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -247,7 +247,6 @@ struct exp {
/*--------------------------------------------------------------------*/
-/* WRW related fields */
struct wrw {
int *wfd;
unsigned werr; /* valid after WRK_Flush() */
@@ -259,6 +258,21 @@ struct wrw {
unsigned ciov; /* Chunked header marker */
};
+/*--------------------------------------------------------------------*/
+
+struct stream_ctx {
+ unsigned magic;
+#define STREAM_CTX_MAGIC 0x8213728b
+#if 0
+ struct vgz *vgz;
+ void *obuf;
+ ssize_t obuf_len;
+ ssize_t obuf_ptr;
+#endif
+ ssize_t stream_next;
+};
+
+/*--------------------------------------------------------------------*/
struct worker {
unsigned magic;
#define WORKER_MAGIC 0x6391adcf
@@ -312,7 +326,7 @@ struct worker {
char *h_content_length;
/* Stream state */
- ssize_t stream_next;
+ struct stream_ctx *sctx;
/* ESI stuff */
struct vep_state *vep;
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index de7632a..36fe329 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -839,6 +839,13 @@ static int
cnt_streambody(struct sess *sp)
{
int i;
+ struct stream_ctx sctx;
+
+
+ memset(&sctx, 0, sizeof sctx);
+ sctx.magic = STREAM_CTX_MAGIC;
+ AZ(sp->wrk->sctx);
+ sp->wrk->sctx = &sctx;
RES_StreamStart(sp);
@@ -854,6 +861,7 @@ cnt_streambody(struct sess *sp)
AN(sp->director);
if (i) {
+ sp->wrk->sctx = NULL;
HSH_Drop(sp);
AZ(sp->obj);
sp->err_code = 503;
@@ -873,6 +881,7 @@ cnt_streambody(struct sess *sp)
RES_StreamEnd(sp);
+ sp->wrk->sctx = NULL;
assert(WRW_IsReleased(sp->wrk));
assert(sp->wrk->wrw.ciov == sp->wrk->wrw.siov);
(void)HSH_Deref(sp->wrk, NULL, &sp->obj);
diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index 5ff645c..484ca1e 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -394,6 +394,10 @@ RES_WriteObj(struct sess *sp)
void
RES_StreamStart(struct sess *sp)
{
+ struct stream_ctx *sctx;
+
+ sctx = sp->wrk->sctx;
+ CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC);
AZ(sp->wrk->res_mode & RES_ESI_CHILD);
AN(sp->wantbody);
@@ -410,31 +414,32 @@ RES_StreamStart(struct sess *sp)
if (sp->wrk->res_mode & RES_CHUNKED)
WRW_Chunked(sp->wrk);
-
- sp->wrk->stream_next = 0;
}
void
RES_StreamPoll(const struct sess *sp)
{
+ struct stream_ctx *sctx;
struct storage *st;
ssize_t l, l2;
void *ptr;
- if (sp->obj->len == sp->wrk->stream_next)
+ sctx = sp->wrk->sctx;
+ CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC);
+ if (sp->obj->len == sctx->stream_next)
return;
- assert(sp->obj->len > sp->wrk->stream_next);
+ assert(sp->obj->len > sctx->stream_next);
l = 0;
VTAILQ_FOREACH(st, &sp->obj->store, list) {
- if (st->len + l <= sp->wrk->stream_next) {
+ if (st->len + l <= sctx->stream_next) {
l += st->len;
continue;
}
- l2 = st->len + l - sp->wrk->stream_next;
- ptr = st->ptr + (sp->wrk->stream_next - l);
+ l2 = st->len + l - sctx->stream_next;
+ ptr = st->ptr + (sctx->stream_next - l);
(void)WRW_Write(sp->wrk, ptr, l2);
l += st->len;
- sp->wrk->stream_next += l2;
+ sctx->stream_next += l2;
}
(void)WRW_Flush(sp->wrk);
}
@@ -442,6 +447,10 @@ RES_StreamPoll(const struct sess *sp)
void
RES_StreamEnd(struct sess *sp)
{
+ struct stream_ctx *sctx;
+
+ sctx = sp->wrk->sctx;
+ CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC);
if (sp->wrk->res_mode & RES_GUNZIP) {
INCOMPL();
More information about the varnish-commit
mailing list