From b72e82fe8234b84081831e9645c250b70ddafff4 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 7 Sep 2006 05:40:09 +0000 Subject: [PATCH] Read more than one session pointer at a time from the pipe and handle them all with one kevent call. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@936 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- .../bin/varnishd/cache_acceptor_kqueue.c | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c index ec4ea537..f464c9df 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -43,19 +44,29 @@ vca_kq_sess(struct sess *sp, int arm) static void vca_kev(struct kevent *kp) { - int i; + int i, j; struct sess *sp; + struct kevent ke[NKEV]; + struct sess *ss[NKEV]; AN(kp->udata); if (kp->udata == pipes) { - while (kp->data > 0) { - i = read(pipes[0], &sp, sizeof sp); - assert(i == sizeof sp); - kp->data -= i; - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - TAILQ_INSERT_TAIL(&sesshead, sp, list); - vca_kq_sess(sp, EV_ADD); + j = 0; + i = read(pipes[0], ss, sizeof ss); + if (i == -1 && errno == EAGAIN) + return; + while (i >= sizeof ss[0]) { + CHECK_OBJ_NOTNULL(ss[j], SESS_MAGIC); + assert(ss[j]->fd >= 0); + TAILQ_INSERT_TAIL(&sesshead, ss[j], list); + EV_SET(&ke[j], ss[j]->fd, EVFILT_READ, + EV_ADD, 0, 0, ss[j]); + j++; + i -= sizeof ss[0]; } + assert(i == 0); + AZ(kevent(kq, ke, j, NULL, 0, NULL)); + VSL(SLT_Debug, 0, "KQ %d", j); return; } CAST_OBJ_NOTNULL(sp, kp->udata, SESS_MAGIC); @@ -143,8 +154,13 @@ vca_kqueue_recycle(struct sess *sp) static void vca_kqueue_init(void) { + int i; AZ(pipe(pipes)); + i = fcntl(pipes[0], F_GETFL); + i |= O_NONBLOCK; + i = fcntl(pipes[0], F_SETFL, i); + AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL)); } -- 2.39.5