Commit c3e01132 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a VSLR() variant which logs a byte range without spending time in

sprintf


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@67 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 77e3c423
......@@ -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
......
......@@ -4,6 +4,7 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdarg.h>
#include <sys/mman.h>
......@@ -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, ...)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment