Commit de1377c7 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Give storage backends a "send" method.

Let storage_file use sendfile(2) for it.



git-svn-id: http://www.varnish-cache.org/svn/trunk@180 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 15a6d222
......@@ -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);
}
......
......@@ -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;
......
......@@ -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
};
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