r2149 - in branches/1.1: . bin/varnishd

des at projects.linpro.no des at projects.linpro.no
Fri Oct 19 13:46:03 CEST 2007


Author: des
Date: 2007-10-19 13:46:03 +0200 (Fri, 19 Oct 2007)
New Revision: 2149

Modified:
   branches/1.1/
   branches/1.1/bin/varnishd/cache_pipe.c
Log:
Merged revisions 2057,2077,2080,2086 via svnmerge from 
svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache

........
  r2057 | phk | 2007-09-30 21:42:08 +0200 (Sun, 30 Sep 2007) | 3 lines
  
  Set the poll'ed fd to -1 when we halfclose the fd to avoid
  an infinite loop on certain OS's.
........
  r2077 | phk | 2007-10-01 14:44:19 +0200 (Mon, 01 Oct 2007) | 3 lines
  
  Go over pipe's polling code and try to do it right in one go by
  actually paying attention to what goes on.
........
  r2080 | phk | 2007-10-08 09:19:52 +0200 (Mon, 08 Oct 2007) | 2 lines
  
  Try to make the pipe code even more robust
........
  r2086 | phk | 2007-10-08 12:25:47 +0200 (Mon, 08 Oct 2007) | 3 lines
  
  Drop the asserts around shutdown(2), there are a number of
  legitimate error conditions.
........



Property changes on: branches/1.1
___________________________________________________________________
Name: svnmerge-integrated
   - /trunk/varnish-cache:1-1722,1727-1729,1733,1738,1743-1777,1779-1798,1800-1815,1817,1819,1823,1830-1838,1846,1853-1855,1857-1859,1862,1865-1868,1871-1880,1883-1884,1886,1888-1889,1896,1898,1902-1905,1907,1909,1912-1916,1920-1928,1935-1939,1941-1949,1955,1957-1958,1967-1968,1970-1974,1976-1977,1984,1986-1989,1991-1998,2026,2031-2033,2078-2079,2088,2097,2106-2107,2133
   + /trunk/varnish-cache:1-1722,1727-1729,1733,1738,1743-1777,1779-1798,1800-1815,1817,1819,1823,1830-1838,1846,1853-1855,1857-1859,1862,1865-1868,1871-1880,1883-1884,1886,1888-1889,1896,1898,1902-1905,1907,1909,1912-1916,1920-1928,1935-1939,1941-1949,1955,1957-1958,1967-1968,1970-1974,1976-1977,1984,1986-1989,1991-1998,2026,2031-2033,2057,2077-2080,2086,2088,2097,2106-2107,2133

Modified: branches/1.1/bin/varnishd/cache_pipe.c
===================================================================
--- branches/1.1/bin/varnishd/cache_pipe.c	2007-10-19 11:42:50 UTC (rev 2148)
+++ branches/1.1/bin/varnishd/cache_pipe.c	2007-10-19 11:46:03 UTC (rev 2149)
@@ -42,28 +42,25 @@
 #include "heritage.h"
 #include "cache.h"
 
-static void
-rdf(struct pollfd *fds, int idx)
+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(fds[idx].fd, SHUT_RD));
-		AZ(shutdown(fds[1-idx].fd, SHUT_WR));
-		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(fds[idx].fd, SHUT_WR));
-			AZ(shutdown(fds[1-idx].fd, SHUT_RD));
-			fds[1-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
@@ -109,17 +106,33 @@
 	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)
+		if (i < 1) 
 			break;
-		if (fds[0].revents)
-			rdf(fds, 0);
-		if (fds[1].revents)
-			rdf(fds, 1);
+		if (fds[0].revents && rdf(vc->fd, sp->fd)) {
+			shutdown(vc->fd, SHUT_RD);
+			shutdown(sp->fd, SHUT_WR);
+			fds[0].events = 0;
+			fds[0].fd = -1;
+		}
+		if (fds[1].revents && rdf(sp->fd, vc->fd)) {
+			shutdown(sp->fd, SHUT_RD);
+			shutdown(vc->fd, SHUT_WR);
+			fds[1].events = 0;
+			fds[1].fd = -1;
+		}
 	}
+	if (fds[0].fd >= 0) {
+		shutdown(vc->fd, SHUT_RD);
+		shutdown(sp->fd, SHUT_WR);
+	}
+	if (fds[1].fd >= 0) {
+		shutdown(sp->fd, SHUT_RD);
+		shutdown(vc->fd, SHUT_WR);
+	}
 	vca_close_session(sp, "pipe");
 	VBE_ClosedFd(sp->wrk, vc);
 }




More information about the varnish-commit mailing list