]> err.no Git - varnish/commitdiff
Allocate struct http as part of the session allocation.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 10 Jul 2006 09:07:29 +0000 (09:07 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 10 Jul 2006 09:07:29 +0000 (09:07 +0000)
Remove http_New() and http_Delete()

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@394 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_http.c
varnish-cache/bin/varnishd/cache_pass.c
varnish-cache/include/stat_field.h

index 366b8d52b1876725763ca875ea9090dc0142ec52..d5aca3949c27ee7019d39859e7d57578a4420e1a 100644 (file)
@@ -149,7 +149,6 @@ struct sess {
        struct VCL_conf         *vcl;
 
        /* Various internal stuff */
-       struct event            *rd_e;
        struct sessmem          *mem;
        time_t                  t0;
 };
@@ -210,8 +209,6 @@ void HSH_Init(void);
 
 /* cache_http.c */
 void http_Init(struct http *ht, void *space);
-struct http *http_New(void);
-void http_Delete(struct http *hp);
 int http_GetHdr(struct http *hp, const char *hdr, char **ptr);
 int http_GetHdrField(struct http *hp, const char *hdr, const char *field, char **ptr);
 int http_GetReq(struct http *hp, char **b);
index b542fdd94835eecf70aec8695cad356a9e4aeadc..c82852b53c53bd13fb5678f19ad3023bb4bddeb1 100644 (file)
@@ -41,13 +41,45 @@ static struct event accept_e[2 * HERITAGE_NSOCKS];
 static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
 
 struct sessmem {
-       struct sess     s;
-       struct event    e;
+       struct sess     sess;
        struct iovec    iov[SESS_IOVS];
        int             niov;
        size_t          liov;
+       struct http     http;
+       char            *http_hdr;
 };
 
+/*--------------------------------------------------------------------*/
+
+static struct sess *
+vca_new_sess(void)
+{
+       struct sessmem *sm;
+
+       sm = calloc(
+           sizeof *sm +
+           heritage.mem_http_headers * sizeof sm->http_hdr +
+           heritage.mem_http_headerspace +
+           heritage.mem_workspace,
+           1);
+       if (sm == NULL)
+               return (NULL);
+       VSL_stats->n_sess++;
+       sm->sess.mem = sm;
+       sm->sess.http = &sm->http;
+       http_Init(&sm->http, (void *)(sm + 1));
+       return (&sm->sess);
+}
+
+static void
+vca_delete_sess(struct sess *sp)
+{
+
+       VSL_stats->n_sess--;
+       free(sp->mem);
+}
+
+
 /*--------------------------------------------------------------------
  * Write data to client
  * We try to use writev() if possible in order to minimize number of
@@ -178,7 +210,6 @@ static void
 accept_f(int fd, short event, void *arg)
 {
        socklen_t l;
-       struct sessmem *sm;
        struct sockaddr addr[2];
        struct sess *sp;
        char port[NI_MAXSERV];
@@ -187,22 +218,14 @@ accept_f(int fd, short event, void *arg)
 
        VSL_stats->client_conn++;
 
-       (void)arg;
-       sm = calloc(sizeof *sm, 1);
-       assert(sm != NULL);     /*
-                                * XXX: this is probably one we should handle
-                                * XXX: accept, emit error NNN and close
-                                */
-       VSL_stats->n_sess++;
+       sp = vca_new_sess();
+       assert(sp != NULL);     /* XXX handle */
 
-       sp = &sm->s;
-       sp->rd_e = &sm->e;
-       sp->mem = sm;
 
        l = sizeof addr;
        sp->fd = accept(fd, addr, &l);
        if (sp->fd < 0) {
-               free(sp);
+               vca_delete_sess(sp);
                return;
        }
 #ifdef SO_NOSIGPIPE /* XXX Linux */
@@ -227,7 +250,6 @@ accept_f(int fd, short event, void *arg)
        VSL(SLT_SessionOpen, sp->fd, "%s", sp->addr);
        time(&sp->t_resp);
        TAILQ_INSERT_TAIL(&sesshead, sp, list);
-       sp->http = http_New();
        http_RecvHead(sp->http, sp->fd, evb, vca_callback, sp);
 }
 
@@ -295,10 +317,7 @@ vca_return_session(struct sess *sp)
                VSL(SLT_SessionReuse, sp->fd, "%s", sp->addr);
                write(pipes[1], &sp, sizeof sp);
        } else {
-               if (sp->http != NULL)
-                       http_Delete(sp->http);
-               VSL_stats->n_sess--;
-               free(sp->mem);
+               vca_delete_sess(sp);
        }
 }
 
index 3c9c7df7c688c6fbfa28033f4ebd7afbdb8055ce..dd230eeecc21558e5d82a7cc2cc3d26f1e4d82a6 100644 (file)
@@ -246,7 +246,7 @@ FetchSession(struct worker *w, struct sess *sp)
        assert(vc != NULL);     /* XXX: handle this */
        VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
 
-       hp = http_New();
+       hp = vc->http;
        http_BuildSbuf(vc->fd, Build_Fetch, w->sb, sp->http);
        i = write(vc->fd, sbuf_data(w->sb), sbuf_len(w->sb));
        assert(i == sbuf_len(w->sb));
@@ -299,7 +299,5 @@ FetchSession(struct worker *w, struct sess *sp)
        if (!sp->obj->cacheable)
                HSH_Deref(sp->obj);
 
-       http_Delete(hp);
-
        return (1);
 }
index 79b8a7ecf5bfd30a3d9a66fd7afd207c9f046725..825d413cf331fed3c960fd3922419a628bd5acae 100644 (file)
@@ -32,40 +32,6 @@ http_Init(struct http *hp, void *space)
 
 /*--------------------------------------------------------------------*/
 
-struct http *
-http_New(void)
-{
-       struct http *hp;
-
-       hp = calloc(sizeof *hp, 1);
-       assert(hp != NULL);
-       VSL_stats->n_http++;
-
-       hp->s = malloc(heritage.mem_http_headerspace);
-       assert(hp->s != NULL);
-
-       hp->e = hp->s + heritage.mem_http_headerspace;
-       hp->v = hp->s;
-       hp->t = hp->s;
-
-       hp->hdr = malloc(sizeof *hp->hdr * heritage.mem_http_headers);
-       assert(hp->hdr != NULL);
-
-       return (hp);
-}
-
-void
-http_Delete(struct http *hp)
-{
-
-       free(hp->hdr);
-       free(hp->s);
-       free(hp);
-       VSL_stats->n_http--;
-}
-
-/*--------------------------------------------------------------------*/
-
 int
 http_GetHdr(struct http *hp, const char *hdr, char **ptr)
 {
index a931bb672a585366ae56d681db85ebaec4744f33..7ac2f6691c8abb32ec00061091a646b02c0386bf 100644 (file)
@@ -166,7 +166,7 @@ PassSession(struct worker *w, struct sess *sp)
         * XXX: It might be cheaper to avoid the event_engine and simply
         * XXX: read(2) the header
         */
-       hp = http_New();
+       hp = vc->http;
        http_RecvHead(hp, vc->fd, w->eb, NULL, NULL);
        event_base_loop(w->eb, 0);
        http_Dissect(hp, vc->fd, 2);
index 87f39b8d4b9147f56e820b7b219a894f06ff9e2c..2baf744f1fad2e1b305c1fd1832eaee87a9f4a9b 100644 (file)
@@ -14,7 +14,6 @@ MAC_STAT(n_object,            uint64_t, "u", "N struct object");
 MAC_STAT(n_objecthead,         uint64_t, "u", "N struct objecthead");
 MAC_STAT(n_header,             uint64_t, "u", "N struct header");
 MAC_STAT(n_smf,                        uint64_t, "u", "N struct smf");
-MAC_STAT(n_http,               uint64_t, "u", "N struct http");
 MAC_STAT(n_vbe,                        uint64_t, "u", "N struct vbe");
 MAC_STAT(n_vbe_conn,           uint64_t, "u", "N struct vbe_conn");