]> err.no Git - varnish/commitdiff
Fix sendfile() on Linux:
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 15 Sep 2006 08:14:36 +0000 (08:14 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 15 Sep 2006 08:14:36 +0000 (08:14 +0000)
 - use the correct headers
 - don't duplicate WRK_Flush()
 - pass the offset correctly

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@984 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/bin/varnishd/cache_response.c

index 2ec49fada1ea6b7ff1c631d39de3e26574ec4a92..75de3979155c135983ccfca0a96f3346dd5523bd 100644 (file)
@@ -4,14 +4,23 @@
  * XXX: automatic thread-pool size adaptation.
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_SENDFILE
+#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 <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include "heritage.h"
@@ -102,7 +111,6 @@ WRK_Write(struct worker *w, const void *ptr, int len)
 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 @@ WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len)
                        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 */
 
index 3328bb214d1015eeb7765883fd9be408d5105ba9..f0dcacea0a0b04339ba3c1f1c9835cd56ca3ad67 100644 (file)
@@ -226,7 +226,6 @@ RES_WriteObj(struct sess *sp)
                        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 @@ RES_WriteObj(struct sess *sp)
                                continue;
                        }
 #endif /* HAVE_SENDFILE */
-#endif /* __FreeBSD__ */
                        VSL_stats->n_objwrite++;
                        WRK_Write(sp->wrk, st->ptr, st->len);
                }