]> err.no Git - varnish/commitdiff
Implement vcl_deliver() and change variable visibility to match.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 3 Jul 2007 22:24:09 +0000 (22:24 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 3 Jul 2007 22:24:09 +0000 (22:24 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1640 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_response.c
varnish-cache/lib/libvcl/vcc_fixed_token.c
varnish-cache/lib/libvcl/vcc_gen_obj.tcl
varnish-cache/lib/libvcl/vcc_obj.c

index e3aea1b99f1241630cdc81db092292da4369f9de..61dc85f7efd025fa7e578c55598a3fd22266f96d 100644 (file)
@@ -471,6 +471,7 @@ void WSL_Flush(struct worker *w);
 #endif
 
 /* cache_response.c */
+void RES_BuildHttp(struct sess *sp);
 void RES_Error(struct sess *sp, int code, const char *reason);
 void RES_WriteObj(struct sess *sp);
 
index acf274ac77d43b7de0b794b7b1f43179a8ea2bee..d4f1005b70df344c223996c7ad25c7647507a092 100644 (file)
@@ -119,7 +119,7 @@ DOT         label="Filter obj.->resp."
 DOT    ]
 DOT    vcl_deliver [
 DOT            shape=record
-DOT            label="vcl_deliver()|req.\nresp."
+DOT            label="vcl_deliver()|resp."
 DOT    ]
 DOT    deliver2 [
 DOT            shape=ellipse
@@ -131,12 +131,29 @@ DOT     vcl_deliver -> errdeliver [label="error"]
 DOT     errdeliver [label="ERROR",shape=plaintext]
 DOT }
 DOT deliver2 -> DONE [style=bold,color=green,weight=4]
+ *
+ * XXX: Ideally we should make the req. available in vcl_deliver() but for
+ * XXX: reasons of economy we don't, since that allows us to reuse the space
+ * XXX: in sp->req for the response.
+ * 
+ * XXX: Rather than allocate two http's and workspaces for all sessions to
+ * XXX: address this deficiency, we could make the VCL compiler set a flag
+ * XXX: if req. is used in vcl_deliver().  When the flag is set we would
+ * XXX: take the memory overhead, for instance by borrowing a struct bereq
+ * XXX: or similar.
+ *
+ * XXX: For now, wait until somebody asks for it.
  */
 
 static int
 cnt_deliver(struct sess *sp)
 {
 
+       RES_BuildHttp(sp);
+       VCL_deliver_method(sp);
+       if (sp->handling != VCL_RET_DELIVER) 
+               INCOMPL();
+
        RES_WriteObj(sp);
        HSH_Deref(sp->obj);
        sp->obj = NULL;
@@ -171,6 +188,7 @@ cnt_done(struct sess *sp)
        double dh, dp, da;
 
        AZ(sp->obj);
+       AZ(sp->bereq);
        sp->backend = NULL;
        if (sp->vcl != NULL) {
                if (sp->wrk->vcl != NULL)
index 045c461b37404449aef8d3f1e761767c691d011a..8669e43e3b4cb3b79a0cdb524a962d34b06aa2d6 100644 (file)
@@ -114,13 +114,9 @@ res_do_conds(struct sess *sp)
 /*--------------------------------------------------------------------*/
 
 void
-RES_WriteObj(struct sess *sp)
+RES_BuildHttp(struct sess *sp)
 {
-       struct storage *st;
-       unsigned u = 0;
-
        CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-       clock_gettime(CLOCK_REALTIME, &sp->t_resp);
 
        if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp))
                return;
@@ -136,12 +132,26 @@ RES_WriteObj(struct sess *sp)
                http_PrintfHeader(sp->wrk, sp->fd, sp->http,
                    "X-Varnish: %u %u", sp->xid, sp->obj->xid);
        else
-               http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid);
+               http_PrintfHeader(sp->wrk, sp->fd, sp->http,
+                   "X-Varnish: %u", sp->xid);
        http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %u",
            sp->obj->age + sp->t_resp.tv_sec - sp->obj->entered);
        http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish");
        if (sp->doclose != NULL)
                http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close");
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+RES_WriteObj(struct sess *sp)
+{
+       struct storage *st;
+       unsigned u = 0;
+
+       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+
+       clock_gettime(CLOCK_REALTIME, &sp->t_resp);
        WRK_Reset(sp->wrk, &sp->fd);
        sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
        CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
index d1776824a550ca8040a0d2a1850d55cd723a3a8c..4d581ceea474cafec580eba1c67e0c747b5447aa 100644 (file)
@@ -483,10 +483,12 @@ vcl_output_lang_h(struct vsb *sb)
        vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n");
        vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n");
        vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n");
+       vsb_cat(sb, "double VRT_r_obj_lastuse(struct sess *);\n");
        vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n");
        vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n");
        vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n");
        vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n");
        vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n");
        vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n");
+       vsb_cat(sb, "double VRT_r_now(struct sess *);\n");
 }
index 396afb0d068edb7b428c2175cd3876145f00779f..10f6c6038f1e8f01b44fcc3aa33b5409052b9634 100755 (executable)
@@ -44,14 +44,14 @@ set spobj {
        # Connection related parameters
        { client.ip
                RO IP
-               {recv pipe pass hash miss hit fetch                        }
+               {recv pipe pass hash miss hit fetch deliver                }
        }
        { client.bandwidth                               # Not implemented yet
                NO
        }
        { server.ip
                RO IP
-               {recv pipe pass hash miss hit fetch                        }
+               {recv pipe pass hash miss hit fetch deliver                }
        }
 
        # Request paramters
@@ -103,7 +103,7 @@ set spobj {
        # The (possibly) cached object
        { obj.proto
                RW STRING
-               {                         hit fetch deliver                }
+               {                         hit fetch                        }
        }
        { obj.status
                RW INT
@@ -115,7 +115,7 @@ set spobj {
        }
        { obj.http.
                RW HEADER
-               {                         hit fetch deliver                }
+               {                         hit fetch                        }
        }
 
        { obj.valid
@@ -138,22 +138,24 @@ set spobj {
        # The response we send back
        { resp.proto
                RW STRING
-               {                             fetch                        }
+               {                                   deliver                }
        }
        { resp.status
                RW INT
-               {                             fetch                        }
+               {                                   deliver                }
        }
        { resp.response
                RW STRING
-               {                             fetch                        }
+               {                                   deliver                }
        }
        { resp.http.
                RW HEADER
-               {                             fetch                        }
+               {                                   deliver                }
        }
 
        # Miscellaneous
+       # XXX: I'm not happy about this one.  All times should be relative
+       # XXX: or delta times in VCL programs, so this shouldn't be needed /phk
        { now
                RO TIME
                {recv pipe pass hash miss hit fetch deliver discard timeout}
index 9f8d682f7b7ed2895bab092858f01d654f25bcab..1d6d710e1353b0bc7d15051283328fd71c61c486 100644 (file)
@@ -36,13 +36,13 @@ struct var vcc_vars[] = {
            "VRT_r_client_ip(sp)",
            NULL,
            V_RO,
-           VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
+           VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
        },
        { "server.ip", IP, 9,
            "VRT_r_server_ip(sp)",
            NULL,
            V_RO,
-           VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
+           VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
        },
        { "req.request", STRING, 11,
            "VRT_r_req_request(sp)",
@@ -108,7 +108,7 @@ struct var vcc_vars[] = {
            "VRT_r_obj_proto(sp)",
            "VRT_l_obj_proto(sp, ",
            V_RW,
-           VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
+           VCL_MET_HIT | VCL_MET_FETCH
        },
        { "obj.status", INT, 10,
            "VRT_r_obj_status(sp)",
@@ -126,7 +126,7 @@ struct var vcc_vars[] = {
            "VRT_r_obj_http_(sp)",
            "VRT_l_obj_http_(sp, ",
            V_RW,
-           VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
+           VCL_MET_HIT | VCL_MET_FETCH
        },
        { "obj.valid", BOOL, 9,
            "VRT_r_obj_valid(sp)",
@@ -156,25 +156,25 @@ struct var vcc_vars[] = {
            "VRT_r_resp_proto(sp)",
            "VRT_l_resp_proto(sp, ",
            V_RW,
-           VCL_MET_FETCH
+           VCL_MET_DELIVER
        },
        { "resp.status", INT, 11,
            "VRT_r_resp_status(sp)",
            "VRT_l_resp_status(sp, ",
            V_RW,
-           VCL_MET_FETCH
+           VCL_MET_DELIVER
        },
        { "resp.response", STRING, 13,
            "VRT_r_resp_response(sp)",
            "VRT_l_resp_response(sp, ",
            V_RW,
-           VCL_MET_FETCH
+           VCL_MET_DELIVER
        },
        { "resp.http.", HEADER, 10,
            "VRT_r_resp_http_(sp)",
            "VRT_l_resp_http_(sp, ",
            V_RW,
-           VCL_MET_FETCH
+           VCL_MET_DELIVER
        },
        { "now", TIME, 3,
            "VRT_r_now(sp)",