From: phk Date: Mon, 10 Jul 2006 09:07:29 +0000 (+0000) Subject: Allocate struct http as part of the session allocation. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3cd324b54bbb42487eda576ade8cdc1216799072;p=varnish Allocate struct http as part of the session allocation. Remove http_New() and http_Delete() git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@394 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 366b8d52..d5aca394 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -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); diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index b542fdd9..c82852b5 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -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); } } diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 3c9c7df7..dd230eee 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 79b8a7ec..825d413c 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -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) { diff --git a/varnish-cache/bin/varnishd/cache_pass.c b/varnish-cache/bin/varnishd/cache_pass.c index a931bb67..7ac2f669 100644 --- a/varnish-cache/bin/varnishd/cache_pass.c +++ b/varnish-cache/bin/varnishd/cache_pass.c @@ -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); diff --git a/varnish-cache/include/stat_field.h b/varnish-cache/include/stat_field.h index 87f39b8d..2baf744f 100644 --- a/varnish-cache/include/stat_field.h +++ b/varnish-cache/include/stat_field.h @@ -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");