]> err.no Git - varnish/commitdiff
Implement sendfile() support for Linux.
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 12 Sep 2006 10:12:34 +0000 (10:12 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 12 Sep 2006 10:12:34 +0000 (10:12 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@971 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_pool.c

index 96ece6bfbb3fb9a705a2b8dcc1056e503caef594..2ec49fada1ea6b7ff1c631d39de3e26574ec4a92 100644 (file)
@@ -102,19 +102,33 @@ WRK_Write(struct worker *w, const void *ptr, int len)
 void
 WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len)
 {
-       struct sf_hdtr sfh;
        int i;
 
        CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
        assert(fd >= 0);
        assert(len > 0);
 
-       memset(&sfh, 0, sizeof sfh);
-       if (w->niov > 0) {
-               sfh.headers = w->iov;
-               sfh.hdr_cnt = w->niov;
-       }
-       i = sendfile(fd, *w->wfd, off, len, &sfh, NULL, 0);
+#if defined(__FreeBSD__)
+       do {
+               struct sf_hdtr sfh;
+               memset(&sfh, 0, sizeof sfh);
+               if (w->niov > 0) {
+                       sfh.headers = w->iov;
+                       sfh.hdr_cnt = w->niov;
+               }
+               i = sendfile(fd, *w->wfd, off, len, &sfh, NULL, 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);
+       } while (0);
+#else
+#error Unknown sendfile() implementation
+#endif
        if (i != 0)
                w->werr++;
        w->liov = 0;