From 2aebd2efd0b621b766bcef049fa6670beeee6754 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 9 Oct 2007 07:22:46 +0000 Subject: [PATCH] Keep track of the highest fd so we don't give poll(2) more pfd's to chew than necessary. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2096 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_acceptor_poll.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_acceptor_poll.c b/varnish-cache/bin/varnishd/cache_acceptor_poll.c index 7cb29803..f0f82ddd 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_poll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_poll.c @@ -46,7 +46,7 @@ static pthread_t vca_poll_thread; static struct pollfd *pollfd; -static unsigned npoll; +static unsigned npoll, hpoll; static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); @@ -82,6 +82,8 @@ vca_poll(int fd) assert(fd >= 0); vca_pollspace((unsigned)fd); + if (hpoll < fd) + hpoll = fd; pollfd[fd].fd = fd; pollfd[fd].events = POLLIN; } @@ -94,6 +96,10 @@ vca_unpoll(int fd) vca_pollspace((unsigned)fd); pollfd[fd].fd = -1; pollfd[fd].events = 0; + if (hpoll == fd) { + while (pollfd[--hpoll].fd == -1) + continue; + } } /*--------------------------------------------------------------------*/ @@ -111,7 +117,7 @@ vca_main(void *arg) vca_poll(vca_pipes[0]); while (1) { - v = poll(pollfd, npoll, 100); + v = poll(pollfd, hpoll + 1, 100); if (v && pollfd[vca_pipes[0]].revents) { v--; i = read(vca_pipes[0], &sp, sizeof sp); -- 2.39.5