From 9eb22601508ab70ae9c89f7238205c0f789b18ee Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 24 Jun 2006 21:07:18 +0000 Subject: [PATCH] Add a "timeout" method to VCL, it can return "fetch" or "discard". git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@228 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/varnishd.c | 3 ++ varnish-cache/include/vcl.h | 1 + varnish-cache/include/vcl_returns.h | 5 ++- varnish-cache/lib/libvcl/vcl_fixed_token.c | 9 ++++ .../lib/libvcl/vcl_gen_fixed_token.tcl | 10 +++-- varnish-cache/lib/libvcl/vcl_token_defs.h | 41 ++++++++++--------- 6 files changed, 44 insertions(+), 25 deletions(-) diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index b2d67c62..7c72d149 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -107,6 +107,9 @@ vcl_default(const char *bflag) " }\n" " insert;\n" "}\n" + "sub vcl_timeout {\n" + " discard;\n" + "}\n" "", bflag); assert(buf != NULL); sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); diff --git a/varnish-cache/include/vcl.h b/varnish-cache/include/vcl.h index 83197434..4b896ff0 100644 --- a/varnish-cache/include/vcl.h +++ b/varnish-cache/include/vcl.h @@ -27,4 +27,5 @@ struct VCL_conf { vcl_func_f *miss_func; vcl_func_f *hit_func; vcl_func_f *fetch_func; + vcl_func_f *timeout_func; }; diff --git a/varnish-cache/include/vcl_returns.h b/varnish-cache/include/vcl_returns.h index 0438e59d..3cc8448f 100644 --- a/varnish-cache/include/vcl_returns.h +++ b/varnish-cache/include/vcl_returns.h @@ -16,6 +16,7 @@ VCL_RET_MAC(pass, PASS, (1 << 3)) VCL_RET_MAC(fetch, FETCH, (1 << 4)) VCL_RET_MAC(insert, INSERT, (1 << 5)) VCL_RET_MAC(deliver, DELIVER, (1 << 6)) +VCL_RET_MAC(discard, DISCARD, (1 << 7)) #else #define VCL_RET_ERROR (1 << 0) #define VCL_RET_LOOKUP (1 << 1) @@ -24,7 +25,8 @@ VCL_RET_MAC(deliver, DELIVER, (1 << 6)) #define VCL_RET_FETCH (1 << 4) #define VCL_RET_INSERT (1 << 5) #define VCL_RET_DELIVER (1 << 6) -#define VCL_RET_MAX 7 +#define VCL_RET_DISCARD (1 << 7) +#define VCL_RET_MAX 8 #endif #ifdef VCL_MET_MAC @@ -32,4 +34,5 @@ VCL_MET_MAC(recv,RECV,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_PIPE|VCL_RET_LOOKUP)) VCL_MET_MAC(miss,MISS,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_PIPE|VCL_RET_FETCH)) VCL_MET_MAC(hit,HIT,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_PIPE|VCL_RET_DELIVER)) VCL_MET_MAC(fetch,FETCH,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_PIPE|VCL_RET_INSERT)) +VCL_MET_MAC(timeout,TIMEOUT,(VCL_RET_FETCH|VCL_RET_DISCARD)) #endif diff --git a/varnish-cache/lib/libvcl/vcl_fixed_token.c b/varnish-cache/lib/libvcl/vcl_fixed_token.c index 5e820382..8f260f76 100644 --- a/varnish-cache/lib/libvcl/vcl_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcl_fixed_token.c @@ -180,6 +180,12 @@ vcl_fixed_token(const char *p, const char **q) } return (0); case 'd': + if (p[0] == 'd' && p[1] == 'i' && p[2] == 's' && + p[3] == 'c' && p[4] == 'a' && p[5] == 'r' && + p[6] == 'd' && !isvar(p[7])) { + *q = p + 7; + return (T_DISCARD); + } if (p[0] == 'd' && p[1] == 'e' && p[2] == 'l' && p[3] == 'i' && p[4] == 'v' && p[5] == 'e' && p[6] == 'r' && !isvar(p[7])) { @@ -373,6 +379,7 @@ vcl_init_tnames(void) vcl_tnames[T_DEC] = "--"; vcl_tnames[T_DECR] = "/="; vcl_tnames[T_DELIVER] = "deliver"; + vcl_tnames[T_DISCARD] = "discard"; vcl_tnames[T_DIV] = "/="; vcl_tnames[T_ELSE] = "else"; vcl_tnames[T_ELSEIF] = "elseif"; @@ -414,6 +421,7 @@ vcl_output_lang_h(FILE *f) fputs("#define VCL_RET_FETCH (1 << 4)\n", f); fputs("#define VCL_RET_INSERT (1 << 5)\n", f); fputs("#define VCL_RET_DELIVER (1 << 6)\n", f); + fputs("#define VCL_RET_DISCARD (1 << 7)\n", f); fputs("/*\n", f); fputs(" * $Id$\n", f); fputs(" *\n", f); @@ -443,6 +451,7 @@ vcl_output_lang_h(FILE *f) fputs(" vcl_func_f *miss_func;\n", f); fputs(" vcl_func_f *hit_func;\n", f); fputs(" vcl_func_f *fetch_func;\n", f); + fputs(" vcl_func_f *timeout_func;\n", f); fputs("};\n", f); fputs("/*\n", f); fputs(" * $Id$ \n", f); diff --git a/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl index 371c4f1b..c25d7d9b 100755 --- a/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcl_gen_fixed_token.tcl @@ -7,10 +7,11 @@ # Second element is list of valid return actions. # set methods { - {recv {error pass pipe lookup}} - {miss {error pass pipe fetch}} - {hit {error pass pipe deliver}} - {fetch {error pass pipe insert}} + {recv {error pass pipe lookup}} + {miss {error pass pipe fetch}} + {hit {error pass pipe deliver}} + {fetch {error pass pipe insert}} + {timeout {fetch discard}} } # These are the return actions @@ -23,6 +24,7 @@ set returns { fetch insert deliver + discard } # Language keywords diff --git a/varnish-cache/lib/libvcl/vcl_token_defs.h b/varnish-cache/lib/libvcl/vcl_token_defs.h index 9a3f9382..b3c2a024 100644 --- a/varnish-cache/lib/libvcl/vcl_token_defs.h +++ b/varnish-cache/lib/libvcl/vcl_token_defs.h @@ -29,23 +29,24 @@ #define T_FETCH 147 #define T_INSERT 148 #define T_DELIVER 149 -#define T_INC 150 -#define T_DEC 151 -#define T_CAND 152 -#define T_COR 153 -#define T_LEQ 154 -#define T_EQ 155 -#define T_NEQ 156 -#define T_GEQ 157 -#define T_SHR 158 -#define T_SHL 159 -#define T_INCR 160 -#define T_DECR 161 -#define T_MUL 162 -#define T_DIV 163 -#define ID 164 -#define VAR 165 -#define CNUM 166 -#define CSTR 167 -#define EOI 168 -#define METHOD 169 +#define T_DISCARD 150 +#define T_INC 151 +#define T_DEC 152 +#define T_CAND 153 +#define T_COR 154 +#define T_LEQ 155 +#define T_EQ 156 +#define T_NEQ 157 +#define T_GEQ 158 +#define T_SHR 159 +#define T_SHL 160 +#define T_INCR 161 +#define T_DECR 162 +#define T_MUL 163 +#define T_DIV 164 +#define ID 165 +#define VAR 166 +#define CNUM 167 +#define CSTR 168 +#define EOI 169 +#define METHOD 170 -- 2.39.5