From 9c48316e7035c72a6412ceba5a4771a4ae37c2f6 Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 5 Apr 2006 09:40:22 +0000 Subject: [PATCH] Account for the last byte of the header. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@118 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/autogen.sh | 13 +++++ varnish-cache/bin/varnishd/cache.h | 14 ++++- varnish-cache/bin/varnishd/cache_httpd.c | 2 +- varnish-cache/bin/varnishd/cache_pass.c | 71 +++++++++++------------- varnish-cache/bin/varnishd/cache_pipe.c | 42 +++++++------- varnish-cache/bin/varnishd/cache_pool.c | 15 ++++- 6 files changed, 91 insertions(+), 66 deletions(-) diff --git a/varnish-cache/autogen.sh b/varnish-cache/autogen.sh index d8330d31..9fa4d1a9 100755 --- a/varnish-cache/autogen.sh +++ b/varnish-cache/autogen.sh @@ -3,6 +3,8 @@ # $Id$ # +set -ex + if [ -d /usr/local/gnu-autotools/bin ] ; then PATH=${PATH}:/usr/local/gnu-autotools/bin export PATH @@ -10,6 +12,7 @@ fi base=$(cd $(dirname $0) && pwd) for dir in $base $base/contrib/libevent ; do + ( echo $dir cd $dir aclocal @@ -17,4 +20,14 @@ for dir in $base $base/contrib/libevent ; do autoheader automake --add-missing --copy --force --foreign autoconf + ) done + +sh configure \ + --enable-pedantic \ + --enable-wall \ + --enable-werror \ + --enable-dependency-tracking + +# This is a safety-measure during development +( cd lib/libvcl && ./*.tcl ) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 156eb5bd..cc0742c6 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -4,6 +4,16 @@ struct event_base; +#ifdef EV_TIMEOUT +struct worker { + struct event_base *eb; + struct event e1, e2; + struct sbuf *sb; +}; +#else +struct worker; +#endif + /* cache_acceptor.c */ void *vca_main(void *arg); void vca_retire_session(struct sess *sp); @@ -22,10 +32,10 @@ void HttpdGetHead(struct sess *sp, struct event_base *eb, sesscb_f *func); pthread_mutex_t sessmtx; /* cache_pass.c */ -void PassSession(struct sess *sp); +void PassSession(struct worker *w, struct sess *sp); /* cache_pipe.c */ -void PipeSession(struct sess *sp); +void PipeSession(struct worker *w, struct sess *sp); /* cache_pool.c */ void CacheInitPool(void); diff --git a/varnish-cache/bin/varnishd/cache_httpd.c b/varnish-cache/bin/varnishd/cache_httpd.c index 32ddbd65..c8897a71 100644 --- a/varnish-cache/bin/varnishd/cache_httpd.c +++ b/varnish-cache/bin/varnishd/cache_httpd.c @@ -163,7 +163,7 @@ http_read_f(int fd, short event, void *arg) continue; break; } - sp->hdr_end = p - sp->rcv; + sp->hdr_end = ++p - sp->rcv; VSL(SLT_Debug, 0, "HTTP %u %u", sp->rcv_len, sp->hdr_end); event_del(sp->rd_e); sp->sesscb(sp); diff --git a/varnish-cache/bin/varnishd/cache_pass.c b/varnish-cache/bin/varnishd/cache_pass.c index 43606d66..1e6fb11d 100644 --- a/varnish-cache/bin/varnishd/cache_pass.c +++ b/varnish-cache/bin/varnishd/cache_pass.c @@ -31,71 +31,66 @@ PassReturn(struct sess *sp) /*--------------------------------------------------------------------*/ void -PassSession(struct sess *sp) +PassSession(struct worker *w, struct sess *sp) { int fd, i, j; void *fd_token; - struct sbuf *sb; - struct event_base *eb; struct sess sp2; - struct event ev; char buf[BUFSIZ]; off_t cl; fd = VBE_GetFd(sp->backend, &fd_token); assert(fd != -1); - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); - assert(sb != NULL); - sbuf_cat(sb, sp->http.req); - sbuf_cat(sb, " "); - sbuf_cat(sb, sp->http.url); - sbuf_cat(sb, " "); - sbuf_cat(sb, sp->http.proto); - sbuf_cat(sb, "\r\n"); + sbuf_clear(w->sb); + assert(w->sb != NULL); + sbuf_cat(w->sb, sp->http.req); + sbuf_cat(w->sb, " "); + sbuf_cat(w->sb, sp->http.url); + sbuf_cat(w->sb, " "); + sbuf_cat(w->sb, sp->http.proto); + sbuf_cat(w->sb, "\r\n"); #define HTTPH(a, b, c, d, e, f, g) \ do { \ if (d && sp->http.b != NULL) { \ - sbuf_cat(sb, a ": "); \ - sbuf_cat(sb, sp->http.b); \ - sbuf_cat(sb, "\r\n"); \ + sbuf_cat(w->sb, a ": "); \ + sbuf_cat(w->sb, sp->http.b); \ + sbuf_cat(w->sb, "\r\n"); \ } \ } while (0); #include "http_headers.h" #undef HTTPH - sbuf_cat(sb, "\r\n"); - sbuf_finish(sb); - i = write(fd, sbuf_data(sb), sbuf_len(sb)); - assert(i == sbuf_len(sb)); + sbuf_cat(w->sb, "\r\n"); + sbuf_finish(w->sb); + i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb)); + assert(i == sbuf_len(w->sb)); memset(&sp2, 0, sizeof sp2); - memset(&ev, 0, sizeof ev); - sp2.rd_e = &ev; + sp2.rd_e = &w->e1; sp2.fd = fd; - eb = event_init(); - HttpdGetHead(&sp2, eb, PassReturn); - event_base_loop(eb, 0); - sbuf_clear(sb); - sbuf_cat(sb, sp2.http.proto); - sbuf_cat(sb, " "); - sbuf_cat(sb, sp2.http.status); - sbuf_cat(sb, " "); - sbuf_cat(sb, sp2.http.response); - sbuf_cat(sb, "\r\n"); + HttpdGetHead(&sp2, w->eb, PassReturn); + event_base_loop(w->eb, 0); + sbuf_clear(w->sb); + sbuf_cat(w->sb, sp2.http.proto); + sbuf_cat(w->sb, " "); + sbuf_cat(w->sb, sp2.http.status); + sbuf_cat(w->sb, " "); + sbuf_cat(w->sb, sp2.http.response); + sbuf_cat(w->sb, "\r\n"); #define HTTPH(a, b, c, d, e, f, g) \ do { \ if (d && sp2.http.b != NULL) { \ - sbuf_cat(sb, a ": "); \ - sbuf_cat(sb, sp2.http.b); \ - sbuf_cat(sb, "\r\n"); \ + sbuf_cat(w->sb, a ": "); \ + sbuf_cat(w->sb, sp2.http.b); \ + sbuf_cat(w->sb, "\r\n"); \ } \ } while (0); #include "http_headers.h" #undef HTTPH - sbuf_cat(sb, "\r\n"); - sbuf_finish(sb); - i = write(sp->fd, sbuf_data(sb), sbuf_len(sb)); - assert(i == sbuf_len(sb)); + sbuf_cat(w->sb, "\r\n"); + sbuf_finish(w->sb); + i = write(sp->fd, sbuf_data(w->sb), sbuf_len(w->sb)); + assert(i == sbuf_len(w->sb)); if (sp2.http.H_Content_Length != NULL) { cl = strtoumax(sp2.http.H_Content_Length, NULL, 0); VSL(SLT_Debug, 0, "CL %ju %u %u", cl, sp->rcv_len, sp->hdr_end); diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index 80eae135..a8257d05 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -42,55 +42,51 @@ rdf(int fd, short event, void *arg) } void -PipeSession(struct sess *sp) +PipeSession(struct worker *w, struct sess *sp) { int fd, i; void *fd_token; - struct sbuf *sb; - struct event_base *eb; struct edir e1, e2; fd = VBE_GetFd(sp->backend, &fd_token); assert(fd != -1); - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); - assert(sb != NULL); - sbuf_cat(sb, sp->http.req); - sbuf_cat(sb, " "); - sbuf_cat(sb, sp->http.url); + sbuf_clear(w->sb); + assert(w->sb != NULL); + sbuf_cat(w->sb, sp->http.req); + sbuf_cat(w->sb, " "); + sbuf_cat(w->sb, sp->http.url); if (sp->http.proto != NULL) { - sbuf_cat(sb, " "); - sbuf_cat(sb, sp->http.proto); + sbuf_cat(w->sb, " "); + sbuf_cat(w->sb, sp->http.proto); } - sbuf_cat(sb, "\r\n"); + sbuf_cat(w->sb, "\r\n"); #define HTTPH(a, b, c, d, e, f, g) \ do { \ if (sp->http.b != NULL) { \ - sbuf_cat(sb, a ": "); \ - sbuf_cat(sb, sp->http.b); \ - sbuf_cat(sb, "\r\n"); \ + sbuf_cat(w->sb, a ": "); \ + sbuf_cat(w->sb, sp->http.b); \ + sbuf_cat(w->sb, "\r\n"); \ } \ } while (0); #include "http_headers.h" #undef HTTPH - sbuf_cat(sb, "\r\n"); - sbuf_finish(sb); - i = write(fd, sbuf_data(sb), sbuf_len(sb)); - assert(i == sbuf_len(sb)); + sbuf_cat(w->sb, "\r\n"); + sbuf_finish(w->sb); + i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb)); + assert(i == sbuf_len(w->sb)); e1.fd = fd; e2.fd = sp->fd; - eb = event_init(); event_set(&e1.ev, sp->fd, EV_READ | EV_PERSIST, rdf, &e1); - event_base_set(eb, &e1.ev); + event_base_set(w->eb, &e1.ev); event_set(&e2.ev, fd, EV_READ | EV_PERSIST, rdf, &e2); - event_base_set(eb, &e2.ev); + event_base_set(w->eb, &e2.ev); event_add(&e1.ev, NULL); event_add(&e2.ev, NULL); - event_base_loop(eb, 0); + event_base_loop(w->eb, 0); close (fd); close (sp->fd); - /* XXX: Delete eb */ VBE_ClosedFd(fd_token); sp->fd = -1; } diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index d1a15939..04a4b8d4 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -3,9 +3,13 @@ */ #include +#include #include #include #include +#include +#include +#include #include "libvarnish.h" #include "vcl_lang.h" @@ -19,7 +23,14 @@ static void * CacheWorker(void *priv) { struct sess *sp; + struct worker w; + memset(&w, 0, sizeof w); + w.eb = event_init(); + assert(w.eb != NULL); + w.sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); + assert(w.sb != NULL); + (void)priv; AZ(pthread_mutex_lock(&sessmtx)); while (1) { @@ -42,9 +53,9 @@ CacheWorker(void *priv) printf("Handling: %d\n", sp->handling); if (0) { - PipeSession(sp); + PipeSession(&w, sp); } else { - PassSession(sp); + PassSession(&w, sp); } AZ(pthread_mutex_lock(&sessmtx)); -- 2.39.5