From edf037a8e6d4efd2c650451287ba567c1d000fe6 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 11 Jul 2006 16:10:10 +0000 Subject: [PATCH] Distribute code from FetchSession almost correctly git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@431 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 5 +- varnish-cache/bin/varnishd/cache_center.c | 45 ++++++++++--- varnish-cache/bin/varnishd/cache_fetch.c | 81 +++++++++++++---------- 3 files changed, 85 insertions(+), 46 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index db912b2e..26a10857 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -161,6 +161,8 @@ struct sess { TAILQ_ENTRY(sess) list; + struct vbe_conn *vbc; + struct http *bkd_http; struct backend *backend; struct object *obj; struct VCL_conf *vcl; @@ -223,7 +225,8 @@ void EXP_Init(void); void EXP_TTLchange(struct object *o); /* cache_fetch.c */ -int FetchSession(struct worker *w, struct sess *sp); +int FetchBody(struct worker *w, struct sess *sp); +int FetchHeaders(struct worker *w, struct sess *sp); /* cache_hash.c */ struct object *HSH_Lookup(struct worker *w, struct http *h); diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 9fca8ffe..bbe36efd 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -57,7 +57,13 @@ DOT } DOT deliver2 -> DONE [style=bold] */ -static void cnt_deliver(struct worker *w, struct sess *sp) { (void)w; (void)sp; INCOMPL(); } +static void +cnt_deliver(struct worker *w, struct sess *sp) +{ + + vca_write_obj(w, sp); + sp->step = STP_DONE; +} /*-------------------------------------------------------------------- DOT DONE [ @@ -139,7 +145,29 @@ DOT fetch_insert -> DELIVER [style=bold] DOT fetch_error -> ERROR */ -static void cnt_fetch(struct worker *w, struct sess *sp) { (void)w; (void)sp; INCOMPL(); } +static void +cnt_fetch(struct worker *w, struct sess *sp) +{ + + RFC2616_cache_policy(sp, sp->bkd_http); + + VCL_fetch_method(sp); + + if (sp->handling == VCL_RET_LOOKUP) + INCOMPL(); + if (sp->handling == VCL_RET_PASS) + INCOMPL(); + if (sp->handling == VCL_RET_INSERT_PASS) + INCOMPL(); + if (sp->handling == VCL_RET_INSERT) { + FetchBody(w, sp); + sp->step = STP_DELIVER; + return; + } + if (sp->handling == VCL_RET_ERROR) + INCOMPL(); + INCOMPL(); +} /*-------------------------------------------------------------------- DOT subgraph cluster_hit { @@ -208,16 +236,14 @@ DOT lookup2 -> MISS [label="miss", style=bold] static void cnt_lookup(struct worker *w, struct sess *sp) { - struct object *o; - o = HSH_Lookup(w, sp->http); - sp->obj = o; - if (o->busy) { + sp->obj = HSH_Lookup(w, sp->http); + if (sp->obj->busy) { VSL_stats->cache_miss++; sp->step = STP_MISS; } else { VSL_stats->cache_hit++; - VSL(SLT_Hit, sp->fd, "%u", o->xid); + VSL(SLT_Hit, sp->fd, "%u", sp->obj->xid); sp->step = STP_HIT; } } @@ -269,9 +295,8 @@ cnt_miss(struct worker *w, struct sess *sp) if (sp->handling == VCL_RET_LOOKUP) INCOMPL(); if (sp->handling == VCL_RET_FETCH) { - /* XXX */ - FetchSession(w, sp); - sp->step = STP_DONE; + FetchHeaders(w, sp); + sp->step = STP_FETCH; return; } INCOMPL(); diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 997ac1e2..47d538a7 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -229,8 +229,9 @@ fetch_eof(struct sess *sp, int fd, struct http *hp) } /*--------------------------------------------------------------------*/ + int -FetchSession(struct worker *w, struct sess *sp) +FetchBody(struct worker *w, struct sess *sp) { int i, cls; struct vbe_conn *vc; @@ -238,37 +239,8 @@ FetchSession(struct worker *w, struct sess *sp) char *b; int body; - sp->obj->xid = sp->xid; - - vc = VBE_GetFd(sp->backend, sp->xid); - if (vc == NULL) - vc = VBE_GetFd(sp->backend, sp->xid); - assert(vc != NULL); /* XXX: handle this */ - VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name); - - hp = vc->http; - http_BuildSbuf(vc->fd, Build_Fetch, w->sb, sp->http); - i = write(vc->fd, sbuf_data(w->sb), sbuf_len(w->sb)); - assert(i == sbuf_len(w->sb)); - time(&sp->t_req); - - /* XXX: copy any contents */ - - /* - * XXX: It might be cheaper to avoid the event_engine and simply - * XXX: read(2) the header - */ - http_RecvHead(hp, vc->fd, w->eb, NULL, NULL); - event_base_loop(w->eb, 0); - time(&sp->t_resp); - assert(http_DissectResponse(hp, vc->fd) == 0); - - body = RFC2616_cache_policy(sp, hp); - - VCL_fetch_method(sp); - - if (sp->obj->cacheable) - EXP_Insert(sp->obj); + vc = sp->vbc; + hp = sp->bkd_http; http_BuildSbuf(sp->fd, Build_Reply, w->sb, hp); if (body) { @@ -285,8 +257,6 @@ FetchSession(struct worker *w, struct sess *sp) sp->obj->header = strdup(sbuf_data(w->sb)); VSL_stats->n_header++; - vca_write_obj(w, sp); - if (http_GetHdr(hp, "Connection", &b) && !strcasecmp(b, "close")) cls = 1; @@ -295,9 +265,50 @@ FetchSession(struct worker *w, struct sess *sp) else VBE_RecycleFd(vc); + if (sp->obj->cacheable) + EXP_Insert(sp->obj); HSH_Unbusy(sp->obj); if (!sp->obj->cacheable) HSH_Deref(sp->obj); + return (0); +} - return (1); +/*--------------------------------------------------------------------*/ + +int +FetchHeaders(struct worker *w, struct sess *sp) +{ + int i, cls; + struct vbe_conn *vc; + struct http *hp; + char *b; + int body; + + sp->obj->xid = sp->xid; + + vc = VBE_GetFd(sp->backend, sp->xid); + if (vc == NULL) + vc = VBE_GetFd(sp->backend, sp->xid); + assert(vc != NULL); /* XXX: handle this */ + VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name); + + hp = vc->http; + http_BuildSbuf(vc->fd, Build_Fetch, w->sb, sp->http); + i = write(vc->fd, sbuf_data(w->sb), sbuf_len(w->sb)); + assert(i == sbuf_len(w->sb)); + time(&sp->t_req); + + /* XXX: copy any body ?? */ + + /* + * XXX: It might be cheaper to avoid the event_engine and simply + * XXX: read(2) the header + */ + http_RecvHead(hp, vc->fd, w->eb, NULL, NULL); + event_base_loop(w->eb, 0); + time(&sp->t_resp); + assert(http_DissectResponse(hp, vc->fd) == 0); + sp->vbc = vc; + sp->bkd_http = hp; + return (0); } -- 2.39.5