Mailing List Archive

r2592 - trunk/varnish-cache/bin/varnishd
Author: des
Date: 2008-03-11 12:10:19 +0100 (Tue, 11 Mar 2008)
New Revision: 2592

Modified:
trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c
Log:
Fix a couple of glaring errors in vca_pollspace().

Noticed by: Jyri J. Virkki <jyri at virkki.com>


Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2008-03-11 09:48:27 UTC (rev 2591)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2008-03-11 11:10:19 UTC (rev 2592)
@@ -56,23 +56,21 @@
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;
}

/*--------------------------------------------------------------------*/