Fix keep-alive idle.

personal/stbuehler/wip
Stefan Bühler 14 years ago
parent e7196f24e2
commit 491b7880cb
  1. 11
      src/connection.c
  2. 1
      src/connection.h
  3. 4
      src/server.c

@ -166,6 +166,7 @@ connection* connection_new(server *srv) {
con->keep_alive_data.link = NULL;
con->keep_alive_data.timeout = 0;
con->keep_alive_data.max_idle = 0;
my_ev_init(&con->keep_alive_data.watcher, connection_keepalive_cb);
con->keep_alive_data.watcher.data = con;
@ -209,6 +210,7 @@ void connection_reset(server *srv, connection *con) {
con->keep_alive_data.link = NULL;
}
con->keep_alive_data.timeout = 0;
con->keep_alive_data.max_idle = 0;
ev_timer_stop(srv->loop, &con->keep_alive_data.watcher);
}
@ -216,12 +218,12 @@ void server_check_keepalive(server *srv);
void connection_reset_keep_alive(server *srv, connection *con) {
ev_timer_stop(srv->loop, &con->keep_alive_data.watcher);
{
guint timeout = GPOINTER_TO_INT(CORE_OPTION(CORE_OPTION_MAX_KEEP_ALIVE_IDLE));
if (timeout == 0) {
con->keep_alive_data.max_idle = GPOINTER_TO_INT(CORE_OPTION(CORE_OPTION_MAX_KEEP_ALIVE_IDLE));
if (con->keep_alive_data.max_idle == 0) {
con_put(srv, con);
return;
}
if (timeout >= srv->keep_alive_queue_timeout) {
if (con->keep_alive_data.max_idle >= srv->keep_alive_queue_timeout) {
/* queue is sorted by con->keep_alive_data.timeout */
gboolean need_start = (0 == srv->keep_alive_queue.length);
con->keep_alive_data.timeout = ev_now((srv)->loop) + srv->keep_alive_queue_timeout;
@ -230,7 +232,7 @@ void connection_reset_keep_alive(server *srv, connection *con) {
if (need_start)
server_check_keepalive(srv);
} else {
ev_timer_set(&con->keep_alive_data.watcher, timeout, 0);
ev_timer_set(&con->keep_alive_data.watcher, con->keep_alive_data.max_idle, 0);
ev_timer_start(srv->loop, &con->keep_alive_data.watcher);
}
}
@ -294,6 +296,7 @@ void connection_free(server *srv, connection *con) {
con->keep_alive_data.link = NULL;
}
con->keep_alive_data.timeout = 0;
con->keep_alive_data.max_idle = 0;
ev_timer_stop(srv->loop, &con->keep_alive_data.watcher);
g_slice_free(connection, con);

@ -100,6 +100,7 @@ struct connection {
struct {
GList *link;
ev_tstamp timeout;
guint max_idle;
ev_timer watcher;
} keep_alive_data;
};

@ -109,9 +109,9 @@ static void server_keepalive_cb(struct ev_loop *loop, ev_timer *w, int revents)
while ( NULL != (l = g_queue_peek_head_link(q)) &&
(con = (connection*) l->data)->keep_alive_data.timeout <= now ) {
guint timeout = GPOINTER_TO_INT(CORE_OPTION(CORE_OPTION_MAX_KEEP_ALIVE_IDLE));
ev_tstamp remaining = timeout - srv->keep_alive_queue_timeout - (now - con->keep_alive_data.timeout);
ev_tstamp remaining = con->keep_alive_data.max_idle - srv->keep_alive_queue_timeout - (now - con->keep_alive_data.timeout);
if (remaining > 0) {
g_queue_delete_link(q, l);
ev_timer_set(&con->keep_alive_data.watcher, remaining, 0);
ev_timer_start(srv->loop, &con->keep_alive_data.watcher);
} else {

Loading…
Cancel
Save