diff --git a/examples/shrpx.cc b/examples/shrpx.cc index 92360851..76906774 100644 --- a/examples/shrpx.cc +++ b/examples/shrpx.cc @@ -196,7 +196,7 @@ evconnlistener* create_evlistener(ListenHandler *handler, int family) ssl_acceptcb, handler, LEV_OPT_REUSEABLE | LEV_OPT_CLOSE_ON_FREE, - 512, + get_config()->backlog, fd); evconnlistener_set_error_cb(evlistener, evlistener_errorcb); return evlistener; @@ -333,6 +333,9 @@ void fill_default_config() mod_config()->syslog = false; mod_config()->syslog_facility = LOG_DAEMON; mod_config()->use_syslog = false; + + // Default accept() backlog + mod_config()->backlog = 256; } } // namespace @@ -424,6 +427,9 @@ void print_help(std::ostream& out) << " Set syslog facility.\n" << " Default: " << str_syslog_facility(get_config()->syslog_facility) << "\n" + << " --backlog= Set listen backlog size.\n" + << " Default: " + << get_config()->backlog << "\n" << " -h, --help Print this help.\n" << std::endl; } @@ -460,6 +466,7 @@ int main(int argc, char **argv) {"conf", required_argument, &flag, 12 }, {"syslog", no_argument, &flag, 13 }, {"syslog-facility", required_argument, &flag, 14 }, + {"backlog", required_argument, &flag, 15 }, {"help", no_argument, 0, 'h' }, {0, 0, 0, 0 } }; @@ -560,6 +567,10 @@ int main(int argc, char **argv) // --syslog-facility cmdcfgs.push_back(std::make_pair(SHRPX_OPT_SYSLOG_FACILITY, optarg)); break; + case 15: + // --backlog + cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKLOG, optarg)); + break; default: break; } diff --git a/examples/shrpx_config.cc b/examples/shrpx_config.cc index 0c0874ef..ebba2449 100644 --- a/examples/shrpx_config.cc +++ b/examples/shrpx_config.cc @@ -66,6 +66,7 @@ const char SHRPX_OPT_PID_FILE[] = "pid-file"; const char SHRPX_OPT_USER[] = "user"; const char SHRPX_OPT_SYSLOG[] = "syslog"; const char SHRPX_OPT_SYSLOG_FACILITY[] = "syslog-facility"; +const char SHRPX_OPT_BACKLOG[] = "backlog"; Config::Config() : verbose(false), @@ -92,7 +93,8 @@ Config::Config() conf_path(0), syslog(false), syslog_facility(0), - use_syslog(false) + use_syslog(false), + backlog(0) {} namespace { @@ -238,6 +240,8 @@ int parse_config(const char *opt, const char *optarg) return -1; } mod_config()->syslog_facility = facility; + } else if(util::strieq(opt, SHRPX_OPT_BACKLOG)) { + mod_config()->backlog = strtol(optarg, 0, 10); } else if(util::strieq(opt, "conf")) { LOG(WARNING) << "conf is ignored"; } else { diff --git a/examples/shrpx_config.h b/examples/shrpx_config.h index e753b3b7..8b4e25fc 100644 --- a/examples/shrpx_config.h +++ b/examples/shrpx_config.h @@ -58,6 +58,7 @@ extern const char SHRPX_OPT_PID_FILE[]; extern const char SHRPX_OPT_USER[]; extern const char SHRPX_OPT_SYSLOG[]; extern const char SHRPX_OPT_SYSLOG_FACILITY[]; +extern const char SHRPX_OPT_BACKLOG[]; union sockaddr_union { sockaddr sa; @@ -100,6 +101,7 @@ struct Config { int syslog_facility; // This member finally decides syslog is used or not bool use_syslog; + int backlog; Config(); };