diff --git a/src/shrpx.cc b/src/shrpx.cc index f1abba0d..ed6cf1f7 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -1032,6 +1032,7 @@ void fill_default_config() { // Default accept() backlog listenerconf.backlog = 512; listenerconf.host_unix = false; + listenerconf.timeout.sleep = 30_s; } } diff --git a/src/shrpx_accept_handler.cc b/src/shrpx_accept_handler.cc index 0d448306..418a3bf0 100644 --- a/src/shrpx_accept_handler.cc +++ b/src/shrpx_accept_handler.cc @@ -87,7 +87,7 @@ void AcceptHandler::accept_connection() { case ENFILE: LOG(WARN) << "acceptor: running out file descriptor; disable acceptor " "temporarily"; - conn_hnr_->disable_acceptor_temporary(30.); + conn_hnr_->sleep_acceptor(get_config()->conn.listener.timeout.sleep); break; } diff --git a/src/shrpx_connection_handler.cc b/src/shrpx_connection_handler.cc index 34b10996..1e6504b0 100644 --- a/src/shrpx_connection_handler.cc +++ b/src/shrpx_connection_handler.cc @@ -385,7 +385,7 @@ void ConnectionHandler::disable_acceptor() { } } -void ConnectionHandler::disable_acceptor_temporary(ev_tstamp t) { +void ConnectionHandler::sleep_acceptor(ev_tstamp t) { if (t == 0. || ev_is_active(&disable_acceptor_timer_)) { return; } diff --git a/src/shrpx_connection_handler.h b/src/shrpx_connection_handler.h index 36c5e40b..deec78c8 100644 --- a/src/shrpx_connection_handler.h +++ b/src/shrpx_connection_handler.h @@ -98,7 +98,7 @@ public: AcceptHandler *get_acceptor6() const; void enable_acceptor(); void disable_acceptor(); - void disable_acceptor_temporary(ev_tstamp t); + void sleep_acceptor(ev_tstamp t); void accept_pending_connection(); void graceful_shutdown_worker(); void set_graceful_shutdown(bool f); diff --git a/src/template.h b/src/template.h index feef5784..7eb11e71 100644 --- a/src/template.h +++ b/src/template.h @@ -171,10 +171,18 @@ constexpr unsigned long long operator"" _g(unsigned long long g) { // User-defined literals for time, converted into double in seconds +// hours constexpr double operator"" _h(unsigned long long h) { return h * 60 * 60; } +// minutes constexpr double operator"" _min(unsigned long long min) { return min * 60; } +// seconds +constexpr double operator"" _s(unsigned long long s) { return s; } + +// milliseconds +constexpr double operator"" _ms(unsigned long long ms) { return ms / 1000.; } + // Returns a copy of NULL-terminated string [first, last). template std::unique_ptr strcopy(InputIt first, InputIt last) {