From 00d2353d3f59a87351c2f331165ea5702683cd22 Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 14 Jun 2006 09:03:45 +0000 Subject: [PATCH] Sanitize close/recycle session logic a bit. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@182 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 4 +-- varnish-cache/bin/varnishd/cache_acceptor.c | 28 +++++++++++++-------- varnish-cache/bin/varnishd/cache_pipe.c | 3 +-- varnish-cache/bin/varnishd/cache_pool.c | 11 +++----- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 4ce785b1..212bd91e 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -60,8 +60,8 @@ extern struct stevedore *stevedore; /* cache_acceptor.c */ void vca_write(struct sess *sp, void *ptr, size_t len); void vca_flush(struct sess *sp); -void vca_retire_session(struct sess *sp); -void vca_recycle_session(struct sess *sp); +void vca_return_session(struct sess *sp); +void vca_close_session(struct sess *sp); void VCA_Init(void); /* cache_backend.c */ diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 8eff0542..0e8988e0 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -66,8 +66,7 @@ vca_flush(struct sess *sp) if (i != sp->mem->liov) { VSL(SLT_SessionClose, sp->fd, "Premature %d of %d", i, sp->mem->liov); - close(sp->fd); - sp->fd = -1; + vca_close_session(sp); } sp->mem->liov = 0; sp->mem->niov = 0; @@ -178,24 +177,31 @@ vca_main(void *arg) return ("FOOBAR"); } +/*--------------------------------------------------------------------*/ + void -vca_recycle_session(struct sess *sp) +vca_close_session(struct sess *sp) { - VSL(SLT_SessionReuse, sp->fd, "%s", sp->addr); - write(pipes[1], &sp, sizeof sp); + + VSL(SLT_SessionClose, sp->fd, "%s", sp->addr); + close(sp->fd); + sp->fd = -1; } +/*--------------------------------------------------------------------*/ + void -vca_retire_session(struct sess *sp) +vca_return_session(struct sess *sp) { - if (sp->http != NULL) - http_Delete(sp->http); if (sp->fd >= 0) { - VSL(SLT_SessionClose, sp->fd, "%s", sp->addr); - close(sp->fd); + VSL(SLT_SessionReuse, sp->fd, "%s", sp->addr); + write(pipes[1], &sp, sizeof sp); + } else { + if (sp->http != NULL) + http_Delete(sp->http); + free(sp); } - free(sp); } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index 9f02ce92..1bdd3521 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -75,7 +75,6 @@ PipeSession(struct worker *w, struct sess *sp) event_add(&e2.ev, NULL); event_base_loop(w->eb, 0); close (fd); - close (sp->fd); + vca_close_session(sp); 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 8fafd6bc..8bceb093 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -159,17 +159,13 @@ CacheWorker(void *priv) if (http_GetHdr(sp->http, "Connection", &b) && !strcmp(b, "close")) { VSL(SLT_SessionClose, sp->fd, "hdr"); - close(sp->fd); - sp->fd = -1; + vca_close_session(sp); } AZ(pthread_mutex_lock(&sessmtx)); RelVCL(sp->vcl); sp->vcl = NULL; - if (sp->fd < 0) - vca_retire_session(sp); - else - vca_recycle_session(sp); + vca_return_session(sp); } } @@ -179,7 +175,8 @@ DealWithSession(void *arg, int good) struct sess *sp = arg; if (!good) { - vca_retire_session(sp); + vca_close_session(sp); + vca_return_session(sp); return; } AZ(pthread_mutex_lock(&sessmtx)); -- 2.39.5