r984 - trunk/varnish-cache/bin/varnishd

des at projects.linpro.no des at projects.linpro.no
Fri Sep 15 10:14:36 CEST 2006


Author: des
Date: 2006-09-15 10:14:36 +0200 (Fri, 15 Sep 2006)
New Revision: 984

Modified:
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
Log:
Fix sendfile() on Linux:

 - use the correct headers
 - don't duplicate WRK_Flush()
 - pass the offset correctly

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-09-15 08:08:28 UTC (rev 983)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-09-15 08:14:36 UTC (rev 984)
@@ -4,14 +4,23 @@
  * XXX: automatic thread-pool size adaptation.
  */
 
+#include <sys/types.h>
+#include <sys/uio.h>
+
+#ifdef HAVE_SENDFILE
+#if defined(__FreeBSD__)
+#include <sys/socket.h>
+#elif defined(__linux__)
+#include <sys/sendfile.h>
+#else
+#error Unknown sendfile() implementation
+#endif
+#endif /* HAVE_SENDFILE */
+
+#include <errno.h>
 #include <stdio.h>
-#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_SENDFILE
-#include <sys/uio.h>
-#include <sys/socket.h>
-#endif /* HAVE_SENDFILE */
 #include <unistd.h>
 
 #include "heritage.h"
@@ -102,7 +111,6 @@
 void
 WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len)
 {
-	int i;
 
 	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
 	assert(fd >= 0);
@@ -116,23 +124,21 @@
 			sfh.headers = w->iov;
 			sfh.hdr_cnt = w->niov;
 		}
-		i = sendfile(fd, *w->wfd, off, len, &sfh, NULL, 0);
+		if (sendfile(fd, *w->wfd, off, len, &sfh, NULL, 0) != 0)
+			w->werr++;
+		w->liov = 0;
+		w->niov = 0;
 	} while (0);
 #elif defined(__linux__)
 	do {
-		if (w->niov > 0 &&
-		    (i = writev(*w->wfd, w->iov, w->niov)) != 0)
-			break;
-		WRK_Flush(w);
-		i = sendfile(*w->wfd, fd, off, len);
+		if (WRK_Flush(w) == 0) {
+			if (sendfile(*w->wfd, fd, &off, len) != 0)
+				w->werr++;
+		}
 	} while (0);
 #else
 #error Unknown sendfile() implementation
 #endif
-	if (i != 0)
-		w->werr++;
-	w->liov = 0;
-	w->niov = 0;
 }
 #endif /* HAVE_SENDFILE */
 

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2006-09-15 08:08:28 UTC (rev 983)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2006-09-15 08:14:36 UTC (rev 984)
@@ -226,7 +226,6 @@
 			AN(st->stevedore);
 			u += st->len;
 			sp->wrk->acct.bodybytes += st->len;
-#ifdef __FreeBSD__
 #ifdef HAVE_SENDFILE
 			/*
 			 * XXX: the overhead of setting up senddile is not
@@ -242,7 +241,6 @@
 				continue;
 			}
 #endif /* HAVE_SENDFILE */
-#endif /* __FreeBSD__ */
 			VSL_stats->n_objwrite++;
 			WRK_Write(sp->wrk, st->ptr, st->len);
 		}




More information about the varnish-commit mailing list