r367 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Jul 7 09:15:33 CEST 2006


Author: phk
Date: 2006-07-07 09:15:33 +0200 (Fri, 07 Jul 2006)
New Revision: 367

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
Log:
Time idle TCP connections out after 30 seconds


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-07 06:29:23 UTC (rev 366)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-07 07:15:33 UTC (rev 367)
@@ -202,7 +202,7 @@
 
 /* cache_pool.c */
 void CacheInitPool(void);
-void DealWithSession(void *arg, int good);
+void DealWithSession(void *arg);
 
 /* cache_shmlog.c */
 void VSL_Init(void);

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-07-07 06:29:23 UTC (rev 366)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2006-07-07 07:15:33 UTC (rev 367)
@@ -34,11 +34,15 @@
 static struct event pipe_e;
 static int pipes[2];
 
+static struct event tick_e;
+static struct timeval tick_rate;
+
 static pthread_t vca_thread;
 
 #define SESS_IOVS	10
 
 static struct event accept_e[2 * HERITAGE_NSOCKS];
+static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
 
 struct sessmem {
 	struct sess	s;
@@ -128,6 +132,41 @@
 /*--------------------------------------------------------------------*/
 
 static void
+vca_tick(int a, short b, void *c)
+{
+	struct sess *sp, *sp2;
+	time_t t;
+
+	printf("vca_tick\n");
+	evtimer_add(&tick_e, &tick_rate);
+	time(&t);
+	TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
+		if (sp->t_resp + 30 < t) {
+			TAILQ_REMOVE(&sesshead, sp, list);
+			vca_close_session(sp, "timeout");
+			vca_return_session(sp);
+		}
+	}
+}
+
+static void
+vca_callback(void *arg, int bad)
+{
+	struct sess *sp = arg;
+
+	TAILQ_REMOVE(&sesshead, sp, list);
+	if (bad) {
+		if (bad == 1)
+			vca_close_session(sp, "overflow");
+		else
+			vca_close_session(sp, "no request");
+		vca_return_session(sp);
+		return;
+	}
+	DealWithSession(sp);
+}
+
+static void
 pipe_f(int fd, short event, void *arg)
 {
 	struct sess *sp;
@@ -135,7 +174,9 @@
 
 	i = read(fd, &sp, sizeof sp);
 	assert(i == sizeof sp);
-	http_RecvHead(sp->http, sp->fd, evb, DealWithSession, sp);
+	time(&sp->t_resp);
+	TAILQ_INSERT_TAIL(&sesshead, sp, list);
+	http_RecvHead(sp->http, sp->fd, evb, vca_callback, sp);
 }
 
 static void
@@ -182,8 +223,10 @@
 	strlcat(sp->addr, " ", VCA_ADDRBUFSIZE);
 	strlcat(sp->addr, port, VCA_ADDRBUFSIZE);
 	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, DealWithSession, sp);
+	http_RecvHead(sp->http, sp->fd, evb, vca_callback, sp);
 }
 
 static void *
@@ -199,6 +242,11 @@
 	event_base_set(evb, &pipe_e);
 	event_add(&pipe_e, NULL);
 
+	evtimer_set(&tick_e, vca_tick, NULL);
+	event_base_set(evb, &tick_e);
+	
+	evtimer_add(&tick_e, &tick_rate);
+
 	ep = accept_e;
 	for (u = 0; u < HERITAGE_NSOCKS; u++) {
 		if (heritage.sock_local[u] >= 0) {
@@ -258,5 +306,7 @@
 VCA_Init(void)
 {
 
+	tick_rate.tv_sec = 1;
+	tick_rate.tv_usec = 0;
 	AZ(pthread_create(&vca_thread, NULL, vca_main, NULL));
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-07 06:29:23 UTC (rev 366)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-07 07:15:33 UTC (rev 367)
@@ -135,19 +135,10 @@
 }
 
 void
-DealWithSession(void *arg, int bad)
+DealWithSession(void *arg)
 {
 	struct sess *sp = arg;
 
-	if (bad) {
-		if (bad == 1)
-			vca_close_session(sp, "overflow");
-		else
-			vca_close_session(sp, "no request");
-		vca_return_session(sp);
-		return;
-	}
-
 	time(&sp->t_req);
 
 	/*




More information about the varnish-commit mailing list