r2077 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Mon Oct 1 14:44:19 CEST 2007
Author: phk
Date: 2007-10-01 14:44:19 +0200 (Mon, 01 Oct 2007)
New Revision: 2077
Modified:
trunk/varnish-cache/bin/varnishd/cache_pipe.c
Log:
Go over pipe's polling code and try to do it right in one go by
actually paying attention to what goes on.
Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-10-01 12:27:49 UTC (rev 2076)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-10-01 12:44:19 UTC (rev 2077)
@@ -43,15 +43,15 @@
#include "cache.h"
static void
-rdf(struct pollfd *fds, int idx)
+rdf(struct pollfd *fds, int idx, int fd0, int fd1)
{
int i, j;
char buf[BUFSIZ], *p;
i = read(fds[idx].fd, buf, sizeof buf);
if (i <= 0 || fds[1-idx].events == 0) {
- AZ(shutdown(fds[idx].fd, SHUT_RD));
- AZ(shutdown(fds[1-idx].fd, SHUT_WR));
+ AZ(shutdown(fd0, SHUT_RD));
+ AZ(shutdown(fd1, SHUT_WR));
fds[idx].fd = -1;
fds[idx].events = 0;
return;
@@ -59,10 +59,10 @@
for (p = buf; i > 0; i -= j, p += j) {
j = write(fds[1-idx].fd, p, i);
if (j != i) {
- AZ(shutdown(fds[idx].fd, SHUT_WR));
- AZ(shutdown(fds[1-idx].fd, SHUT_RD));
- fds[1-idx].fd = -1;
- fds[1-idx].events = 0;
+ AZ(shutdown(fd0, SHUT_RD));
+ AZ(shutdown(fd1, SHUT_WR));
+ fds[idx].fd = -1;
+ fds[idx].events = 0;
return;
}
}
@@ -114,13 +114,21 @@
fds[0].revents = 0;
fds[1].revents = 0;
i = poll(fds, 2, params->pipe_timeout * 1000);
- if (i != 1)
+ if (i < 1)
break;
if (fds[0].revents)
- rdf(fds, 0);
+ rdf(fds, 0, vc->fd, sp->fd);
if (fds[1].revents)
- rdf(fds, 1);
+ rdf(fds, 1, sp->fd, vc->fd);
}
+ if (fds[0].fd >= 0) {
+ AZ(shutdown(fds[0].fd, SHUT_RD));
+ AZ(shutdown(fds[1].fd, SHUT_WR));
+ }
+ if (fds[1].fd >= 0) {
+ AZ(shutdown(fds[1].fd, SHUT_RD));
+ AZ(shutdown(fds[0].fd, SHUT_WR));
+ }
vca_close_session(sp, "pipe");
VBE_ClosedFd(sp->wrk, vc);
}
More information about the varnish-commit
mailing list