]> err.no Git - varnish/commitdiff
Time idle TCP connections out after 30 seconds
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 7 Jul 2006 07:15:33 +0000 (07:15 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 7 Jul 2006 07:15:33 +0000 (07:15 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@367 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/cache_pool.c

index 3c60a06b84c264f814b170bac840a49e843e48f8..006421406e1c5e72923a3e812c360ec2c185d961 100644 (file)
@@ -202,7 +202,7 @@ void PipeSession(struct worker *w, struct sess *sp);
 
 /* cache_pool.c */
 void CacheInitPool(void);
-void DealWithSession(void *arg, int good);
+void DealWithSession(void *arg);
 
 /* cache_shmlog.c */
 void VSL_Init(void);
index bad2b85110060a9e6846dea099a9825c22bc672c..00ef0f844782bb8db8401a13471b9f70c770ccdb 100644 (file)
@@ -34,11 +34,15 @@ static struct event_base *evb;
 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;
@@ -127,6 +131,41 @@ vca_write_obj(struct worker *w, struct sess *sp)
 
 /*--------------------------------------------------------------------*/
 
+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)
 {
@@ -135,7 +174,9 @@ pipe_f(int fd, short event, void *arg)
 
        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 @@ accept_f(int fd, short event, void *arg)
        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 @@ vca_main(void *arg)
        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 @@ void
 VCA_Init(void)
 {
 
+       tick_rate.tv_sec = 1;
+       tick_rate.tv_usec = 0;
        AZ(pthread_create(&vca_thread, NULL, vca_main, NULL));
 }
index 323ab3b12fc58b93eeba0ea9302039b83572295d..31f8d66a6ac85e17ffacff174189e672f674e7d3 100644 (file)
@@ -135,19 +135,10 @@ out:
 }
 
 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);
 
        /*