asio: Add http2::backlog API function

This commit is contained in:
Tatsuhiro Tsujikawa 2014-11-10 23:26:01 +09:00
parent 9adfd08848
commit 8e30adbca0
5 changed files with 28 additions and 5 deletions

View File

@ -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<typename T, typename F>

View File

@ -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> server_;
std::size_t num_threads_;
std::size_t num_concurrent_tasks_;
int backlog_;
};
} // namespace server

View File

@ -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<boost::asio::ssl::context> ssl_ctx)
std::unique_ptr<boost::asio::ssl::context> 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);
if(backlog == -1) {
acceptor_.listen();
} else {
acceptor_.listen(backlog);
}
start_accept();

View File

@ -68,7 +68,8 @@ public:
std::size_t io_service_pool_size,
std::size_t thread_pool_size,
request_cb cb,
std::unique_ptr<boost::asio::ssl::context> ssl_ctx);
std::unique_ptr<boost::asio::ssl::context> ssl_ctx,
int backlog = -1);
/// Run the server's io_service loop.
void run();

View File

@ -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<http2_impl> impl_;
};