Commit aaa1cf69 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Fix sendfile() on Linux:

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

git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@984 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 6d46c3f3
...@@ -4,14 +4,23 @@ ...@@ -4,14 +4,23 @@
* XXX: automatic thread-pool size adaptation. * XXX: automatic thread-pool size adaptation.
*/ */
#include <stdio.h> #include <sys/types.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_SENDFILE
#include <sys/uio.h> #include <sys/uio.h>
#ifdef HAVE_SENDFILE
#if defined(__FreeBSD__)
#include <sys/socket.h> #include <sys/socket.h>
#elif defined(__linux__)
#include <sys/sendfile.h>
#else
#error Unknown sendfile() implementation
#endif
#endif /* HAVE_SENDFILE */ #endif /* HAVE_SENDFILE */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "heritage.h" #include "heritage.h"
...@@ -102,7 +111,6 @@ WRK_Write(struct worker *w, const void *ptr, int len) ...@@ -102,7 +111,6 @@ WRK_Write(struct worker *w, const void *ptr, int len)
void void
WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len) WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len)
{ {
int i;
CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
assert(fd >= 0); assert(fd >= 0);
...@@ -116,23 +124,21 @@ WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len) ...@@ -116,23 +124,21 @@ WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len)
sfh.headers = w->iov; sfh.headers = w->iov;
sfh.hdr_cnt = w->niov; 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); } while (0);
#elif defined(__linux__) #elif defined(__linux__)
do { do {
if (w->niov > 0 && if (WRK_Flush(w) == 0) {
(i = writev(*w->wfd, w->iov, w->niov)) != 0) if (sendfile(*w->wfd, fd, &off, len) != 0)
break; w->werr++;
WRK_Flush(w); }
i = sendfile(*w->wfd, fd, off, len);
} while (0); } while (0);
#else #else
#error Unknown sendfile() implementation #error Unknown sendfile() implementation
#endif #endif
if (i != 0)
w->werr++;
w->liov = 0;
w->niov = 0;
} }
#endif /* HAVE_SENDFILE */ #endif /* HAVE_SENDFILE */
......
...@@ -226,7 +226,6 @@ RES_WriteObj(struct sess *sp) ...@@ -226,7 +226,6 @@ RES_WriteObj(struct sess *sp)
AN(st->stevedore); AN(st->stevedore);
u += st->len; u += st->len;
sp->wrk->acct.bodybytes += st->len; sp->wrk->acct.bodybytes += st->len;
#ifdef __FreeBSD__
#ifdef HAVE_SENDFILE #ifdef HAVE_SENDFILE
/* /*
* XXX: the overhead of setting up senddile is not * XXX: the overhead of setting up senddile is not
...@@ -242,7 +241,6 @@ RES_WriteObj(struct sess *sp) ...@@ -242,7 +241,6 @@ RES_WriteObj(struct sess *sp)
continue; continue;
} }
#endif /* HAVE_SENDFILE */ #endif /* HAVE_SENDFILE */
#endif /* __FreeBSD__ */
VSL_stats->n_objwrite++; VSL_stats->n_objwrite++;
WRK_Write(sp->wrk, st->ptr, st->len); WRK_Write(sp->wrk, st->ptr, st->len);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment