Commit 7b8a9976 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Account for the last byte of the header.


git-svn-id: http://www.varnish-cache.org/svn/trunk@118 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent b262c869
......@@ -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 )
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
}
......@@ -3,9 +3,13 @@
*/
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <pthread.h>
#include <queue.h>
#include <sys/time.h>
#include <sbuf.h>
#include <event.h>
#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));
......
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