"\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);
}
*/
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;
storage_open_f *open; /* called by cache process */
storage_alloc_f *alloc;
storage_free_f *free;
+ storage_send_f *send;
/* private fields */
void *priv;
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/mman.h>
+#include <sys/socket.h>
#include "vcl_lang.h"
#include "libvarnish.h"
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);
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)
{
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
};