r2046 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Wed Sep 26 21:15:25 CEST 2007
Author: phk
Date: 2007-09-26 21:15:25 +0200 (Wed, 26 Sep 2007)
New Revision: 2046
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_http.c
trunk/varnish-cache/bin/varnishd/shmlog.c
Log:
Use the new txt type more extensively, it does improve readability a bit.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2007-09-26 18:59:28 UTC (rev 2045)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2007-09-26 19:15:25 UTC (rev 2046)
@@ -509,9 +509,9 @@
void VSL_Init(void);
#ifdef SHMLOGHEAD_MAGIC
-void VSLR(enum shmlogtag tag, int id, const char *b, const char *e);
+void VSLR(enum shmlogtag tag, int id, txt t);
void VSL(enum shmlogtag tag, int id, const char *fmt, ...);
-void WSLR(struct worker *w, enum shmlogtag tag, int id, const char *b, const char *e);
+void WSLR(struct worker *w, enum shmlogtag tag, int id, txt t);
void WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...);
void WSL_Flush(struct worker *w);
#define INCOMPL() do { \
@@ -602,3 +602,25 @@
return
((unsigned)((const unsigned char *)e - (const unsigned char *)b));
}
+
+static inline void
+Tcheck(const txt t)
+{
+
+ AN(t.b);
+ AN(t.e);
+ assert(t.b <= t.e);
+}
+
+/*
+ * unsigned length of a txt
+ */
+
+static inline unsigned
+Tlen(const txt t)
+{
+
+ Tcheck(t);
+ return
+ ((unsigned)(t.e - t.b));
+}
Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-09-26 18:59:28 UTC (rev 2045)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-09-26 19:15:25 UTC (rev 2046)
@@ -92,7 +92,7 @@
WSLH(struct worker *w, enum httptag t, int fd, const struct http *hp, unsigned hdr)
{
- WSLR(w, http2shmlog(hp, t), fd, hp->hd[hdr].b, hp->hd[hdr].e);
+ WSLR(w, http2shmlog(hp, t), fd, hp->hd[hdr]);
}
/*--------------------------------------------------------------------*/
@@ -325,16 +325,16 @@
return (0);
if (len == 0)
- len = pdiff(hp->pl.b, hp->pl.e);
+ len = Tlen(hp->pl);
if (hp->pl.b + len > hp->pl.e)
- len = pdiff(hp->pl.b, hp->pl.e);
+ len = Tlen(hp->pl);
if (len == 0)
return (0);
*b = hp->pl.b;
*e = hp->pl.b + len;
hp->pl.b += len;
- assert(hp->pl.b <= hp->pl.e);
+ Tcheck(hp->pl);
return (1);
}
@@ -350,7 +350,7 @@
u = 0;
if (hp->pl.b < hp->pl.e) {
- u = pdiff(hp->pl.b, hp->pl.e);
+ u = Tlen(hp->pl);
if (u > len)
u = len;
memcpy(b, hp->pl.b, u);
@@ -435,7 +435,7 @@
hp->nhd++;
} else {
VSL_stats->losthdr++;
- WSLR(w, SLT_LostHeader, fd, p, q);
+ WSL(w, SLT_LostHeader, fd, "%.*s", q - p, p);
}
}
return (0);
@@ -450,7 +450,7 @@
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
/* Assert a NUL at rx.e */
- assert(hp->rx.b < hp->rx.e);
+ Tcheck(hp->rx);
hp->logtag = HTTP_Rx;
for (p = hp->rx.b ; isspace(*p); p++)
@@ -468,7 +468,7 @@
while (isspace(*p) && *p != '\n')
p++;
if (*p == '\n') {
- WSLR(w, SLT_HttpGarbage, fd, hp->rx.b, hp->rx.e);
+ WSLR(w, SLT_HttpGarbage, fd, hp->rx);
return (400);
}
hp->hd[HTTP_HDR_URL].b = p;
@@ -477,7 +477,7 @@
hp->hd[HTTP_HDR_URL].e = p;
WSLH(w, HTTP_T_URL, fd, hp, HTTP_HDR_URL);
if (*p == '\n') {
- WSLR(w, SLT_HttpGarbage, fd, hp->rx.b, hp->rx.e);
+ WSLR(w, SLT_HttpGarbage, fd, hp->rx);
return (400);
}
*p++ = '\0';
@@ -486,7 +486,7 @@
while (isspace(*p) && *p != '\n')
p++;
if (*p == '\n') {
- WSLR(w, SLT_HttpGarbage, fd, hp->rx.b, hp->rx.e);
+ WSLR(w, SLT_HttpGarbage, fd, hp->rx);
return (400);
}
hp->hd[HTTP_HDR_PROTO].b = p;
@@ -499,7 +499,7 @@
while (isspace(*p) && *p != '\n')
p++;
if (*p != '\n') {
- WSLR(w, SLT_HttpGarbage, fd, hp->rx.b, hp->rx.e);
+ WSLR(w, SLT_HttpGarbage, fd, hp->rx);
return (400);
}
*p++ = '\0';
@@ -516,14 +516,14 @@
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
/* Assert a NUL at rx.e */
- assert(hp->rx.b < hp->rx.e);
+ Tcheck(hp->rx);
hp->logtag = HTTP_Rx;
for (p = hp->rx.b ; isspace(*p); p++)
continue;
if (memcmp(p, "HTTP/1.", 7)) {
- WSLR(w, SLT_HttpGarbage, fd, hp->rx.b, hp->rx.e);
+ WSLR(w, SLT_HttpGarbage, fd, hp->rx);
return (400);
}
/* First, protocol */
@@ -615,7 +615,7 @@
hp->rx.b = hp->ws->f;
hp->rx.e = hp->rx.b;
if (hp->pl.b != NULL) {
- l = pdiff(hp->pl.b, hp->pl.e);
+ l = Tlen(hp->pl);
memmove(hp->rx.b, hp->pl.b, l);
hp->rx.e = hp->rx.b + l;
hp->pl.b = hp->pl.e = NULL;
@@ -644,7 +644,7 @@
l /= 2; /* Don't fill all of workspace with read-ahead */
if (l <= 1) {
VSL(SLT_HttpError, fd, "Received too much");
- VSLR(SLT_HttpGarbage, fd, hp->rx.b, hp->rx.e);
+ VSLR(SLT_HttpGarbage, fd, hp->rx);
hp->rx.b = hp->rx.e = NULL;
WS_Release(hp->ws, 0);
return (1);
@@ -663,7 +663,7 @@
VSL(SLT_HttpError, fd,
"Received (only) %d bytes, errno %d",
hp->rx.e - hp->rx.b, errno);
- VSLR(SLT_Debug, fd, hp->rx.b, hp->rx.e);
+ VSLR(SLT_Debug, fd, hp->rx);
} else if (errno == 0)
VSL(SLT_HttpError, fd, "Received nothing");
else
@@ -767,7 +767,7 @@
to->nhd++;
} else {
VSL_stats->losthdr++;
- WSLR(w, SLT_LostHeader, fd, fm->hd[n].b, fm->hd[n].e);
+ WSLR(w, SLT_LostHeader, fd, fm->hd[n]);
}
}
@@ -855,7 +855,7 @@
WSLH(w, htt, fd, hp, u);
continue;
}
- l = pdiff(hp->hd[u].b, hp->hd[u].e);
+ l = Tlen(hp->hd[u]);
p = WS_Alloc(hp->ws, l + 1);
if (p != NULL) {
WSLH(w, htt, fd, hp, u);
@@ -863,7 +863,7 @@
hp->hd[u].b = p;
hp->hd[u].e = p + l;
} else {
- WSLR(w, SLT_LostHeader, fd, hp->hd[u].b, hp->hd[u].e);
+ WSLR(w, SLT_LostHeader, fd, hp->hd[u]);
hp->hd[u].b = NULL;
hp->hd[u].e = NULL;
}
Modified: trunk/varnish-cache/bin/varnishd/shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/shmlog.c 2007-09-26 18:59:28 UTC (rev 2045)
+++ trunk/varnish-cache/bin/varnishd/shmlog.c 2007-09-26 19:15:25 UTC (rev 2046)
@@ -83,20 +83,18 @@
/*--------------------------------------------------------------------*/
void
-VSLR(enum shmlogtag tag, int id, const char *b, const char *e)
+VSLR(enum shmlogtag tag, int id, txt t)
{
unsigned char *p;
unsigned l;
- assert(b != NULL);
- if (e == NULL)
- e = strchr(b, '\0');
+ Tcheck(t);
/* Truncate */
- l = pdiff(b, e);
+ l = Tlen(t);
if (l > 255) {
l = 255;
- e = b + l;
+ t.e = t.b + l;
}
/* Only hold the lock while we find our space */
@@ -117,7 +115,7 @@
p[1] = l & 0xff;
p[2] = (id >> 8) & 0xff;
p[3] = id & 0xff;
- memcpy(p + 4, b, l);
+ memcpy(p + 4, t.b, l);
p[4 + l] = '\0';
/* XXX: memory barrier */
p[0] = tag;
@@ -131,12 +129,15 @@
va_list ap;
unsigned char *p;
unsigned n;
+ txt t;
AN(fmt);
va_start(ap, fmt);
if (strchr(fmt, '%') == NULL) {
- VSLR(tag, id, fmt, NULL);
+ t.b = (void*)(uintptr_t)fmt;
+ t.e = strchr(fmt, '\0');
+ VSLR(tag, id, t);
return;
}
@@ -200,20 +201,18 @@
/*--------------------------------------------------------------------*/
void
-WSLR(struct worker *w, enum shmlogtag tag, int id, const char *b, const char *e)
+WSLR(struct worker *w, enum shmlogtag tag, int id, txt t)
{
unsigned char *p;
unsigned l;
- assert(b != NULL);
- if (e == NULL)
- e = strchr(b, '\0');
+ Tcheck(t);
/* Truncate */
- l = pdiff(b, e);
+ l = Tlen(t);
if (l > 255) {
l = 255;
- e = b + l;
+ t.e = t.b + l;
}
assert(w->wlp < w->wle);
@@ -229,7 +228,7 @@
p[1] = l & 0xff;
p[2] = (id >> 8) & 0xff;
p[3] = id & 0xff;
- memcpy(p + 4, b, l);
+ memcpy(p + 4, t.b, l);
p[4 + l] = '\0';
p[0] = tag;
w->wlr++;
@@ -243,12 +242,15 @@
va_list ap;
unsigned char *p;
unsigned n;
+ txt t;
AN(fmt);
va_start(ap, fmt);
if (strchr(fmt, '%') == NULL) {
- WSLR(w, tag, id, fmt, NULL);
+ t.b = (void*)(uintptr_t)fmt;
+ t.e = strchr(fmt, '\0');
+ WSLR(w, tag, id, t);
return;
}
More information about the varnish-commit
mailing list