From 39f89f4a6069fcaffdb1a6dc8b5107163eac1e22 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 21 Jun 2015 14:32:47 +0900 Subject: [PATCH] src: Use user-defined literals for k, m, and g. --- src/HttpServer.cc | 4 ++-- src/HttpServer.h | 3 ++- src/app_helper.cc | 3 ++- src/asio_client_session_impl.cc | 2 +- src/asio_client_session_impl.h | 6 ++++-- src/asio_server_connection.h | 5 +++-- src/deflatehd.cc | 10 +++++++++- src/h2load.cc | 4 ++-- src/h2load.h | 3 ++- src/memchunk.h | 2 +- src/nghttp.cc | 12 ++++++------ src/nghttp.h | 4 ++-- src/shrpx.cc | 6 +++--- src/shrpx_client_handler.h | 2 +- src/shrpx_connection_handler.cc | 2 +- src/shrpx_http2_session.h | 2 +- src/shrpx_http_downstream_connection.cc | 2 +- src/shrpx_log.cc | 4 ++-- src/shrpx_spdy_upstream.cc | 2 +- src/template.h | 12 ++++++++++++ 20 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 7b72888e..d74dc907 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -453,7 +453,7 @@ int Http2Handler::fill_wb() { int Http2Handler::read_clear() { int rv; - std::array buf; + std::array buf; for (;;) { ssize_t nread; @@ -570,7 +570,7 @@ int Http2Handler::tls_handshake() { } int Http2Handler::read_tls() { - std::array buf; + std::array buf; ERR_clear_error(); diff --git a/src/HttpServer.h b/src/HttpServer.h index 212f12ad..7128ddb2 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -45,6 +45,7 @@ #include "http2.h" #include "buffer.h" +#include "template.h" namespace nghttp2 { @@ -155,7 +156,7 @@ public: struct ev_loop *get_loop() const; - using WriteBuf = Buffer<65536>; + using WriteBuf = Buffer<64_k>; WriteBuf *get_wb(); diff --git a/src/app_helper.cc b/src/app_helper.cc index 58f8439c..2ce51af7 100644 --- a/src/app_helper.cc +++ b/src/app_helper.cc @@ -58,6 +58,7 @@ #include "app_helper.h" #include "util.h" #include "http2.h" +#include "template.h" namespace nghttp2 { @@ -463,7 +464,7 @@ ssize_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { int rv; z_stream zst; - uint8_t temp_out[8192]; + uint8_t temp_out[8_k]; auto temp_outlen = sizeof(temp_out); zst.next_in = Z_NULL; diff --git a/src/asio_client_session_impl.cc b/src/asio_client_session_impl.cc index 9cb57c90..7baa385e 100644 --- a/src/asio_client_session_impl.cc +++ b/src/asio_client_session_impl.cc @@ -313,7 +313,7 @@ bool session_impl::setup_session() { return false; } - const uint32_t window_size = 256 * 1024 * 1024; + const uint32_t window_size = 256_m; std::array iv{ {{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}, diff --git a/src/asio_client_session_impl.h b/src/asio_client_session_impl.h index 88bbad83..37032d68 100644 --- a/src/asio_client_session_impl.h +++ b/src/asio_client_session_impl.h @@ -31,6 +31,8 @@ #include +#include "template.h" + namespace nghttp2 { namespace asio_http2 { namespace client { @@ -90,8 +92,8 @@ public: void do_write(); protected: - boost::array rb_; - boost::array wb_; + boost::array rb_; + boost::array wb_; std::size_t wblen_; private: diff --git a/src/asio_server_connection.h b/src/asio_server_connection.h index 5ce48d92..0d58b882 100644 --- a/src/asio_server_connection.h +++ b/src/asio_server_connection.h @@ -49,6 +49,7 @@ #include "asio_server_http2_handler.h" #include "asio_server_serve_mux.h" #include "util.h" +#include "template.h" namespace nghttp2 { @@ -153,9 +154,9 @@ private: std::shared_ptr handler_; /// Buffer for incoming data. - boost::array buffer_; + boost::array buffer_; - boost::array outbuf_; + boost::array outbuf_; bool writing_; }; diff --git a/src/deflatehd.cc b/src/deflatehd.cc index cd0c5d59..565a4790 100644 --- a/src/deflatehd.cc +++ b/src/deflatehd.cc @@ -49,6 +49,10 @@ extern "C" { #include "comp_helper.h" } +#include "template.h" + +namespace nghttp2 { + typedef struct { size_t table_size; size_t deflate_table_size; @@ -122,7 +126,7 @@ static void deflate_hd(nghttp2_hd_deflater *deflater, ssize_t rv; nghttp2_bufs bufs; - nghttp2_bufs_init2(&bufs, 4096, 16, 0, nghttp2_mem_default()); + nghttp2_bufs_init2(&bufs, 4_k, 16, 0, nghttp2_mem_default()); rv = nghttp2_hd_deflate_hd_bufs(deflater, &bufs, (nghttp2_nv *)nva.data(), nva.size()); @@ -448,3 +452,7 @@ int main(int argc, char **argv) { output_sum, comp_ratio); return 0; } + +} // namespace nghttp2 + +int main(int argc, char **argv) { return nghttp2::main(argc, argv); } diff --git a/src/h2load.cc b/src/h2load.cc index cb91fbf4..28e138ed 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -506,7 +506,7 @@ int Client::on_write() { } int Client::read_clear() { - uint8_t buf[8192]; + uint8_t buf[8_k]; for (;;) { ssize_t nread; @@ -626,7 +626,7 @@ int Client::tls_handshake() { } int Client::read_tls() { - uint8_t buf[8192]; + uint8_t buf[8_k]; ERR_clear_error(); diff --git a/src/h2load.h b/src/h2load.h index 78a20389..e965cd37 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -50,6 +50,7 @@ #include "http2.h" #include "buffer.h" +#include "template.h" using namespace nghttp2; @@ -200,7 +201,7 @@ struct Client { // The number of requests this client has done so far. size_t req_done; int fd; - Buffer<65536> wb; + Buffer<64_k> wb; enum { ERR_CONNECT_FAIL = -100 }; diff --git a/src/memchunk.h b/src/memchunk.h index 0f12c15e..1673a343 100644 --- a/src/memchunk.h +++ b/src/memchunk.h @@ -228,7 +228,7 @@ template struct Memchunks { size_t len; }; -using Memchunk16K = Memchunk<16384>; +using Memchunk16K = Memchunk<16_k>; using MemchunkPool = Pool; using DefaultMemchunks = Memchunks; diff --git a/src/nghttp.cc b/src/nghttp.cc index b1d99408..696b8b51 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -95,7 +95,7 @@ constexpr auto anchors = std::array{{ } // namespace Config::Config() - : output_upper_thres(1024 * 1024), padding(0), + : padding(0), peer_max_concurrent_streams(NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS), header_table_size(-1), weight(NGHTTP2_DEFAULT_WEIGHT), multiply(1), timeout(0.), window_bits(-1), connection_window_bits(-1), verbose(0), @@ -362,7 +362,7 @@ int submit_request(HttpClient *client, const Headers &headers, Request *req) { if (config.continuation) { for (size_t i = 0; i < 6; ++i) { build_headers.emplace_back("continuation-test-" + util::utos(i + 1), - std::string(4096, '-')); + std::string(4_k, '-')); } } auto num_initial_headers = build_headers.size(); @@ -634,7 +634,7 @@ void HttpClient::disconnect() { int HttpClient::read_clear() { ev_timer_again(loop, &rt); - std::array buf; + std::array buf; for (;;) { ssize_t nread; @@ -1149,7 +1149,7 @@ int HttpClient::read_tls() { ERR_clear_error(); - std::array buf; + std::array buf; for (;;) { auto rv = SSL_read(ssl, buf.data(), buf.size()); @@ -1525,7 +1525,7 @@ int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, if (req->inflater) { while (len > 0) { - const size_t MAX_OUTLEN = 4096; + const size_t MAX_OUTLEN = 4_k; std::array out; size_t outlen = MAX_OUTLEN; size_t tlen = len; @@ -2244,7 +2244,7 @@ int run(char **uris, int n) { << std::endl; } while (1) { - std::array buf; + std::array buf; ssize_t rret, wret; while ((rret = read(0, buf.data(), buf.size())) == -1 && errno == EINTR) diff --git a/src/nghttp.h b/src/nghttp.h index 0a7ee351..5aaa374c 100644 --- a/src/nghttp.h +++ b/src/nghttp.h @@ -52,6 +52,7 @@ #include "buffer.h" #include "http2.h" #include "nghttp2_gzip.h" +#include "template.h" namespace nghttp2 { @@ -68,7 +69,6 @@ struct Config { std::string datafile; std::string harfile; nghttp2_option *http2_option; - size_t output_upper_thres; size_t padding; ssize_t peer_max_concurrent_streams; ssize_t header_table_size; @@ -260,7 +260,7 @@ struct HttpClient { // true if the response message of HTTP Upgrade request is fully // received. It is not relevant the upgrade succeeds, or not. bool upgrade_response_complete; - Buffer<65536> wb; + Buffer<64_k> wb; // SETTINGS payload sent as token68 in HTTP Upgrade std::array settings_payload; diff --git a/src/shrpx.cc b/src/shrpx.cc index 1392c450..ab1cb486 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -945,8 +945,8 @@ void fill_default_config() { mod_config()->downstream_connections_per_host = 8; mod_config()->downstream_connections_per_frontend = 0; mod_config()->listener_disable_timeout = 0.; - mod_config()->downstream_request_buffer_size = 16 * 1024; - mod_config()->downstream_response_buffer_size = 16 * 1024; + mod_config()->downstream_request_buffer_size = 16_k; + mod_config()->downstream_response_buffer_size = 16_k; mod_config()->no_server_push = false; mod_config()->host_unix = false; mod_config()->http2_downstream_connections_per_worker = 0; @@ -955,7 +955,7 @@ void fill_default_config() { mod_config()->fetch_ocsp_response_file = strcopy(PKGDATADIR "/fetch-ocsp-response"); mod_config()->no_ocsp = false; - mod_config()->header_field_buffer = 64 * 1024; + mod_config()->header_field_buffer = 64_k; mod_config()->max_header_fields = 100; } } // namespace diff --git a/src/shrpx_client_handler.h b/src/shrpx_client_handler.h index 4367c2b5..a2df98eb 100644 --- a/src/shrpx_client_handler.h +++ b/src/shrpx_client_handler.h @@ -119,7 +119,7 @@ public: Worker *get_worker() const; using WriteBuf = Buffer<32768>; - using ReadBuf = Buffer<8192>; + using ReadBuf = Buffer<8_k>; WriteBuf *get_wb(); ReadBuf *get_rb(); diff --git a/src/shrpx_connection_handler.cc b/src/shrpx_connection_handler.cc index 50f3368b..cd93d44d 100644 --- a/src/shrpx_connection_handler.cc +++ b/src/shrpx_connection_handler.cc @@ -455,7 +455,7 @@ int ConnectionHandler::start_ocsp_update(const char *cert_file) { } void ConnectionHandler::read_ocsp_chunk() { - std::array buf; + std::array buf; for (;;) { ssize_t n; while ((n = read(ocsp_.fd, buf.data(), buf.size())) == -1 && errno == EINTR) diff --git a/src/shrpx_http2_session.h b/src/shrpx_http2_session.h index 2fa2de5a..6f642063 100644 --- a/src/shrpx_http2_session.h +++ b/src/shrpx_http2_session.h @@ -177,7 +177,7 @@ public: CONNECTION_CHECK_STARTED }; - using ReadBuf = Buffer<8192>; + using ReadBuf = Buffer<8_k>; using WriteBuf = Buffer<32768>; private: diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 500286eb..34f06b56 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -729,7 +729,7 @@ int HttpDownstreamConnection::on_read() { } ev_timer_again(conn_.loop, &conn_.rt); - std::array buf; + std::array buf; int rv; if (downstream_->get_upgraded()) { diff --git a/src/shrpx_log.cc b/src/shrpx_log.cc index 1446df6e..199114f7 100644 --- a/src/shrpx_log.cc +++ b/src/shrpx_log.cc @@ -125,7 +125,7 @@ Log::~Log() { return; } - char buf[4096]; + char buf[4_k]; auto tty = lgconf->errorlog_tty; lgconf->update_tstamp(std::chrono::system_clock::now()); @@ -172,7 +172,7 @@ void upstream_accesslog(const std::vector &lfv, return; } - char buf[4096]; + char buf[4_k]; auto downstream = lgsp.downstream; diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index 28777e3d..535909e6 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -464,7 +464,7 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler) rv = spdylay_session_server_new(&session_, version, &callbacks, this); assert(rv == 0); - uint32_t max_buffer = 65536; + uint32_t max_buffer = 64_k; rv = spdylay_session_set_option(session_, SPDYLAY_OPT_MAX_RECV_CTRL_FRAME_BUFFER, &max_buffer, sizeof(max_buffer)); diff --git a/src/template.h b/src/template.h index 144aed1b..4d7342c3 100644 --- a/src/template.h +++ b/src/template.h @@ -145,6 +145,18 @@ template void dlist_delete_all(DList &dl) { } } +constexpr unsigned long long operator"" _k(unsigned long long k) { + return k * 1024; +} + +constexpr unsigned long long operator"" _m(unsigned long long m) { + return m * 1024 * 1024; +} + +constexpr unsigned long long operator"" _g(unsigned long long g) { + return g * 1024 * 1024 * 1024; +} + } // namespace nghttp2 #endif // TEMPLATE_H