From: des Date: Fri, 15 Sep 2006 08:14:36 +0000 (+0000) Subject: Fix sendfile() on Linux: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e0c7c191a204a7b2c54d0b2557b1a0d4db549d3;p=varnish Fix sendfile() on Linux: - 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 --- diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 2ec49fad..75de3979 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -4,14 +4,23 @@ * XXX: automatic thread-pool size adaptation. */ -#include -#include -#include -#include -#ifdef HAVE_SENDFILE +#include #include + +#ifdef HAVE_SENDFILE +#if defined(__FreeBSD__) #include +#elif defined(__linux__) +#include +#else +#error Unknown sendfile() implementation +#endif #endif /* HAVE_SENDFILE */ + +#include +#include +#include +#include #include #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 */ diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index 3328bb21..f0dcacea 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -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); }