From: phk Date: Wed, 14 Jun 2006 07:21:48 +0000 (+0000) Subject: Give storage backends a "send" method. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=228a45482d1de78217997e7b1a770e28179f2f83;p=varnish Give storage backends a "send" method. Let storage_file use sendfile(2) for it. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@180 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 32816a41..8fafd6bc 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -78,8 +78,12 @@ DeliverSession(struct worker *w, struct sess *sp) "\r\n", sp->obj->len); vca_write(sp, buf, strlen(buf)); - TAILQ_FOREACH(st, &sp->obj->store, list) - vca_write(sp, st->ptr, st->len); + TAILQ_FOREACH(st, &sp->obj->store, list) { + if (st->stevedore->send != NULL) + st->stevedore->send(st, sp); + else + vca_write(sp, st->ptr, st->len); + } vca_flush(sp); return (1); } diff --git a/varnish-cache/bin/varnishd/stevedore.h b/varnish-cache/bin/varnishd/stevedore.h index 41ba35a7..084bd926 100644 --- a/varnish-cache/bin/varnishd/stevedore.h +++ b/varnish-cache/bin/varnishd/stevedore.h @@ -3,11 +3,13 @@ */ struct stevedore; +struct sess; typedef void storage_init_f(struct stevedore *, const char *spec); typedef void storage_open_f(struct stevedore *); typedef struct storage *storage_alloc_f(struct stevedore *, size_t size); typedef void storage_free_f(struct storage *); +typedef void storage_send_f(struct storage *, struct sess *); struct stevedore { const char *name; @@ -15,6 +17,7 @@ struct stevedore { storage_open_f *open; /* called by cache process */ storage_alloc_f *alloc; storage_free_f *free; + storage_send_f *send; /* private fields */ void *priv; diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index d81461a6..3ad62fbe 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "vcl_lang.h" #include "libvarnish.h" @@ -409,7 +410,7 @@ smf_open_chunk(struct smf_sc *sc, off_t sz, off_t off, off_t *fail, off_t *sum) if (sz < *fail && sz < SIZE_T_MAX) { p = mmap(NULL, sz, PROT_READ|PROT_WRITE, - MAP_NOCORE | MAP_NOSYNC | MAP_PRIVATE, sc->fd, off); + MAP_NOCORE | MAP_NOSYNC | MAP_SHARED, sc->fd, off); if (p != MAP_FAILED) { (*sum) += sz; new_smf(sc, p, off, sz); @@ -459,9 +460,12 @@ smf_alloc(struct stevedore *st, unsigned size) smf->s.priv = smf; smf->s.ptr = smf->ptr; smf->s.len = size; + smf->s.stevedore = st; return (&smf->s); } +/*--------------------------------------------------------------------*/ + static void smf_free(struct storage *s) { @@ -471,10 +475,34 @@ smf_free(struct storage *s) free_smf(smf); } +/*--------------------------------------------------------------------*/ + +static void +smf_send(struct storage *st, struct sess *sp) +{ + struct smf *smf; + int i; + off_t sent; + + smf = st->priv; + + printf("SEND %12p %12p %12jx %12jx\n", (void*)smf, (void*)smf->ptr, (uintmax_t)smf->offset, (uintmax_t)smf->size); + vca_flush(sp); + i = sendfile(smf->sc->fd, + sp->fd, + smf->offset, + st->len, NULL, &sent, 0); + printf("sent i=%d sent=%ju size=%ju\n", + i, (uintmax_t)sent, (uintmax_t)st->len); +} + +/*--------------------------------------------------------------------*/ + struct stevedore smf_stevedore = { "file", smf_init, smf_open, smf_alloc, - smf_free + smf_free, + smf_send };