From: Stefan Eissing Date: Fri, 29 Jan 2016 14:37:17 +0000 (+0000) Subject: using keepalive timeout only when no streams are open, changing from seconds to prope... X-Git-Tag: 2.5.0-alpha~2250 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=736f2fce8e93221200e55aaebebc367417af9b85;p=thirdparty%2Fapache%2Fhttpd.git using keepalive timeout only when no streams are open, changing from seconds to proper apr_interval_time_t git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1727594 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/http2/h2_filter.c b/modules/http2/h2_filter.c index bde3b01b9ce..87ac9df5345 100644 --- a/modules/http2/h2_filter.c +++ b/modules/http2/h2_filter.c @@ -51,7 +51,7 @@ static apr_status_t consume_brigade(h2_filter_cin *cin, apr_bucket* bucket = APR_BRIGADE_FIRST(bb); if (APR_BUCKET_IS_METADATA(bucket)) { - /* we do nothing regarding any meta here */ + /* we do nothing regardih2_filter_cin_timeout_setng any meta here */ } else { const char *bucket_data = NULL; @@ -92,9 +92,9 @@ h2_filter_cin *h2_filter_cin_create(apr_pool_t *p, h2_filter_cin_cb *cb, void *c return cin; } -void h2_filter_cin_timeout_set(h2_filter_cin *cin, int timeout_secs) +void h2_filter_cin_timeout_set(h2_filter_cin *cin, apr_interval_time_t timeout) { - cin->timeout_secs = timeout_secs; + cin->timeout = timeout; } apr_status_t h2_filter_core_input(ap_filter_t* f, @@ -105,12 +105,12 @@ apr_status_t h2_filter_core_input(ap_filter_t* f, { h2_filter_cin *cin = f->ctx; apr_status_t status = APR_SUCCESS; - apr_time_t saved_timeout = UNSET; + apr_interval_time_t saved_timeout = UNSET; ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, f->c, - "core_input(%ld): read, %s, mode=%d, readbytes=%ld, timeout=%d", + "core_input(%ld): read, %s, mode=%d, readbytes=%ld", (long)f->c->id, (block == APR_BLOCK_READ)? "BLOCK_READ" : "NONBLOCK_READ", - mode, (long)readbytes, cin->timeout_secs); + mode, (long)readbytes); if (mode == AP_MODE_INIT || mode == AP_MODE_SPECULATIVE) { return ap_get_brigade(f->next, brigade, mode, block, readbytes); @@ -137,10 +137,9 @@ apr_status_t h2_filter_core_input(ap_filter_t* f, * in the scoreboard is preserved. */ if (block == APR_BLOCK_READ) { - if (cin->timeout_secs > 0) { - apr_time_t t = apr_time_from_sec(cin->timeout_secs); + if (cin->timeout > 0) { apr_socket_timeout_get(cin->socket, &saved_timeout); - apr_socket_timeout_set(cin->socket, t); + apr_socket_timeout_set(cin->socket, cin->timeout); } } status = ap_get_brigade(f->next, cin->bb, AP_MODE_READBYTES, diff --git a/modules/http2/h2_filter.h b/modules/http2/h2_filter.h index 401a6e0e44a..9a38a9b9cbc 100644 --- a/modules/http2/h2_filter.h +++ b/modules/http2/h2_filter.h @@ -29,13 +29,13 @@ typedef struct h2_filter_cin { h2_filter_cin_cb *cb; void *cb_ctx; apr_socket_t *socket; - int timeout_secs; + apr_interval_time_t timeout; apr_time_t start_read; } h2_filter_cin; h2_filter_cin *h2_filter_cin_create(apr_pool_t *p, h2_filter_cin_cb *cb, void *ctx); -void h2_filter_cin_timeout_set(h2_filter_cin *cin, int timeout_secs); +void h2_filter_cin_timeout_set(h2_filter_cin *cin, apr_interval_time_t timeout); apr_status_t h2_filter_core_input(ap_filter_t* filter, apr_bucket_brigade* brigade, diff --git a/modules/http2/h2_private.h b/modules/http2/h2_private.h index 0ad02d3b71f..eb24fa1a210 100644 --- a/modules/http2/h2_private.h +++ b/modules/http2/h2_private.h @@ -16,6 +16,8 @@ #ifndef mod_h2_h2_private_h #define mod_h2_h2_private_h +#include + #include extern module AP_MODULE_DECLARE_DATA http2_module; diff --git a/modules/http2/h2_session.c b/modules/http2/h2_session.c index b22e5153133..1597d787cd1 100644 --- a/modules/http2/h2_session.c +++ b/modules/http2/h2_session.c @@ -1834,16 +1834,17 @@ static void h2_session_ev_no_io(h2_session *session, int arg, const char *msg) /* When we have no streams, no task event are possible, * switch to blocking reads */ transit(session, "no io", H2_SESSION_ST_IDLE); - session->keepalive_until = apr_time_now() + session->s->keep_alive_timeout; + session->idle_until = apr_time_now() + session->s->keep_alive_timeout; } } else if (!h2_stream_set_has_unsubmitted(session->streams) && !h2_stream_set_has_suspended(session->streams)) { /* none of our streams is waiting for a response or * new output data from task processing, - * switch to blocking reads. */ + * switch to blocking reads. We are probably waiting on + * window updates. */ transit(session, "no io", H2_SESSION_ST_IDLE); - session->keepalive_until = apr_time_now() + session->s->keep_alive_timeout; + session->idle_until = apr_time_now() + session->s->timeout; } else { /* Unable to do blocking reads, as we wait on events from @@ -2052,7 +2053,7 @@ apr_status_t h2_session_process(h2_session *session, int async) dispatch_event(session, H2_SESSION_EV_DATA_READ, 0, NULL); } else if (APR_STATUS_IS_EAGAIN(status) || APR_STATUS_IS_TIMEUP(status)) { - if (apr_time_now() > session->keepalive_until) { + if (apr_time_now() > session->idle_until) { dispatch_event(session, H2_SESSION_EV_CONN_TIMEOUT, 0, NULL); } else { @@ -2080,10 +2081,10 @@ apr_status_t h2_session_process(h2_session *session, int async) /* nothing to read */ } else if (APR_STATUS_IS_TIMEUP(status)) { - if (apr_time_now() > session->keepalive_until) { + if (apr_time_now() > session->idle_until) { dispatch_event(session, H2_SESSION_EV_CONN_TIMEOUT, 0, "timeout"); } - /* continue keepalive handling */ + /* continue reading handling */ } else { dispatch_event(session, H2_SESSION_EV_CONN_ERROR, 0, NULL); diff --git a/modules/http2/h2_session.h b/modules/http2/h2_session.h index bdf815df1af..354b837e17b 100644 --- a/modules/http2/h2_session.h +++ b/modules/http2/h2_session.h @@ -113,7 +113,7 @@ typedef struct h2_session { apr_size_t max_stream_mem; /* max buffer memory for a single stream */ apr_time_t start_wait; /* Time we started waiting for sth. to happen */ - apr_time_t keepalive_until; /* Time when we stop keeing an idle conn alive */ + apr_time_t idle_until; /* Time we shut down due to sheer boredom */ apr_pool_t *pool; /* pool to use in session handling */ apr_bucket_brigade *bbtmp; /* brigade for keeping temporary data */ diff --git a/modules/http2/mod_http2.c b/modules/http2/mod_http2.c index 809a8832765..a3b978c8790 100644 --- a/modules/http2/mod_http2.c +++ b/modules/http2/mod_http2.c @@ -15,6 +15,7 @@ #include #include +#include #include #include