]> err.no Git - varnish/commitdiff
First step of slow client handling: Lose the stevedore function
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Aug 2006 08:42:58 +0000 (08:42 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Aug 2006 08:42:58 +0000 (08:42 +0000)
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

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_response.c
varnish-cache/bin/varnishd/stevedore.h
varnish-cache/bin/varnishd/storage_file.c
varnish-cache/bin/varnishd/storage_malloc.c

index add40e89cfc43a7598dc474353039ffd7af621a0..e560c68a67e911f1bb7aaf1e2404900b4081090e 100644 (file)
@@ -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"
index 1eb9b04b81551065b9ecdde81272e7d3dbe02484..d4ccf5239cf5717298c82ff5cbc847bd582d3a0d 100644 (file)
@@ -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);
        }
index 89548e81cceff5510daf52c855a3caba63729a4b..a1fdb6bdc5839d78e217d5da0ae186fc7c7a741f 100644 (file)
@@ -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;
index 02168493520ed9ad7464afe56d2944a454308572..88f9a7e84f7dd499226ce5fed6df3f3929a0728e 100644 (file)
@@ -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
index 2794c8e90f9e74fae524b56a98f3aa01a2d986ae..e97a597722a7587c1eafae85492f1f3c26acf7af 100644 (file)
@@ -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);
 }