From: des Date: Tue, 11 Mar 2008 11:10:19 +0000 (+0000) Subject: Fix a couple of glaring errors in vca_pollspace(). X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=499db62958acabea5265eb9a4dac7a322d5994c9;p=varnish Fix a couple of glaring errors in vca_pollspace(). Noticed by: Jyri J. Virkki git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2592 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_acceptor_poll.c b/varnish-cache/bin/varnishd/cache_acceptor_poll.c index 3566f889..167d77c7 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_poll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_poll.c @@ -56,23 +56,21 @@ static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); static void vca_pollspace(unsigned fd) { - struct pollfd *p; - unsigned u, v; + struct pollfd *newpollfd; + unsigned newnpoll; if (fd < npoll) return; - if (npoll == 0) - npoll = 16; - for (u = npoll; fd >= u; ) - u += u; - VSL(SLT_Debug, 0, "Acceptor Pollspace %u", u); - p = realloc(pollfd, u * sizeof *p); - XXXAN(p); /* close offending fd */ - memset(p + npoll, 0, (u - npoll) * sizeof *p); - for (v = npoll ; v <= u; v++) - p->fd = -1; - pollfd = p; - npoll = u; + newnpoll = npoll; + while (fd >= newnpoll) + newnpoll = newnpoll * 2 + 1; + VSL(SLT_Debug, 0, "Acceptor poll space increased to %u", newnpoll); + newpollfd = realloc(pollfd, newnpoll * sizeof *pollfd); + XXXAN(newpollfd); /* close offending fd */ + pollfd = newpollfd; + memset(pollfd + npoll, 0, (newnpoll - npoll) * sizeof *pollfd); + while (npoll < newnpoll) + pollfd[npoll++].fd = -1; } /*--------------------------------------------------------------------*/