From 54851ef7a6db7fdc072c7119b171bb5bd10a879f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 5 Feb 2015 23:21:53 +0900 Subject: [PATCH] src: Move make_unique to nghttp2 namespace --- src/HttpServer.cc | 11 ++++---- src/Makefile.am | 2 +- src/asio_http2_handler.cc | 7 ++--- src/asio_http2_impl.cc | 5 ++-- src/h2load.cc | 21 ++++++++------- src/memchunk.h | 5 ++-- src/memchunk_test.cc | 1 + src/nghttp.cc | 9 ++++--- src/shrpx.cc | 15 ++++++----- src/shrpx_client_handler.cc | 22 +++++++-------- src/shrpx_config.cc | 7 ++--- src/shrpx_connection_handler.cc | 14 +++++----- src/shrpx_http2_session.cc | 5 ++-- src/shrpx_http2_upstream.cc | 4 +-- src/shrpx_https_upstream.cc | 6 ++--- src/shrpx_spdy_upstream.cc | 5 ++-- src/shrpx_worker.cc | 7 ++--- src/template.h | 48 +++++++++++++++++++++++++++++++++ src/util.h | 12 --------- 19 files changed, 127 insertions(+), 79 deletions(-) create mode 100644 src/template.h diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 0bace4d6..0a4221aa 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -47,6 +47,7 @@ #include "http2.h" #include "util.h" #include "ssl.h" +#include "template.h" #ifndef O_BINARY #define O_BINARY (0) @@ -223,7 +224,7 @@ public: } } auto handler = - util::make_unique(this, fd, ssl, get_next_session_id()); + make_unique(this, fd, ssl, get_next_session_id()); handler->setup_bev(); if (!ssl) { if (handler->on_connect() != 0) { @@ -754,7 +755,7 @@ int Http2Handler::submit_push_promise(Stream *stream, return promised_stream_id; } - auto promised_stream = util::make_unique(this, promised_stream_id); + auto promised_stream = make_unique(this, promised_stream_id); append_nv(promised_stream.get(), nva); add_stream(promised_stream_id, std::move(promised_stream)); @@ -1083,7 +1084,7 @@ int on_begin_headers_callback(nghttp2_session *session, return 0; } - auto stream = util::make_unique(hd, frame->hd.stream_id); + auto stream = make_unique(hd, frame->hd.stream_id); add_stream_read_timeout(stream.get()); @@ -1362,10 +1363,10 @@ public: if (config_->verbose) { std::cerr << "spawning thread #" << i << std::endl; } - auto worker = util::make_unique(); + auto worker = make_unique(); auto loop = ev_loop_new(0); worker->sessions = - util::make_unique(loop, config_, sessions_->get_ssl_ctx()); + make_unique(loop, config_, sessions_->get_ssl_ctx()); ev_async_init(&worker->w, worker_acceptcb); worker->w.data = worker.get(); ev_async_start(loop, &worker->w); diff --git a/src/Makefile.am b/src/Makefile.am index 5b2f7ac1..a68a9ae9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -120,7 +120,7 @@ NGHTTPX_SRCS = \ shrpx_downstream_connection_pool.cc shrpx_downstream_connection_pool.h \ shrpx_rate_limit.cc shrpx_rate_limit.h \ shrpx_connection.cc shrpx_connection.h \ - buffer.h memchunk.h + buffer.h memchunk.h template.h if HAVE_SPDYLAY NGHTTPX_SRCS += shrpx_spdy_upstream.cc shrpx_spdy_upstream.h diff --git a/src/asio_http2_handler.cc b/src/asio_http2_handler.cc index 2643d961..8a5ba5a0 100644 --- a/src/asio_http2_handler.cc +++ b/src/asio_http2_handler.cc @@ -28,12 +28,13 @@ #include "http2.h" #include "util.h" +#include "template.h" namespace nghttp2 { namespace asio_http2 { -channel::channel() : impl_(util::make_unique()) {} +channel::channel() : impl_(make_unique()) {} void channel::post(void_cb cb) { impl_->post(std::move(cb)); } @@ -51,7 +52,7 @@ namespace server { extern std::shared_ptr cached_date; -request::request() : impl_(util::make_unique()) {} +request::request() : impl_(make_unique()) {} const std::vector
&request::headers() const { return impl_->headers(); } @@ -84,7 +85,7 @@ bool request::run_task(thread_cb start) { request_impl &request::impl() { return *impl_; } -response::response() : impl_(util::make_unique()) {} +response::response() : impl_(make_unique()) {} void response::write_head(unsigned int status_code, std::vector
headers) { diff --git a/src/asio_http2_impl.cc b/src/asio_http2_impl.cc index d123c0e6..d793befe 100644 --- a/src/asio_http2_impl.cc +++ b/src/asio_http2_impl.cc @@ -33,6 +33,7 @@ #include "asio_server.h" #include "util.h" #include "ssl.h" +#include "template.h" namespace nghttp2 { @@ -40,7 +41,7 @@ namespace asio_http2 { namespace server { -http2::http2() : impl_(util::make_unique()) {} +http2::http2() : impl_(make_unique()) {} http2::~http2() {} @@ -75,7 +76,7 @@ void http2_impl::listen(const std::string &address, uint16_t port, std::unique_ptr ssl_ctx; if (!private_key_file_.empty() && !certificate_file_.empty()) { - ssl_ctx = util::make_unique( + ssl_ctx = make_unique( boost::asio::ssl::context::sslv23); ssl_ctx->use_private_key_file(private_key_file_, diff --git a/src/h2load.cc b/src/h2load.cc index f30e26d3..b5fc484f 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -55,6 +55,7 @@ #include "ssl.h" #include "http2.h" #include "util.h" +#include "template.h" using namespace nghttp2; @@ -399,13 +400,13 @@ int Client::on_connect() { for (int i = 0; i < 2; ++i) { if (next_proto) { if (util::check_h2_is_selected(next_proto, next_proto_len)) { - session = util::make_unique(this); + session = make_unique(this); } else { #ifdef HAVE_SPDYLAY auto spdy_version = spdylay_npn_get_version(next_proto, next_proto_len); if (spdy_version) { - session = util::make_unique(this, spdy_version); + session = make_unique(this, spdy_version); } else { debug_nextproto_error(); fail(); @@ -434,17 +435,17 @@ int Client::on_connect() { } else { switch (config.no_tls_proto) { case Config::PROTO_HTTP2: - session = util::make_unique(this); + session = make_unique(this); break; #ifdef HAVE_SPDYLAY case Config::PROTO_SPDY2: - session = util::make_unique(this, SPDYLAY_PROTO_SPDY2); + session = make_unique(this, SPDYLAY_PROTO_SPDY2); break; case Config::PROTO_SPDY3: - session = util::make_unique(this, SPDYLAY_PROTO_SPDY3); + session = make_unique(this, SPDYLAY_PROTO_SPDY3); break; case Config::PROTO_SPDY3_1: - session = util::make_unique(this, SPDYLAY_PROTO_SPDY3_1); + session = make_unique(this, SPDYLAY_PROTO_SPDY3_1); break; #endif // HAVE_SPDYLAY default: @@ -704,7 +705,7 @@ Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients, ++req_todo; --nreqs_rem; } - clients.push_back(util::make_unique(this, req_todo)); + clients.push_back(make_unique(this, req_todo)); } } @@ -1327,7 +1328,7 @@ int main(int argc, char **argv) { << " concurrent clients, " << nreqs << " total requests" << std::endl; workers.push_back( - util::make_unique(i, ssl_ctx, nreqs, nclients, &config)); + make_unique(i, ssl_ctx, nreqs, nclients, &config)); auto &worker = workers.back(); futures.push_back( std::async(std::launch::async, [&worker]() { worker->run(); })); @@ -1339,8 +1340,8 @@ int main(int argc, char **argv) { std::cout << "spawning thread #" << (config.nthreads - 1) << ": " << nclients_last << " concurrent clients, " << nreqs_last << " total requests" << std::endl; - workers.push_back(util::make_unique( - config.nthreads - 1, ssl_ctx, nreqs_last, nclients_last, &config)); + workers.push_back(make_unique(config.nthreads - 1, ssl_ctx, + nreqs_last, nclients_last, &config)); workers.back()->run(); #ifndef NOTHREADS diff --git a/src/memchunk.h b/src/memchunk.h index 76334a4b..64e386af 100644 --- a/src/memchunk.h +++ b/src/memchunk.h @@ -29,11 +29,12 @@ #include +#include #include #include #include -#include "util.h" +#include "template.h" namespace nghttp2 { @@ -67,7 +68,7 @@ template struct Pool { return m; } - pool = util::make_unique(std::move(pool)); + pool = make_unique(std::move(pool)); poolsize += T::size; return pool.get(); } diff --git a/src/memchunk_test.cc b/src/memchunk_test.cc index 4d90553c..1c0f801d 100644 --- a/src/memchunk_test.cc +++ b/src/memchunk_test.cc @@ -29,6 +29,7 @@ #include #include "memchunk.h" +#include "util.h" namespace nghttp2 { diff --git a/src/nghttp.cc b/src/nghttp.cc index 15b8c0dc..9a3f8061 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -53,6 +53,7 @@ #include "util.h" #include "base64.h" #include "ssl.h" +#include "template.h" #ifndef O_BINARY #define O_BINARY (0) @@ -731,7 +732,7 @@ int HttpClient::connected() { writefn = &HttpClient::write_clear; if (need_upgrade()) { - htp = util::make_unique(); + htp = make_unique(); http_parser_init(htp.get(), HTTP_RESPONSE); htp->data = this; @@ -1234,8 +1235,8 @@ bool HttpClient::add_request(const std::string &uri, path_cache.insert(uri); } - reqvec.push_back(util::make_unique( - uri, u, data_prd, data_length, pri_spec, std::move(dep), pri, level)); + reqvec.push_back(make_unique(uri, u, data_prd, data_length, pri_spec, + std::move(dep), pri, level)); return true; } @@ -1632,7 +1633,7 @@ int on_begin_headers_callback(nghttp2_session *session, nghttp2_priority_spec_default_init(&pri_spec); - auto req = util::make_unique("", u, nullptr, 0, pri_spec, nullptr); + auto req = make_unique("", u, nullptr, 0, pri_spec, nullptr); req->stream_id = stream_id; nghttp2_session_set_stream_user_data(session, stream_id, req.get()); diff --git a/src/shrpx.cc b/src/shrpx.cc index 33758ed1..ef94c87d 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -66,6 +66,7 @@ #include "util.h" #include "app_helper.h" #include "ssl.h" +#include "template.h" extern char **environ; @@ -153,7 +154,7 @@ std::unique_ptr create_acceptor(ConnectionHandler *handler, if (port == get_config()->port) { LOG(NOTICE) << "Listening on port " << get_config()->port; - return util::make_unique(fd, handler); + return make_unique(fd, handler); } LOG(WARN) << "Port was changed between old binary (" << port @@ -201,7 +202,7 @@ std::unique_ptr create_acceptor(ConnectionHandler *handler, if (fd == -1) { continue; } - util::make_socket_nonblocking(fd); + make_socket_nonblocking(fd); #endif // !SOCK_NONBLOCK int val = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, @@ -260,7 +261,7 @@ std::unique_ptr create_acceptor(ConnectionHandler *handler, LOG(NOTICE) << "Listening on " << host << ", port " << get_config()->port; - return util::make_unique(fd, handler); + return make_unique(fd, handler); } } // namespace @@ -354,7 +355,7 @@ void exec_binary_signal_cb(struct ev_loop *loop, ev_signal *w, int revents) { return; } - auto argv = util::make_unique(get_config()->argc + 1); + auto argv = make_unique(get_config()->argc + 1); argv[0] = exec_path; for (int i = 1; i < get_config()->argc; ++i) { @@ -366,7 +367,7 @@ void exec_binary_signal_cb(struct ev_loop *loop, ev_signal *w, int revents) { for (char **p = environ; *p; ++p, ++envlen) ; // 3 for missing fd4, fd6 and port. - auto envp = util::make_unique(envlen + 3 + 1); + auto envp = make_unique(envlen + 3 + 1); size_t envidx = 0; auto acceptor4 = conn_handler->get_acceptor4(); @@ -511,7 +512,7 @@ namespace { int event_loop() { auto loop = EV_DEFAULT; - auto conn_handler = util::make_unique(loop); + auto conn_handler = make_unique(loop); if (get_config()->daemon) { if (daemon(0, 0) == -1) { auto error = errno; @@ -1720,7 +1721,7 @@ int main(int argc, char **argv) { #ifndef NOTHREADS std::unique_ptr lock; if (!get_config()->tls_ctx_per_worker) { - lock = util::make_unique(); + lock = make_unique(); } #endif // NOTHREADS diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index e098cf4b..8f4fad46 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -42,6 +42,7 @@ #include "shrpx_spdy_upstream.h" #endif // HAVE_SPDYLAY #include "util.h" +#include "template.h" using namespace nghttp2; @@ -377,7 +378,7 @@ ClientHandler::ClientHandler(struct ev_loop *loop, int fd, SSL *ssl, // For non-TLS version, first create HttpsUpstream. It may be // upgraded to HTTP/2 through HTTP Upgrade or direct HTTP/2 // connection. - upstream_ = util::make_unique(this); + upstream_ = make_unique(this); alpn_ = "http/1.1"; read_ = &ClientHandler::read_clear; write_ = &ClientHandler::write_clear; @@ -455,7 +456,7 @@ int ClientHandler::validate_next_proto() { on_read_ = &ClientHandler::upstream_http2_connhd_read; - auto http2_upstream = util::make_unique(this); + auto http2_upstream = make_unique(this); if (!ssl::check_http2_requirement(conn_.tls.ssl)) { rv = http2_upstream->terminate_session(NGHTTP2_INADEQUATE_SECURITY); @@ -480,7 +481,7 @@ int ClientHandler::validate_next_proto() { #ifdef HAVE_SPDYLAY uint16_t version = spdylay_npn_get_version(next_proto, next_proto_len); if (version) { - upstream_ = util::make_unique(version, this); + upstream_ = make_unique(version, this); switch (version) { case SPDYLAY_PROTO_SPDY2: @@ -507,7 +508,7 @@ int ClientHandler::validate_next_proto() { } #endif // HAVE_SPDYLAY if (next_proto_len == 8 && memcmp("http/1.1", next_proto, 8) == 0) { - upstream_ = util::make_unique(this); + upstream_ = make_unique(this); alpn_ = "http/1.1"; // At this point, input buffer is already filled with some @@ -532,7 +533,7 @@ int ClientHandler::validate_next_proto() { if (LOG_ENABLED(INFO)) { CLOG(INFO, this) << "No protocol negotiated. Fallback to HTTP/1.1"; } - upstream_ = util::make_unique(this); + upstream_ = make_unique(this); alpn_ = "http/1.1"; // At this point, input buffer is already filled with some bytes. @@ -594,11 +595,10 @@ ClientHandler::get_downstream_connection() { } if (http2session_) { - dconn = util::make_unique(dconn_pool_, - http2session_); - } else { dconn = - util::make_unique(dconn_pool_, conn_.loop); + make_unique(dconn_pool_, http2session_); + } else { + dconn = make_unique(dconn_pool_, conn_.loop); } dconn->set_client_handler(this); return dconn; @@ -632,7 +632,7 @@ ConnectBlocker *ClientHandler::get_http1_connect_blocker() const { } void ClientHandler::direct_http2_upgrade() { - upstream_ = util::make_unique(this); + upstream_ = make_unique(this); // TODO We don't know exact h2 draft version in direct upgrade. We // just use library default for now. alpn_ = NGHTTP2_CLEARTEXT_PROTO_VERSION_ID; @@ -640,7 +640,7 @@ void ClientHandler::direct_http2_upgrade() { } int ClientHandler::perform_http2_upgrade(HttpsUpstream *http) { - auto upstream = util::make_unique(this); + auto upstream = make_unique(this); if (upstream->upgrade_upstream(http) != 0) { return -1; } diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index f7e5c220..3c94440c 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -46,6 +46,7 @@ #include "shrpx_http.h" #include "http2.h" #include "util.h" +#include "template.h" using namespace nghttp2; @@ -208,7 +209,7 @@ bool is_secure(const char *filename) { std::unique_ptr read_tls_ticket_key_file(const std::vector &files) { - auto ticket_keys = util::make_unique(); + auto ticket_keys = make_unique(); auto &keys = ticket_keys->keys; keys.resize(files.size()); size_t i = 0; @@ -251,7 +252,7 @@ FILE *open_file_for_write(const char *filename) { // We get race condition if execve is called at the same time. if (fd != -1) { - util::make_socket_closeonexec(fd); + make_socket_closeonexec(fd); } #endif if (fd == -1) { @@ -293,7 +294,7 @@ std::unique_ptr strcopy(const char *val) { } std::unique_ptr strcopy(const char *val, size_t len) { - auto res = util::make_unique(len + 1); + auto res = make_unique(len + 1); memcpy(res.get(), val, len); res[len] = '\0'; return res; diff --git a/src/shrpx_connection_handler.cc b/src/shrpx_connection_handler.cc index 6f5c0779..930ea077 100644 --- a/src/shrpx_connection_handler.cc +++ b/src/shrpx_connection_handler.cc @@ -39,6 +39,7 @@ #include "shrpx_downstream_connection.h" #include "shrpx_accept_handler.h" #include "util.h" +#include "template.h" using namespace nghttp2; @@ -62,8 +63,7 @@ ConnectionHandler::ConnectionHandler(struct ev_loop *loop) : loop_(loop), sv_ssl_ctx_(nullptr), cl_ssl_ctx_(nullptr), // rate_limit_group_(bufferevent_rate_limit_group_new( // evbase, get_config()->worker_rate_limit_cfg)), - worker_stat_(util::make_unique()), - worker_round_robin_cnt_(0) { + worker_stat_(make_unique()), worker_round_robin_cnt_(0) { ev_timer_init(&disable_acceptor_timer_, acceptor_disable_cb, 0., 0.); disable_acceptor_timer_.data = this; } @@ -107,9 +107,9 @@ void ConnectionHandler::create_worker_thread(size_t num) { assert(workers_.size() == 0); for (size_t i = 0; i < num; ++i) { - workers_.push_back(util::make_unique(sv_ssl_ctx_, cl_ssl_ctx_, - worker_config->cert_tree, - worker_config->ticket_keys)); + workers_.push_back(make_unique(sv_ssl_ctx_, cl_ssl_ctx_, + worker_config->cert_tree, + worker_config->ticket_keys)); if (LOG_ENABLED(INFO)) { LLOG(INFO, this) << "Created thread #" << workers_.size() - 1; @@ -209,11 +209,11 @@ struct ev_loop *ConnectionHandler::get_loop() const { } void ConnectionHandler::create_http2_session() { - http2session_ = util::make_unique(loop_, cl_ssl_ctx_); + http2session_ = make_unique(loop_, cl_ssl_ctx_); } void ConnectionHandler::create_http1_connect_blocker() { - http1_connect_blocker_ = util::make_unique(loop_); + http1_connect_blocker_ = make_unique(loop_); } const WorkerStat *ConnectionHandler::get_worker_stat() const { diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index a6031e2c..7c1b9660 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -43,6 +43,7 @@ #include "http2.h" #include "util.h" #include "base64.h" +#include "template.h" using namespace nghttp2; @@ -265,7 +266,7 @@ int Http2Session::initiate_connection() { on_read_ = &Http2Session::downstream_read_proxy; on_write_ = &Http2Session::downstream_connect_proxy; - proxy_htp_ = util::make_unique(); + proxy_htp_ = make_unique(); http_parser_init(proxy_htp_.get(), HTTP_RESPONSE); proxy_htp_->data = this; @@ -505,7 +506,7 @@ int Http2Session::submit_request(Http2DownstreamConnection *dconn, int32_t pri, const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd) { assert(state_ == CONNECTED); - auto sd = util::make_unique(); + auto sd = make_unique(); // TODO Specify nullptr to pri_spec for now auto stream_id = nghttp2_submit_request(session_, nullptr, nva, nvlen, data_prd, sd.get()); diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index c22b57d1..79a9c5d2 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -40,6 +40,7 @@ #include "util.h" #include "base64.h" #include "app_helper.h" +#include "template.h" using namespace nghttp2; @@ -244,8 +245,7 @@ int on_begin_headers_callback(nghttp2_session *session, } // TODO Use priority 0 for now - auto downstream = - util::make_unique(upstream, frame->hd.stream_id, 0); + auto downstream = make_unique(upstream, frame->hd.stream_id, 0); downstream->reset_upstream_rtimer(); diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 83bde251..dda329a6 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -31,13 +31,13 @@ #include "shrpx_client_handler.h" #include "shrpx_downstream.h" #include "shrpx_downstream_connection.h" -//#include "shrpx_http2_downstream_connection.h" #include "shrpx_http.h" #include "shrpx_config.h" #include "shrpx_error.h" #include "shrpx_worker_config.h" #include "http2.h" #include "util.h" +#include "template.h" using namespace nghttp2; @@ -64,7 +64,7 @@ int htp_msg_begin(http_parser *htp) { } upstream->reset_current_header_length(); // TODO specify 0 as priority for now - upstream->attach_downstream(util::make_unique(upstream, 0, 0)); + upstream->attach_downstream(make_unique(upstream, 0, 0)); return 0; } } // namespace @@ -582,7 +582,7 @@ void HttpsUpstream::error_reply(unsigned int status_code) { auto downstream = get_downstream(); if (!downstream) { - attach_downstream(util::make_unique(this, 1, 1)); + attach_downstream(make_unique(this, 1, 1)); downstream = get_downstream(); } diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index d3b1c80c..8e9d5475 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -39,6 +39,7 @@ #include "shrpx_worker_config.h" #include "http2.h" #include "util.h" +#include "template.h" using namespace nghttp2; @@ -794,7 +795,7 @@ int SpdyUpstream::error_reply(Downstream *downstream, Downstream *SpdyUpstream::add_pending_downstream(int32_t stream_id, int32_t priority) { - auto downstream = util::make_unique(this, stream_id, priority); + auto downstream = make_unique(this, stream_id, priority); auto res = downstream.get(); downstream_queue_.add_pending(std::move(downstream)); @@ -844,7 +845,7 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream) { } size_t nheader = downstream->get_response_headers().size(); // 8 means server, :status, :version and possible via header field. - auto nv = util::make_unique( + auto nv = make_unique( nheader * 2 + 8 + get_config()->add_response_headers.size() * 2 + 1); size_t hdidx = 0; diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index 83ae8bf9..9f5682ca 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -35,6 +35,7 @@ #include "shrpx_worker_config.h" #include "shrpx_connect_blocker.h" #include "util.h" +#include "template.h" using namespace nghttp2; @@ -51,7 +52,7 @@ Worker::Worker(SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx, ssl::CertLookupTree *cert_tree, const std::shared_ptr &ticket_keys) : loop_(ev_loop_new(0)), sv_ssl_ctx_(sv_ssl_ctx), cl_ssl_ctx_(cl_ssl_ctx), - worker_stat_(util::make_unique()) { + worker_stat_(make_unique()) { ev_async_init(&w_, eventcb); w_.data = this; ev_async_start(loop_, &w_); @@ -66,9 +67,9 @@ Worker::Worker(SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx, } if (get_config()->downstream_proto == PROTO_HTTP2) { - http2session_ = util::make_unique(loop_, cl_ssl_ctx_); + http2session_ = make_unique(loop_, cl_ssl_ctx_); } else { - http1_connect_blocker_ = util::make_unique(loop_); + http1_connect_blocker_ = make_unique(loop_); } worker_config->ticket_keys = ticket_keys; diff --git a/src/template.h b/src/template.h new file mode 100644 index 00000000..422cc1ef --- /dev/null +++ b/src/template.h @@ -0,0 +1,48 @@ +/* + * nghttp2 - HTTP/2 C Library + * + * Copyright (c) 2015 Tatsuhiro Tsujikawa + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#ifndef TEMPLATE_H +#define TEMPLATE_H + +#include "nghttp2_config.h" + +#include + +namespace nghttp2 { + +template +typename std::enable_if::value, std::unique_ptr>::type +make_unique(U &&... u) { + return std::unique_ptr(new T(std::forward(u)...)); +} + +template +typename std::enable_if::value, std::unique_ptr>::type +make_unique(size_t size) { + return std::unique_ptr(new typename std::remove_extent::type[size]()); +} + +} // namespace nghttp2 + +#endif // TEMPLATE_H diff --git a/src/util.h b/src/util.h index 9f48411f..186f7673 100644 --- a/src/util.h +++ b/src/util.h @@ -403,18 +403,6 @@ template std::string utox(T n) { return res; } -template -typename std::enable_if::value, std::unique_ptr>::type -make_unique(U &&... u) { - return std::unique_ptr(new T(std::forward(u)...)); -} - -template -typename std::enable_if::value, std::unique_ptr>::type -make_unique(size_t size) { - return std::unique_ptr(new typename std::remove_extent::type[size]()); -} - void to_token68(std::string &base64str); void to_base64(std::string &token68str);