From 8e30adbca07588d2a1c96d857ab383640fe6b62f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 10 Nov 2014 23:26:01 +0900 Subject: [PATCH] asio: Add http2::backlog API function --- src/asio_http2_impl.cc | 15 +++++++++++++-- src/asio_http2_impl.h | 2 ++ src/asio_server.cc | 9 +++++++-- src/asio_server.h | 3 ++- src/includes/nghttp2/asio_http2.h | 4 ++++ 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/asio_http2_impl.cc b/src/asio_http2_impl.cc index 23f3f1ce..2bc03955 100644 --- a/src/asio_http2_impl.cc +++ b/src/asio_http2_impl.cc @@ -68,9 +68,15 @@ void http2::num_concurrent_tasks(size_t num_concurrent_tasks) impl_->num_concurrent_tasks(num_concurrent_tasks); } +void http2::backlog(int backlog) +{ + impl_->backlog(backlog); +} + http2_impl::http2_impl() : num_threads_(1), - num_concurrent_tasks_(1) + num_concurrent_tasks_(1), + backlog_(-1) {} namespace { @@ -134,7 +140,7 @@ void http2_impl::listen(const std::string& address, uint16_t port, } server(address, port, num_threads_, num_concurrent_tasks_, - std::move(cb), std::move(ssl_ctx)).run(); + std::move(cb), std::move(ssl_ctx), backlog_).run(); } void http2_impl::num_threads(size_t num_threads) @@ -154,6 +160,11 @@ void http2_impl::num_concurrent_tasks(size_t num_concurrent_tasks) num_concurrent_tasks_ = num_concurrent_tasks; } +void http2_impl::backlog(int backlog) +{ + backlog_ = backlog; +} + } // namespace server template diff --git a/src/asio_http2_impl.h b/src/asio_http2_impl.h index 9cca408d..17451c6d 100644 --- a/src/asio_http2_impl.h +++ b/src/asio_http2_impl.h @@ -45,12 +45,14 @@ public: void num_threads(size_t num_threads); void tls(std::string private_key_file, std::string certificate_file); void num_concurrent_tasks(size_t num_concurrent_tasks); + void backlog(int backlog); private: std::string private_key_file_; std::string certificate_file_; std::unique_ptr server_; std::size_t num_threads_; std::size_t num_concurrent_tasks_; + int backlog_; }; } // namespace server diff --git a/src/asio_server.cc b/src/asio_server.cc index cbf9fd35..37254829 100644 --- a/src/asio_server.cc +++ b/src/asio_server.cc @@ -46,7 +46,8 @@ server::server(const std::string& address, uint16_t port, std::size_t io_service_pool_size, std::size_t thread_pool_size, request_cb cb, - std::unique_ptr ssl_ctx) + std::unique_ptr ssl_ctx, + int backlog) : io_service_pool_(io_service_pool_size, thread_pool_size), signals_(io_service_pool_.get_io_service()), tick_timer_(io_service_pool_.get_io_service(), @@ -76,7 +77,11 @@ server::server(const std::string& address, uint16_t port, acceptor_.open(endpoint.protocol()); acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); acceptor_.bind(endpoint); - acceptor_.listen(); + if(backlog == -1) { + acceptor_.listen(); + } else { + acceptor_.listen(backlog); + } start_accept(); diff --git a/src/asio_server.h b/src/asio_server.h index 1d2b9b67..966d04af 100644 --- a/src/asio_server.h +++ b/src/asio_server.h @@ -68,7 +68,8 @@ public: std::size_t io_service_pool_size, std::size_t thread_pool_size, request_cb cb, - std::unique_ptr ssl_ctx); + std::unique_ptr ssl_ctx, + int backlog = -1); /// Run the server's io_service loop. void run(); diff --git a/src/includes/nghttp2/asio_http2.h b/src/includes/nghttp2/asio_http2.h index f57eee76..d1427738 100644 --- a/src/includes/nghttp2/asio_http2.h +++ b/src/includes/nghttp2/asio_http2.h @@ -208,6 +208,10 @@ public: // of thread to handle incoming HTTP request. For this purpose, see // num_threads(). void num_concurrent_tasks(size_t num_concurrent_tasks); + + // Sets the maximum length to which the queue of pending + // connections. + void backlog(int backlog); private: std::unique_ptr impl_; };