From 9f537bc1ac4eb39b007156cb62debe3e66e8ad9f Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 6 Apr 2006 09:09:09 +0000 Subject: [PATCH] Add a vca_recycle_session() function which sticks a session back into the acceptors event engine. Do Id keyword git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@127 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 1 + varnish-cache/bin/varnishd/cache_acceptor.c | 30 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 5c306caa..ed2c2db2 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -18,6 +18,7 @@ struct worker; /* cache_acceptor.c */ void *vca_main(void *arg); void vca_retire_session(struct sess *sp); +void vca_recycle_session(struct sess *sp); /* cache_backend.c */ void VBE_Init(void); diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index f5615e17..f8783554 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -1,5 +1,9 @@ /* * $Id$ + * + * XXX: We need to pass sessions back into the event engine when they are + * reused. Not sure what the most efficient way is for that. For now + * write the session pointer to a pipe which the event engine monitors. */ #include @@ -25,6 +29,8 @@ #include "cache.h" static struct event_base *evb; +static struct event pipe_e; +static int pipes[2]; static struct event accept_e[2 * HERITAGE_NSOCKS]; @@ -33,6 +39,17 @@ struct sessmem { struct event e; }; +static void +pipe_f(int fd, short event, void *arg) +{ + struct sess *sp; + int i; + + i = read(fd, &sp, sizeof sp); + assert(i == sizeof sp); + HttpdGetHead(sp, evb, DealWithSession); +} + static void accept_f(int fd, short event, void *arg) { @@ -74,8 +91,13 @@ vca_main(void *arg) unsigned u; struct event *ep; + AZ(pipe(pipes)); evb = event_init(); + event_set(&pipe_e, pipes[0], EV_READ | EV_PERSIST, pipe_f, NULL); + event_base_set(evb, &pipe_e); + event_add(&pipe_e, NULL); + ep = accept_e; for (u = 0; u < HERITAGE_NSOCKS; u++) { if (heritage.sock_local[u] >= 0) { @@ -101,10 +123,18 @@ vca_main(void *arg) return ("FOOBAR"); } +void +vca_recycle_session(struct sess *sp) +{ + VSL(SLT_SessionReuse, sp->fd, "%s", sp->addr); + write(pipes[1], &sp, sizeof sp); +} + void vca_retire_session(struct sess *sp) { + VSL(SLT_SessionClose, sp->fd, "%s", sp->addr); if (sp->fd >= 0) close(sp->fd); free(sp); -- 2.39.5