Commit e37bd797 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Time idle TCP connections out after 30 seconds


git-svn-id: http://www.varnish-cache.org/svn/trunk@367 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 2dcf4175
......@@ -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);
......
......@@ -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));
}
......@@ -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);
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment