From cebfdacc5aa6624b72f252cbc75a6be68e3e5715 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 21 Jun 2015 14:51:32 +0900 Subject: [PATCH] src: Use user-defined literals for time (hours and minutes) --- src/HttpServer.cc | 4 ++-- src/shrpx.cc | 11 +++++------ src/template.h | 8 ++++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index d74dc907..f14dfe02 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -100,8 +100,8 @@ template void append_nv(Stream *stream, const Array &nva) { } // namespace Config::Config() - : stream_read_timeout(60.), stream_write_timeout(60.), data_ptr(nullptr), - padding(0), num_worker(1), max_concurrent_streams(100), + : stream_read_timeout(1_min), stream_write_timeout(1_min), + data_ptr(nullptr), padding(0), num_worker(1), 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), echo_upload(false) {} diff --git a/src/shrpx.cc b/src/shrpx.cc index ab1cb486..7d459cbd 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -710,8 +710,7 @@ int event_loop() { } if (auto_tls_ticket_key) { // Renew ticket key every 12hrs - ev_timer_init(&renew_ticket_key_timer, renew_ticket_key_cb, 0., - 12 * 3600.); + ev_timer_init(&renew_ticket_key_timer, renew_ticket_key_cb, 0., 12_h); renew_ticket_key_timer.data = conn_handler.get(); ev_timer_again(loop, &renew_ticket_key_timer); @@ -831,16 +830,16 @@ void fill_default_config() { mod_config()->cert_file = nullptr; // Read timeout for HTTP2 upstream connection - mod_config()->http2_upstream_read_timeout = 180.; + mod_config()->http2_upstream_read_timeout = 3_min; // Read timeout for non-HTTP2 upstream connection - mod_config()->upstream_read_timeout = 180.; + mod_config()->upstream_read_timeout = 3_min; // Write timeout for HTTP2/non-HTTP2 upstream connection mod_config()->upstream_write_timeout = 30.; // Read/Write timeouts for downstream connection - mod_config()->downstream_read_timeout = 180.; + mod_config()->downstream_read_timeout = 3_min; mod_config()->downstream_write_timeout = 30.; // Read timeout for HTTP/2 stream @@ -951,7 +950,7 @@ void fill_default_config() { mod_config()->host_unix = false; mod_config()->http2_downstream_connections_per_worker = 0; // ocsp update interval = 14400 secs = 4 hours, borrowed from h2o - mod_config()->ocsp_update_interval = 14400.; + mod_config()->ocsp_update_interval = 4_h; mod_config()->fetch_ocsp_response_file = strcopy(PKGDATADIR "/fetch-ocsp-response"); mod_config()->no_ocsp = false; diff --git a/src/template.h b/src/template.h index 4d7342c3..7a9c3623 100644 --- a/src/template.h +++ b/src/template.h @@ -145,6 +145,8 @@ template void dlist_delete_all(DList &dl) { } } +// User-defined literals for K, M, and G (powers of 1024) + constexpr unsigned long long operator"" _k(unsigned long long k) { return k * 1024; } @@ -157,6 +159,12 @@ constexpr unsigned long long operator"" _g(unsigned long long g) { return g * 1024 * 1024 * 1024; } +// User-defined literals for time, converted into double in seconds + +constexpr double operator"" _h(unsigned long long h) { return h * 60 * 60; } + +constexpr double operator"" _min(unsigned long long min) { return min * 60; } + } // namespace nghttp2 #endif // TEMPLATE_H