]> err.no Git - varnish/commitdiff
Distribute code from FetchSession almost correctly
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Jul 2006 16:10:10 +0000 (16:10 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Jul 2006 16:10:10 +0000 (16:10 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@431 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_fetch.c

index db912b2e78a0de4b055edd63bb77fc9b8100d953..26a10857397752aec56d239ed97e398118b0ed67 100644 (file)
@@ -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);
index 9fca8ffee9597755be29551143b5b07dea030126..bbe36efdd3f6e2e69483f088efff8bba5f29fd52 100644 (file)
@@ -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();
index 997ac1e25e0233a60c22fb42c0f09cc445b49be8..47d538a7ee84591e8e86fb6d186313150bba1c64 100644 (file)
@@ -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);
 }