From 2d5d9d5d0439b51a8f1eca9783eb86bf4796d38a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 6 May 2015 10:42:43 +0900 Subject: [PATCH] nghttpd: Add -m, --max-concurrent-streams option --- src/HttpServer.cc | 16 +++++++++------- src/HttpServer.h | 1 + src/nghttpd.cc | 18 +++++++++++++++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 19cdbed7..edbf1a81 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -89,9 +89,9 @@ template void append_nv(Stream *stream, const Array &nva) { Config::Config() : stream_read_timeout(60.), stream_write_timeout(60.), session_option(nullptr), data_ptr(nullptr), padding(0), num_worker(1), - header_table_size(-1), port(0), verbose(false), daemon(false), - verify_client(false), no_tls(false), error_gzip(false), - early_response(false), hexdump(false) { + max_concurrent_streams(100), header_table_size(-1), port(0), + verbose(false), daemon(false), verify_client(false), no_tls(false), + error_gzip(false), early_response(false), hexdump(false) { nghttp2_option_new(&session_option); nghttp2_option_set_recv_client_preface(session_option, 1); } @@ -660,8 +660,10 @@ int Http2Handler::on_write() { return write_(*this); } int Http2Handler::connection_made() { int r; + auto config = sessions_->get_config(); + r = nghttp2_session_server_new2(&session_, sessions_->get_callbacks(), this, - sessions_->get_config()->session_option); + config->session_option); if (r != 0) { return r; } @@ -669,11 +671,11 @@ int Http2Handler::connection_made() { size_t niv = 1; entry[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; - entry[0].value = 100; + entry[0].value = config->max_concurrent_streams; - if (sessions_->get_config()->header_table_size >= 0) { + if (config->header_table_size >= 0) { entry[niv].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; - entry[niv].value = sessions_->get_config()->header_table_size; + entry[niv].value = config->header_table_size; ++niv; } r = nghttp2_submit_settings(session_, NGHTTP2_FLAG_NONE, entry.data(), niv); diff --git a/src/HttpServer.h b/src/HttpServer.h index d6272f4a..98ca9c43 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -63,6 +63,7 @@ struct Config { void *data_ptr; size_t padding; size_t num_worker; + size_t max_concurrent_streams; ssize_t header_table_size; uint16_t port; bool verbose; diff --git a/src/nghttpd.cc b/src/nghttpd.cc index d7691598..5126cea1 100644 --- a/src/nghttpd.cc +++ b/src/nghttpd.cc @@ -88,6 +88,7 @@ void print_usage(std::ostream &out) { namespace { void print_help(std::ostream &out) { + Config config; print_usage(out); out << R"( Specify listening port number. @@ -128,6 +129,10 @@ Options: -b, --padding= Add at most bytes to a frame payload as padding. Specify 0 to disable padding. + -m, --max-concurrent-streams= + Set the maximum number of the concurrent streams in one + HTTP/2 session. + Default: )" << config.max_concurrent_streams << R"( -n, --workers= Set the number of worker threads. Default: 1 @@ -173,6 +178,7 @@ int main(int argc, char **argv) { {"header-table-size", required_argument, nullptr, 'c'}, {"push", required_argument, nullptr, 'p'}, {"padding", required_argument, nullptr, 'b'}, + {"max-concurrent-streams", required_argument, nullptr, 'm'}, {"workers", required_argument, nullptr, 'n'}, {"error-gzip", no_argument, nullptr, 'e'}, {"no-tls", no_argument, &flag, 1}, @@ -184,7 +190,7 @@ int main(int argc, char **argv) { {"hexdump", no_argument, &flag, 7}, {nullptr, 0, nullptr, 0}}; int option_index = 0; - int c = getopt_long(argc, argv, "DVb:c:d:ehn:p:va:", long_options, + int c = getopt_long(argc, argv, "DVb:c:d:ehm:n:p:va:", long_options, &option_index); char *end; if (c == -1) { @@ -209,6 +215,16 @@ int main(int argc, char **argv) { case 'e': config.error_gzip = true; break; + case 'm': { + // max-concurrent-streams option + auto n = util::parse_uint(optarg); + if (n == -1) { + std::cerr << "-m: invalid argument: " << optarg << std::endl; + exit(EXIT_FAILURE); + } + config.max_concurrent_streams = n; + break; + } case 'n': #ifdef NOTHREADS std::cerr << "-n: WARNING: Threading disabled at build time, "