From: phk Date: Mon, 7 Aug 2006 08:42:58 +0000 (+0000) Subject: First step of slow client handling: Lose the stevedore function X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=061ba585a70dd6f3c9a66a58e09108bc2635e3a7;p=varnish 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: svn+ssh://projects.linpro.no/svn/varnish/trunk@708 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index add40e89..e560c68a 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -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" diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index 1eb9b04b..d4ccf523 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/stevedore.h b/varnish-cache/bin/varnishd/stevedore.h index 89548e81..a1fdb6bd 100644 --- a/varnish-cache/bin/varnishd/stevedore.h +++ b/varnish-cache/bin/varnishd/stevedore.h @@ -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; diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index 02168493..88f9a7e8 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -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 diff --git a/varnish-cache/bin/varnishd/storage_malloc.c b/varnish-cache/bin/varnishd/storage_malloc.c index 2794c8e9..e97a5977 100644 --- a/varnish-cache/bin/varnishd/storage_malloc.c +++ b/varnish-cache/bin/varnishd/storage_malloc.c @@ -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); }