From d5866a2797437bf5b5b06d8ac036f4991650c949 Mon Sep 17 00:00:00 2001 From: des Date: Tue, 12 Sep 2006 10:12:34 +0000 Subject: [PATCH] Implement sendfile() support for Linux. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@971 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_pool.c | 28 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 96ece6bf..2ec49fad 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -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; -- 2.39.5