]> err.no Git - varnish/commitdiff
Give storage backends a "send" method.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 14 Jun 2006 07:21:48 +0000 (07:21 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 14 Jun 2006 07:21:48 +0000 (07:21 +0000)
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

varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/bin/varnishd/stevedore.h
varnish-cache/bin/varnishd/storage_file.c

index 32816a41a1a8551c72d400a189b561350a56a58c..8fafd6bcf6bce3cd9a99fd8395e113af778da91d 100644 (file)
@@ -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);
 }
index 41ba35a74dd8bcd7c6a61dc5f14078009a915315..084bd926f9476a09012b88a800c96dc7a4cdbf41 100644 (file)
@@ -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;
index d81461a636a8031b7264832dac394f3a2b5ffd80..3ad62fbec41705d2ff658455b0bdf07527789ebb 100644 (file)
@@ -19,6 +19,7 @@
 #include <sys/param.h>
 #include <sys/mount.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
 
 #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
 };