diff --git a/include/lighttpd/connection.h b/include/lighttpd/connection.h index 41fdbcf..0532c48 100644 --- a/include/lighttpd/connection.h +++ b/include/lighttpd/connection.h @@ -56,6 +56,7 @@ struct connection { guint max_idle; ev_timer watcher; } keep_alive_data; + guint keep_alive_requests; /* I/O timeout data */ waitqueue_elem io_timeout_elem; diff --git a/include/lighttpd/plugin_core.h b/include/lighttpd/plugin_core.h index 9bbb9f4..625bc8c 100644 --- a/include/lighttpd/plugin_core.h +++ b/include/lighttpd/plugin_core.h @@ -13,6 +13,7 @@ enum core_options_t { CORE_OPTION_SERVER_TAG, CORE_OPTION_MAX_KEEP_ALIVE_IDLE, + CORE_OPTION_MAX_KEEP_ALIVE_REQUESTS, CORE_OPTION_MIME_TYPES, diff --git a/src/connection.c b/src/connection.c index d3790c0..072ea4b 100644 --- a/src/connection.c +++ b/src/connection.c @@ -122,6 +122,11 @@ static gboolean connection_handle_read(connection *con) { con->keep_alive_data.timeout = 0; ev_timer_stop(con->wrk->loop, &con->keep_alive_data.watcher); + con->keep_alive_requests++; + /* disable keep alive if limit is reached */ + if (con->keep_alive_requests == CORE_OPTION(CORE_OPTION_MAX_KEEP_ALIVE_REQUESTS).number) + con->keep_alive = FALSE; + con->state = CON_STATE_READ_REQUEST_HEADER; con->ts = CUR_TS(con->wrk); @@ -369,6 +374,7 @@ void connection_reset(connection *con) { con->keep_alive_data.timeout = 0; con->keep_alive_data.max_idle = 0; ev_timer_stop(con->wrk->loop, &con->keep_alive_data.watcher); + con->keep_alive_requests = 0; /* reset stats */ con->stats.bytes_in = G_GUINT64_CONSTANT(0); diff --git a/src/plugin_core.c b/src/plugin_core.c index 2e91052..411d4e9 100644 --- a/src/plugin_core.c +++ b/src/plugin_core.c @@ -798,6 +798,7 @@ static const plugin_option options[] = { { "server.tag", VALUE_STRING, "lighttpd-2.0~sandbox", NULL, NULL }, { "server.max_keep_alive_idle", VALUE_NUMBER, GINT_TO_POINTER(5), NULL, NULL }, + { "server.max_keep_alive_requests", VALUE_NUMBER, GINT_TO_POINTER(15), NULL, NULL }, { "mime_types", VALUE_LIST, NULL, core_option_mime_types_parse, core_option_mime_types_free },