r394 - in trunk/varnish-cache: bin/varnishd include

phk at projects.linpro.no phk at projects.linpro.no
Mon Jul 10 11:07:29 CEST 2006


Author: phk
Date: 2006-07-10 11:07:29 +0200 (Mon, 10 Jul 2006)
New Revision: 394

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/cache_pass.c
   trunk/varnish-cache/include/stat_field.h
Log:
Allocate struct http as part of the session allocation.

Remove http_New() and http_Delete()




Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-10 08:41:26 UTC (rev 393)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-10 09:07:29 UTC (rev 394)
@@ -149,7 +149,6 @@
 	struct VCL_conf		*vcl;
 
 	/* Various internal stuff */
-	struct event		*rd_e;
 	struct sessmem		*mem;
 	time_t			t0;
 };
@@ -210,8 +209,6 @@
 
 /* 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);

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-07-10 08:41:26 UTC (rev 393)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-07-10 09:07:29 UTC (rev 394)
@@ -41,13 +41,45 @@
 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 @@
 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 @@
 
 	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 @@
 	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 @@
 		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);
 	}
 }
 

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-10 08:41:26 UTC (rev 393)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-07-10 09:07:29 UTC (rev 394)
@@ -246,7 +246,7 @@
 	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 @@
 	if (!sp->obj->cacheable)
 		HSH_Deref(sp->obj);
 
-	http_Delete(hp);
-
 	return (1);
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-10 08:41:26 UTC (rev 393)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2006-07-10 09:07:29 UTC (rev 394)
@@ -32,40 +32,6 @@
 
 /*--------------------------------------------------------------------*/
 
-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)
 {

Modified: trunk/varnish-cache/bin/varnishd/cache_pass.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-07-10 08:41:26 UTC (rev 393)
+++ trunk/varnish-cache/bin/varnishd/cache_pass.c	2006-07-10 09:07:29 UTC (rev 394)
@@ -166,7 +166,7 @@
 	 * 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);

Modified: trunk/varnish-cache/include/stat_field.h
===================================================================
--- trunk/varnish-cache/include/stat_field.h	2006-07-10 08:41:26 UTC (rev 393)
+++ trunk/varnish-cache/include/stat_field.h	2006-07-10 09:07:29 UTC (rev 394)
@@ -14,7 +14,6 @@
 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");
 




More information about the varnish-commit mailing list