From 6ff67ae869cf8e14e035c1f5f4ac36ed9ec88230 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 6 Feb 2015 22:44:09 +0900 Subject: [PATCH] src: Move array_size to nghttp2 namespace --- src/h2load_http2_session.cc | 6 +++--- src/h2load_spdy_session.cc | 11 +++++------ src/memchunk_test.cc | 6 +++--- src/shrpx_http_downstream_connection.cc | 6 +++--- src/shrpx_log.cc | 3 ++- src/shrpx_ssl.cc | 2 +- src/shrpx_ssl_test.cc | 4 ++-- src/template.h | 4 ++++ src/util.h | 4 ---- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/h2load_http2_session.cc b/src/h2load_http2_session.cc index c9228bc1..8c202369 100644 --- a/src/h2load_http2_session.cc +++ b/src/h2load_http2_session.cc @@ -148,14 +148,14 @@ void Http2Session::on_connect() { nghttp2_session_client_new(&session_, callbacks, client_); - nghttp2_settings_entry iv[2]; + std::array iv; iv[0].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; iv[0].value = 0; iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; iv[1].value = (1 << client_->worker->config->window_bits) - 1; - rv = nghttp2_submit_settings(session_, NGHTTP2_FLAG_NONE, iv, - util::array_size(iv)); + rv = nghttp2_submit_settings(session_, NGHTTP2_FLAG_NONE, iv.data(), + iv.size()); assert(rv == 0); diff --git a/src/h2load_spdy_session.cc b/src/h2load_spdy_session.cc index afa5b9bc..25fda42f 100644 --- a/src/h2load_spdy_session.cc +++ b/src/h2load_spdy_session.cc @@ -124,12 +124,11 @@ void SpdySession::on_connect() { spdylay_session_set_option(session_, SPDYLAY_OPT_NO_AUTO_WINDOW_UPDATE, &val, sizeof(val)); - spdylay_settings_entry iv[1]; - iv[0].settings_id = SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE; - iv[0].flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; - iv[0].value = (1 << client_->worker->config->window_bits); - spdylay_submit_settings(session_, SPDYLAY_FLAG_SETTINGS_NONE, iv, - util::array_size(iv)); + spdylay_settings_entry iv; + iv.settings_id = SPDYLAY_SETTINGS_INITIAL_WINDOW_SIZE; + iv.flags = SPDYLAY_ID_FLAG_SETTINGS_NONE; + iv.value = (1 << client_->worker->config->window_bits); + spdylay_submit_settings(session_, SPDYLAY_FLAG_SETTINGS_NONE, &iv, 1); auto config = client_->worker->config; diff --git a/src/memchunk_test.cc b/src/memchunk_test.cc index 1c0f801d..f95f3032 100644 --- a/src/memchunk_test.cc +++ b/src/memchunk_test.cc @@ -154,8 +154,8 @@ void test_memchunks_riovec(void) { chunks.append(buf, sizeof(buf)); - struct iovec iov[2]; - auto iovcnt = chunks.riovec(iov, util::array_size(iov)); + std::array iov; + auto iovcnt = chunks.riovec(iov.data(), iov.size()); auto m = chunks.head; @@ -170,7 +170,7 @@ void test_memchunks_riovec(void) { chunks.drain(2 * 16); - iovcnt = chunks.riovec(iov, util::array_size(iov)); + iovcnt = chunks.riovec(iov.data(), iov.size()); CU_ASSERT(1 == iovcnt); diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 61873cad..61a11c87 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -713,12 +713,12 @@ int HttpDownstreamConnection::on_write() { auto upstream = downstream_->get_upstream(); auto input = downstream_->get_request_buf(); - struct iovec iov[MAX_WR_IOVCNT]; + std::array iov; while (input->rleft() > 0) { - auto iovcnt = input->riovec(iov, util::array_size(iov)); + auto iovcnt = input->riovec(iov.data(), iov.size()); - auto nwrite = conn_.writev_clear(iov, iovcnt); + auto nwrite = conn_.writev_clear(iov.data(), iovcnt); if (nwrite == 0) { return 0; diff --git a/src/shrpx_log.cc b/src/shrpx_log.cc index 8a661323..2c4d8f71 100644 --- a/src/shrpx_log.cc +++ b/src/shrpx_log.cc @@ -39,6 +39,7 @@ #include "shrpx_downstream.h" #include "shrpx_worker_config.h" #include "util.h" +#include "template.h" using namespace nghttp2; @@ -63,7 +64,7 @@ int Log::severity_thres_ = NOTICE; void Log::set_severity_level(int severity) { severity_thres_ = severity; } int Log::set_severity_level_by_name(const char *name) { - for (size_t i = 0, max = util::array_size(SEVERITY_STR); i < max; ++i) { + for (size_t i = 0, max = array_size(SEVERITY_STR); i < max; ++i) { if (strcmp(SEVERITY_STR[i], name) == 0) { severity_thres_ = i; return 0; diff --git a/src/shrpx_ssl.cc b/src/shrpx_ssl.cc index 834dd34d..5a7babe8 100644 --- a/src/shrpx_ssl.cc +++ b/src/shrpx_ssl.cc @@ -267,7 +267,7 @@ int alpn_select_proto_cb(SSL *ssl, const unsigned char **out, namespace { const char *tls_names[] = {"TLSv1.2", "TLSv1.1", "TLSv1.0"}; -const size_t tls_namelen = util::array_size(tls_names); +const size_t tls_namelen = array_size(tls_names); const long int tls_masks[] = {SSL_OP_NO_TLSv1_2, SSL_OP_NO_TLSv1_1, SSL_OP_NO_TLSv1}; } // namespace diff --git a/src/shrpx_ssl_test.cc b/src/shrpx_ssl_test.cc index 13e06dc7..22bac630 100644 --- a/src/shrpx_ssl_test.cc +++ b/src/shrpx_ssl_test.cc @@ -50,7 +50,7 @@ void test_shrpx_ssl_create_lookup_tree(void) { "sourceforge.net", // duplicate "*.foo.bar", // oo.bar is suffix of *.foo.bar "oo.bar"}; - int num = util::array_size(ctxs); + int num = array_size(ctxs); for (int i = 0; i < num; ++i) { tree->add_cert(ctxs[i], hostnames[i], strlen(hostnames[i])); } @@ -88,7 +88,7 @@ void test_shrpx_ssl_create_lookup_tree(void) { SSL_CTX_new(SSLv23_method()), SSL_CTX_new(SSLv23_method()), SSL_CTX_new(SSLv23_method()), SSL_CTX_new(SSLv23_method())}; const char *names[] = {"rab", "zab", "zzub", "ab"}; - num = util::array_size(ctxs2); + num = array_size(ctxs2); tree = make_unique(); for (int i = 0; i < num; ++i) { diff --git a/src/template.h b/src/template.h index efb3cb0c..ff1a281f 100644 --- a/src/template.h +++ b/src/template.h @@ -50,6 +50,10 @@ std::array make_array(T &&t, Rest &&... rest) { {std::forward(t), std::forward(rest)...}}; } +template constexpr size_t array_size(T (&)[N]) { + return N; +} + } // namespace nghttp2 #endif // TEMPLATE_H diff --git a/src/util.h b/src/util.h index 7b233b8c..a18993fa 100644 --- a/src/util.h +++ b/src/util.h @@ -54,10 +54,6 @@ namespace nghttp2 { namespace util { -template constexpr size_t array_size(T (&)[N]) { - return N; -} - template struct Defer { Defer(T t, F f) : t(t), f(std::move(f)) {}