Commit 059f71aa authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

First step of slow client handling: Lose the stevedore function

for sending and instead record the fd+off_t in the storage object.

This eliminates sendfile from storage_file.c, next step is to put
it back in the generic code in cache_response.c





git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@708 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 70e1a305
......@@ -134,11 +134,15 @@ struct storage {
unsigned magic;
#define STORAGE_MAGIC 0x1a4e51c0
TAILQ_ENTRY(storage) list;
struct stevedore *stevedore;
void *priv;
unsigned char *ptr;
unsigned len;
unsigned space;
void *priv;
struct stevedore *stevedore;
int fd;
off_t where;
};
#include "stevedore.h"
......
......@@ -155,7 +155,6 @@ RES_WriteObj(struct sess *sp)
sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
/* XXX: conditional request handling */
if (sp->wantbody) {
TAILQ_FOREACH(st, &sp->obj->store, list) {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
......@@ -163,15 +162,7 @@ RES_WriteObj(struct sess *sp)
assert(st->stevedore != NULL);
u += st->len;
sp->wrk->acct.bodybytes += st->len;
if (st->stevedore->send == NULL) {
WRK_Write(sp->wrk, st->ptr, st->len);
} else {
st->stevedore->send(st, sp);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
sp->wrk->niov = 0;
sp->wrk->liov = 0;
}
WRK_Write(sp->wrk, st->ptr, st->len);
}
assert(u == sp->obj->len);
}
......
......@@ -11,7 +11,6 @@ typedef void storage_open_f(struct stevedore *);
typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
typedef void storage_trim_f(struct storage *, size_t size);
typedef void storage_free_f(struct storage *);
typedef void storage_send_f(struct storage *, struct sess *);
struct stevedore {
const char *name;
......@@ -20,7 +19,6 @@ struct stevedore {
storage_alloc_f *alloc;
storage_trim_f *trim;
storage_free_f *free;
storage_send_f *send;
/* private fields */
void *priv;
......
......@@ -515,6 +515,8 @@ smf_alloc(struct stevedore *st, size_t size)
smf->s.ptr = smf->ptr;
smf->s.len = 0;
smf->s.stevedore = st;
smf->s.fd = smf->sc->fd;
smf->s.where = smf->offset;
CHECK_OBJ_NOTNULL(&smf->s, STORAGE_MAGIC);
return (&smf->s);
}
......@@ -566,43 +568,6 @@ smf_free(struct storage *s)
/*--------------------------------------------------------------------*/
static void
smf_send(struct storage *st, struct sess *sp)
{
struct smf *smf;
int i;
off_t sent;
struct sf_hdtr sfh;
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
CAST_OBJ_NOTNULL(smf, st->priv, SMF_MAGIC);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
memset(&sfh, 0, sizeof sfh);
sfh.headers = sp->wrk->iov;
sfh.hdr_cnt = sp->wrk->niov;
i = sendfile(smf->sc->fd,
sp->fd,
smf->offset,
st->len, &sfh, &sent, 0);
/* Check again after potentially long sleep */
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
CHECK_OBJ_NOTNULL(smf, SMF_MAGIC);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (sent == st->len + sp->wrk->liov)
return;
vca_close_session(sp, "remote closed");
if (errno == EPIPE || errno == ENOTCONN)
return;
VSL(SLT_Debug, sp->fd,
"sent i=%d sent=%ju size=%ju liov=%ju errno=%d\n",
i, (uintmax_t)sent, (uintmax_t)st->len,
(uintmax_t)sp->wrk->liov, errno);
}
/*--------------------------------------------------------------------*/
struct stevedore smf_stevedore = {
.name = "file",
.init = smf_init,
......@@ -610,7 +575,6 @@ struct stevedore smf_stevedore = {
.alloc = smf_alloc,
.trim = smf_trim,
.free = smf_free,
.send = smf_send
};
#ifdef INCLUDE_TEST_DRIVER
......
......@@ -24,6 +24,7 @@ sma_alloc(struct stevedore *st, size_t size)
assert(sma->s.ptr != NULL);
sma->s.len = 0;
sma->s.space = size;
sma->s.fd = -1;
sma->s.stevedore = st;
return (&sma->s);
}
......
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