nghttpd: Add -F and -f option to disable connection/stream level flow control

This commit is contained in:
Tatsuhiro Tsujikawa 2013-07-28 19:28:41 +09:00
parent 56db10cb5e
commit 9f9c0cbcd1
3 changed files with 42 additions and 6 deletions

View File

@ -72,6 +72,8 @@ Config::Config()
data_ptr(nullptr), data_ptr(nullptr),
verify_client(false), verify_client(false),
no_tls(false), no_tls(false),
no_connection_flow_control(false),
no_stream_flow_control(false),
output_upper_thres(1024*1024) output_upper_thres(1024*1024)
{} {}
@ -346,13 +348,28 @@ int Http2Handler::on_connect()
if(r != 0) { if(r != 0) {
return r; return r;
} }
nghttp2_settings_entry entry; nghttp2_settings_entry entry[2];
entry.settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; size_t niv = 1;
entry.value = NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS; entry[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
r = nghttp2_submit_settings(session_, &entry, 1); entry[0].value = NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS;
if(sessions_->get_config()->no_connection_flow_control &&
sessions_->get_config()->no_stream_flow_control) {
entry[niv].settings_id = NGHTTP2_SETTINGS_FLOW_CONTROL_OPTIONS;
entry[niv].value = 1;
++niv;
}
r = nghttp2_submit_settings(session_, entry, niv);
if(r != 0) { if(r != 0) {
return r; return r;
} }
if(sessions_->get_config()->no_connection_flow_control &&
!sessions_->get_config()->no_stream_flow_control) {
r = nghttp2_submit_window_update(session_, NGHTTP2_FLAG_END_FLOW_CONTROL,
0, 0);
if(r != 0) {
return r;
}
}
return on_write(); return on_write();
} }
@ -698,6 +715,11 @@ void hd_on_frame_recv_callback
auto req = util::make_unique<Request>(stream_id); auto req = util::make_unique<Request>(stream_id);
append_nv(req.get(), frame->headers.nva, frame->headers.nvlen); append_nv(req.get(), frame->headers.nva, frame->headers.nvlen);
hd->add_stream(stream_id, std::move(req)); hd->add_stream(stream_id, std::move(req));
if(!hd->get_config()->no_connection_flow_control &&
hd->get_config()->no_stream_flow_control) {
nghttp2_submit_window_update(session, NGHTTP2_FLAG_END_FLOW_CONTROL,
stream_id, 0);
}
break; break;
} }
case NGHTTP2_HCAT_HEADERS: case NGHTTP2_HCAT_HEADERS:

View File

@ -57,6 +57,8 @@ struct Config {
void *data_ptr; void *data_ptr;
bool verify_client; bool verify_client;
bool no_tls; bool no_tls;
bool no_connection_flow_control;
bool no_stream_flow_control;
size_t output_upper_thres; size_t output_upper_thres;
Config(); Config();
}; };

View File

@ -45,7 +45,7 @@ namespace nghttp2 {
namespace { namespace {
void print_usage(std::ostream& out) void print_usage(std::ostream& out)
{ {
out << "Usage: nghttpd [-DVhv] [-d <PATH>] [--no-tls] <PORT> [<PRIVATE_KEY> <CERT>]" out << "Usage: nghttpd [-FDVfhv] [-d <PATH>] [--no-tls] <PORT> [<PRIVATE_KEY> <CERT>]"
<< std::endl; << std::endl;
} }
} // namespace } // namespace
@ -73,6 +73,10 @@ void print_help(std::ostream& out)
<< " -v, --verbose Print debug information such as reception/\n" << " -v, --verbose Print debug information such as reception/\n"
<< " transmission of frames and name/value pairs.\n" << " transmission of frames and name/value pairs.\n"
<< " --no-tls Disable SSL/TLS.\n" << " --no-tls Disable SSL/TLS.\n"
<< " -F, --no-connection-flow-control\n"
<< " Disables connection level flow control.\n"
<< " -f, --no-stream-flow-control\n"
<< " Disables stream level flow control.\n"
<< " -h, --help Print this help.\n" << " -h, --help Print this help.\n"
<< std::endl; << std::endl;
} }
@ -90,14 +94,19 @@ int main(int argc, char **argv)
{"verbose", no_argument, 0, 'v' }, {"verbose", no_argument, 0, 'v' },
{"verify-client", no_argument, 0, 'V' }, {"verify-client", no_argument, 0, 'V' },
{"no-tls", no_argument, &flag, 1 }, {"no-tls", no_argument, &flag, 1 },
{"no-connection-flow-control", no_argument, 0, 'F'},
{"no-stream-flow-control", no_argument, 0, 'f'},
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
int option_index = 0; int option_index = 0;
int c = getopt_long(argc, argv, "DVd:hv", long_options, &option_index); int c = getopt_long(argc, argv, "FDVd:fhv", long_options, &option_index);
if(c == -1) { if(c == -1) {
break; break;
} }
switch(c) { switch(c) {
case 'F':
config.no_connection_flow_control = true;
break;
case 'D': case 'D':
config.daemon = true; config.daemon = true;
break; break;
@ -107,6 +116,9 @@ int main(int argc, char **argv)
case 'd': case 'd':
config.htdocs = optarg; config.htdocs = optarg;
break; break;
case 'f':
config.no_stream_flow_control = true;
break;
case 'h': case 'h':
print_help(std::cout); print_help(std::cout);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);