From 796e79b0e2e567b35f3415a4a58b267448e72458 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Tue, 16 Sep 2008 11:22:44 +0200 Subject: [PATCH] Implement string representation of time Partially addresses: #294 --- varnish-cache/bin/varnishd/cache_vrt.c | 12 ++++++ varnish-cache/include/vrt.h | 1 + varnish-cache/lib/libvcl/vcc_fixed_token.c | 43 +++++++++++----------- varnish-cache/lib/libvcl/vcc_string.c | 3 ++ 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index c29d3be8..0e5bb163 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -642,6 +642,18 @@ VRT_IP_string(const struct sess *sp, const struct sockaddr *sa) return (p); } +char * +VRT_time_string(const struct sess *sp, double t) +{ + char *p; + int size; + + size = snprintf(NULL, 0, "%.3f", t) + 1; + AN(p = WS_Alloc(sp->http->ws, size)); + assert(snprintf(p, size, "%.3f", t) < size); + return (p); +} + char * VRT_int_string(const struct sess *sp, int num) { diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index 051d6148..d837818a 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -172,6 +172,7 @@ void VRT_init_dir_round_robin(struct cli *, struct director **, const struct vrt_dir_round_robin *); void VRT_fini_dir(struct cli *, struct director *); +char *VRT_time_string(const struct sess *sp, double); char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa); char *VRT_int_string(const struct sess *sp, int); char *VRT_double_string(const struct sess *sp, double); diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index dfcf7368..e4648edd 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -167,11 +167,10 @@ vcl_output_lang_h(struct vsb *sb) /* ../../include/vcl.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3377 2008-11-10 11"); - vsb_cat(sb, ":55:15Z tfheen $\n *\n * NB: This file is machine gen"); - vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit vcc_gen_fixed_token."); - vsb_cat(sb, "tcl instead\n */\n\nstruct sess;\n"); - vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); + vsb_cat(sb, "/*\n * $Id$\n *\n * NB: This file is machine generate"); + vsb_cat(sb, "d, DO NOT EDIT!\n *\n * Edit vcc_gen_fixed_token.tcl i"); + vsb_cat(sb, "nstead\n */\n\nstruct sess;\nstruct cli;\n"); + vsb_cat(sb, "\ntypedef void vcl_init_f(struct cli *);\n"); vsb_cat(sb, "typedef void vcl_fini_f(struct cli *);\n"); vsb_cat(sb, "typedef int vcl_func_f(struct sess *sp);\n"); vsb_cat(sb, "\nstruct VCL_conf {\n\tunsigned\tmagic;\n"); @@ -223,15 +222,15 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); - vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3393 2008-11-14 09:"); - vsb_cat(sb, "49:28Z phk $\n *\n * Runtime support for compiled VCL "); - vsb_cat(sb, "programs.\n *\n * XXX: When this file is changed, lib/"); - vsb_cat(sb, "libvcl/vcc_gen_fixed_token.tcl\n"); - vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n"); - vsb_cat(sb, "\nstruct sess;\nstruct vsb;\nstruct cli;\n"); - vsb_cat(sb, "struct director;\nstruct VCL_conf;\n"); - vsb_cat(sb, "struct sockaddr;\n\n/*\n * A backend probe specificati"); - vsb_cat(sb, "on\n */\n\nextern void *vrt_magic_string_end;\n"); + vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id$\n *\n"); + vsb_cat(sb, " * Runtime support for compiled VCL programs.\n"); + vsb_cat(sb, " *\n * XXX: When this file is changed, lib/libvcl/vcc_"); + vsb_cat(sb, "gen_fixed_token.tcl\n * XXX: *MUST* be rerun.\n"); + vsb_cat(sb, " */\n\nstruct sess;\nstruct vsb;\n"); + vsb_cat(sb, "struct cli;\nstruct director;\n"); + vsb_cat(sb, "struct VCL_conf;\nstruct sockaddr;\n"); + vsb_cat(sb, "\n/*\n * A backend probe specification\n"); + vsb_cat(sb, " */\n\nextern void *vrt_magic_string_end;\n"); vsb_cat(sb, "\nstruct vrt_backend_probe {\n\tconst char\t*url;\n"); vsb_cat(sb, "\tconst char\t*request;\n\tdouble\t\ttimeout;\n"); vsb_cat(sb, "\tdouble\t\tinterval;\n\tunsigned\twindow;\n"); @@ -299,19 +298,19 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, "void VRT_init_dir_round_robin(struct cli *, struct dir"); vsb_cat(sb, "ector **,\n const struct vrt_dir_round_robin *);\n"); vsb_cat(sb, "void VRT_fini_dir(struct cli *, struct director *);\n"); - vsb_cat(sb, "\nchar *VRT_IP_string(const struct sess *sp, const str"); - vsb_cat(sb, "uct sockaddr *sa);\nchar *VRT_int_string(const struct "); - vsb_cat(sb, "sess *sp, int);\nchar *VRT_double_string(const struct "); - vsb_cat(sb, "sess *sp, double);\nconst char *VRT_backend_string(str"); - vsb_cat(sb, "uct sess *sp);\n\n#define VRT_done(sp, hand)\t\t\t\\\n"); + vsb_cat(sb, "\nchar *VRT_time_string(const struct sess *sp, double)"); + vsb_cat(sb, ";\nchar *VRT_IP_string(const struct sess *sp, const st"); + vsb_cat(sb, "ruct sockaddr *sa);\nchar *VRT_int_string(const struct"); + vsb_cat(sb, " sess *sp, int);\nchar *VRT_double_string(const struct"); + vsb_cat(sb, " sess *sp, double);\nconst char *VRT_backend_string(st"); + vsb_cat(sb, "ruct sess *sp);\n\n#define VRT_done(sp, hand)\t\t\t\\\n"); vsb_cat(sb, "\tdo {\t\t\t\t\t\\\n\t\tVRT_handling(sp, hand);\t\t\\\n"); vsb_cat(sb, "\t\treturn (1);\t\t\t\\\n\t} while (0)\n"); /* ../../include/vrt_obj.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_obj.tcl 3324 2008-10-18 20:50:10Z "); - vsb_cat(sb, "phk $\n *\n * NB: This file is machine generated, DO "); - vsb_cat(sb, "NOT EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); + vsb_cat(sb, "/*\n * $Id$\n *\n * NB: This file is machine generate"); + vsb_cat(sb, "d, DO NOT EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct "); vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses"); vsb_cat(sb, "s *);\nint VRT_r_server_port(struct sess *);\n"); diff --git a/varnish-cache/lib/libvcl/vcc_string.c b/varnish-cache/lib/libvcl/vcc_string.c index cb87a03f..be6014d8 100644 --- a/varnish-cache/lib/libvcl/vcc_string.c +++ b/varnish-cache/lib/libvcl/vcc_string.c @@ -159,6 +159,9 @@ vcc_StringVal(struct tokenlist *tl) case FLOAT: Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname); break; + case TIME: + Fb(tl, 0, "VRT_time_string(sp, %s)", vp->rname); + break; case BACKEND: Fb(tl, 0, "VRT_backend_string(sp)"); break; -- 2.39.5