From cd58802547f5792d699f1be5db169d162f685279 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 24 Mar 2006 10:22:47 +0000 Subject: [PATCH] Add a VSLR() variant which logs a byte range without spending time in sprintf git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@67 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 7 +++- varnish-cache/bin/varnishd/cache_shmlog.c | 49 +++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 0ec110dd..249089de 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -9,15 +9,20 @@ struct sess { char rcv[VCA_RXBUFSIZE + 1]; char addr[VCA_ADDRBUFSIZE]; unsigned rcv_len; - struct event rd_e; + struct event *rd_e; + struct sessmem *mem; }; /* cache_acceptor.c */ void *vca_main(void *arg); +/* cache_httpd.c */ +void HttpdAnalyze(struct sess *sp); + /* cache_shmlog.c */ void VSL_Init(void); #ifdef SHMLOGHEAD_MAGIC +void VSLR(enum shmlogtag tag, unsigned id, const char *b, const char *e); void VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...); #endif diff --git a/varnish-cache/bin/varnishd/cache_shmlog.c b/varnish-cache/bin/varnishd/cache_shmlog.c index 562b437d..aa2ad9bd 100644 --- a/varnish-cache/bin/varnishd/cache_shmlog.c +++ b/varnish-cache/bin/varnishd/cache_shmlog.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -14,6 +15,54 @@ static struct shmloghead *loghead; static unsigned char *logstart, *logend; +/* + * This variant copies a byte-range directly to the log, without + * taking the detour over sprintf() + */ + +void +VSLR(enum shmlogtag tag, unsigned id, const char *b, const char *e) +{ + va_list ap; + unsigned char *p, *q; + + assert(b != NULL); + if (e == NULL) + e = strchr(b, '\0'); + assert(e != NULL); + + /* Truncate */ + if (e - b > 255) + e = b + 255; + + /* XXX: Lock */ + q = NULL; + p = logstart + loghead->ptr; + assert(p < logend); + + /* Wrap if necessary */ + if (p + 4 + (e - b) > logend) { + q = p; + p = logstart; + *p = SLT_ENDMARKER; + } + p[1] = e - b; + p[2] = id >> 8; + p[3] = id & 0xff; + memcpy(p + 4, b, e - b); + p[0] = tag; + + if (q != NULL) + *q = SLT_WRAPMARKER; + + loghead->ptr = (p + 4 + (e - b)) - logstart; + + /* XXX: Unlock */ + + va_end(ap); +} + + void VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...) { -- 2.39.5