From: phk Date: Fri, 13 Jul 2007 07:21:46 +0000 (+0000) Subject: Unify the recycle functionality of the acceptors, all three used the same X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a910f46778a3f42490c1136c25119f98f8861985;p=varnish Unify the recycle functionality of the acceptors, all three used the same method. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1683 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 99d012e7..e4302130 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -360,6 +360,7 @@ void vca_return_session(struct sess *sp); void vca_close_session(struct sess *sp, const char *why); void VCA_Prep(struct sess *sp); void VCA_Init(void); +extern int vca_pipes[2]; /* 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 26bb6696..b30da4d7 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -76,6 +76,8 @@ static struct linger linger; static unsigned char need_sndtimeo, need_rcvtimeo, need_linger, need_test; +int vca_pipes[2]; + static void sock_test(int fd) { @@ -255,7 +257,10 @@ vca_return_session(struct sess *sp) CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); AZ(sp->obj); AZ(sp->vcl); - vca_act->recycle(sp); + if (sp->fd < 0) + SES_Delete(sp); + else + assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp)); } @@ -273,6 +278,7 @@ VCA_Init(void) fprintf(stderr, "No acceptor in program\n"); exit (2); } + AZ(pipe(vca_pipes)); vca_act->init(); AZ(pthread_create(&vca_thread_acct, NULL, vca_acct, NULL)); } diff --git a/varnish-cache/bin/varnishd/cache_acceptor.h b/varnish-cache/bin/varnishd/cache_acceptor.h index d578a63b..ce62bc5c 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.h +++ b/varnish-cache/bin/varnishd/cache_acceptor.h @@ -32,12 +32,10 @@ struct sess; typedef void acceptor_init_f(void); -typedef void acceptor_recycle_f(struct sess *); struct acceptor { const char *name; acceptor_init_f *init; - acceptor_recycle_f *recycle; }; #if defined(HAVE_EPOLL_CTL) diff --git a/varnish-cache/bin/varnishd/cache_acceptor_epoll.c b/varnish-cache/bin/varnishd/cache_acceptor_epoll.c index b12f5e2f..ec9fed1d 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_epoll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_epoll.c @@ -48,7 +48,6 @@ static pthread_t vca_epoll_thread; static int epfd = -1; -static int pipes[2]; static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead); @@ -79,12 +78,12 @@ vca_main(void *arg) epfd = epoll_create(16); assert(epfd >= 0); - vca_add(pipes[0], pipes); + vca_add(vca_pipes[0], vca_pipes); while (1) { if (epoll_wait(epfd, &ev, 1, 100) > 0) { - if (ev.data.ptr == pipes) { - i = read(pipes[0], &sp, sizeof sp); + if (ev.data.ptr == vca_pipes) { + i = read(vca_pipes[0], &sp, sizeof sp); assert(i == sizeof sp); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); TAILQ_INSERT_TAIL(&sesshead, sp, list); @@ -119,28 +118,16 @@ vca_main(void *arg) /*--------------------------------------------------------------------*/ -static void -vca_epoll_recycle(struct sess *sp) -{ - - if (sp->fd < 0) - SES_Delete(sp); - else - assert(sizeof sp == write(pipes[1], &sp, sizeof sp)); -} - static void vca_epoll_init(void) { - AZ(pipe(pipes)); AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL)); } struct acceptor acceptor_epoll = { .name = "epoll", .init = vca_epoll_init, - .recycle = vca_epoll_recycle, }; #endif /* defined(HAVE_EPOLL_CTL) */ diff --git a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c index 5da41ff2..92edd145 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c @@ -52,7 +52,6 @@ static pthread_t vca_kqueue_thread; static int kq = -1; static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead); -static int pipes[2]; #define NKEV 100 @@ -81,9 +80,9 @@ vca_kev(struct kevent *kp) struct sess *ss[NKEV]; AN(kp->udata); - if (kp->udata == pipes) { + if (kp->udata == vca_pipes) { j = 0; - i = read(pipes[0], ss, sizeof ss); + i = read(vca_pipes[0], ss, sizeof ss); if (i == -1 && errno == EAGAIN) return; while (i >= sizeof ss[0]) { @@ -135,7 +134,7 @@ vca_kqueue_main(void *arg) j = 0; EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL); - EV_SET(&ke[j++], pipes[0], EVFILT_READ, EV_ADD, 0, 0, pipes); + EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes); AZ(kevent(kq, ke, j, NULL, 0, NULL)); nki = 0; @@ -172,25 +171,14 @@ vca_kqueue_main(void *arg) /*--------------------------------------------------------------------*/ -static void -vca_kqueue_recycle(struct sess *sp) -{ - - if (sp->fd < 0) - SES_Delete(sp); - else - assert(write(pipes[1], &sp, sizeof sp) == sizeof sp); -} - static void vca_kqueue_init(void) { int i; - AZ(pipe(pipes)); - i = fcntl(pipes[0], F_GETFL); + i = fcntl(vca_pipes[0], F_GETFL); i |= O_NONBLOCK; - i = fcntl(pipes[0], F_SETFL, i); + i = fcntl(vca_pipes[0], F_SETFL, i); AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL)); } @@ -198,7 +186,6 @@ vca_kqueue_init(void) struct acceptor acceptor_kqueue = { .name = "kqueue", .init = vca_kqueue_init, - .recycle = vca_kqueue_recycle, }; #endif /* defined(HAVE_KQUEUE) */ diff --git a/varnish-cache/bin/varnishd/cache_acceptor_poll.c b/varnish-cache/bin/varnishd/cache_acceptor_poll.c index 03f8004b..1e2bda21 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_poll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_poll.c @@ -51,8 +51,6 @@ static pthread_t vca_poll_thread; static struct pollfd *pollfd; static unsigned npoll; -static int pipes[2]; - static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead); /*--------------------------------------------------------------------*/ @@ -109,13 +107,13 @@ vca_main(void *arg) (void)arg; - vca_poll(pipes[0]); + vca_poll(vca_pipes[0]); while (1) { v = poll(pollfd, npoll, 100); - if (v && pollfd[pipes[0]].revents) { + if (v && pollfd[vca_pipes[0]].revents) { v--; - i = read(pipes[0], &sp, sizeof sp); + i = read(vca_pipes[0], &sp, sizeof sp); assert(i == sizeof sp); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); TAILQ_INSERT_TAIL(&sesshead, sp, list); @@ -152,27 +150,16 @@ vca_main(void *arg) /*--------------------------------------------------------------------*/ -static void -vca_poll_recycle(struct sess *sp) -{ - - if (sp->fd < 0) - SES_Delete(sp); - else - assert(sizeof sp == write(pipes[1], &sp, sizeof sp)); -} - static void vca_poll_init(void) { - AZ(pipe(pipes)); + AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL)); } struct acceptor acceptor_poll = { .name = "poll", .init = vca_poll_init, - .recycle = vca_poll_recycle, }; #endif /* defined(HAVE_POLL) */