nghttpd: Add -m, --max-concurrent-streams option
This commit is contained in:
parent
7ecca39025
commit
2d5d9d5d04
|
@ -89,9 +89,9 @@ template <typename Array> 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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -88,6 +88,7 @@ void print_usage(std::ostream &out) {
|
|||
|
||||
namespace {
|
||||
void print_help(std::ostream &out) {
|
||||
Config config;
|
||||
print_usage(out);
|
||||
out << R"(
|
||||
<PORT> Specify listening port number.
|
||||
|
@ -128,6 +129,10 @@ Options:
|
|||
-b, --padding=<N>
|
||||
Add at most <N> bytes to a frame payload as padding.
|
||||
Specify 0 to disable padding.
|
||||
-m, --max-concurrent-streams=<N>
|
||||
Set the maximum number of the concurrent streams in one
|
||||
HTTP/2 session.
|
||||
Default: )" << config.max_concurrent_streams << R"(
|
||||
-n, --workers=<N>
|
||||
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, "
|
||||
|
|
Loading…
Reference in New Issue