r2080 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Mon Oct 8 09:19:52 CEST 2007
Author: phk
Date: 2007-10-08 09:19:52 +0200 (Mon, 08 Oct 2007)
New Revision: 2080
Modified:
trunk/varnish-cache/bin/varnishd/cache_pipe.c
Log:
Try to make the pipe code even more robust
Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-10-08 07:18:48 UTC (rev 2079)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-10-08 07:19:52 UTC (rev 2080)
@@ -42,30 +42,25 @@
#include "heritage.h"
#include "cache.h"
-static void
-rdf(struct pollfd *fds, int idx, int fd0, int fd1)
+static int
+rdf(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(fd0, SHUT_RD));
- AZ(shutdown(fd1, SHUT_WR));
- fds[idx].fd = -1;
- fds[idx].events = 0;
- return;
- }
+ i = read(fd0, buf, sizeof buf);
+ if (i <= 0)
+ return (1);
for (p = buf; i > 0; i -= j, p += j) {
- j = write(fds[1-idx].fd, p, i);
- if (j != i) {
- AZ(shutdown(fd0, SHUT_RD));
- AZ(shutdown(fd1, SHUT_WR));
- fds[idx].fd = -1;
- fds[idx].events = 0;
- return;
+ j = write(fd1, p, i);
+ if (j <= 0)
+ return (1);
+ if (i != j) {
+ printf("flunk %d %d\n", i, j);
+ usleep(100000); /* XXX hack */
}
}
+ return (0);
}
void
@@ -110,24 +105,32 @@
fds[1].fd = sp->fd;
fds[1].events = POLLIN | POLLERR;
- while (fds[0].events || fds[1].events) {
+ while (fds[0].fd > -1 || fds[1].fd > -1) {
fds[0].revents = 0;
fds[1].revents = 0;
i = poll(fds, 2, params->pipe_timeout * 1000);
if (i < 1)
break;
- if (fds[0].revents)
- rdf(fds, 0, vc->fd, sp->fd);
- if (fds[1].revents)
- rdf(fds, 1, sp->fd, vc->fd);
+ if (fds[0].revents && rdf(vc->fd, sp->fd)) {
+ AZ(shutdown(vc->fd, SHUT_RD));
+ AZ(shutdown(sp->fd, SHUT_WR));
+ fds[0].events = 0;
+ fds[0].fd = -1;
+ }
+ if (fds[1].revents && rdf(sp->fd, vc->fd)) {
+ AZ(shutdown(sp->fd, SHUT_RD));
+ AZ(shutdown(vc->fd, SHUT_WR));
+ fds[1].events = 0;
+ fds[1].fd = -1;
+ }
}
if (fds[0].fd >= 0) {
- AZ(shutdown(fds[0].fd, SHUT_RD));
- AZ(shutdown(fds[1].fd, SHUT_WR));
+ AZ(shutdown(vc->fd, SHUT_RD));
+ AZ(shutdown(sp->fd, SHUT_WR));
}
if (fds[1].fd >= 0) {
- AZ(shutdown(fds[1].fd, SHUT_RD));
- AZ(shutdown(fds[0].fd, SHUT_WR));
+ AZ(shutdown(sp->fd, SHUT_RD));
+ AZ(shutdown(vc->fd, SHUT_WR));
}
vca_close_session(sp, "pipe");
VBE_ClosedFd(sp->wrk, vc);
More information about the varnish-commit
mailing list