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]);
}
/*--------------------------------------------------------------------*/
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);
}
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);
hp->nhd++;
} else {
VSL_stats->losthdr++;
- WSLR(w, SLT_LostHeader, fd, p, q);
+ WSL(w, SLT_LostHeader, fd, "%.*s", q - p, p);
}
}
return (0);
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++)
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;
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';
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;
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';
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 */
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;
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);
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
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]);
}
}
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);
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;
}
/*--------------------------------------------------------------------*/
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 */
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;
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;
}
/*--------------------------------------------------------------------*/
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);
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++;
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;
}