From 6800d317e7838bdfb17b2f9bfca20d3ed4331ee8 Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Sun, 11 Nov 2018 23:55:06 +0000 Subject: [PATCH] added access to the number of the current server port --- src/asio_server.cc | 9 +++++++++ src/asio_server.h | 3 +++ src/asio_server_http2.cc | 2 ++ src/asio_server_http2_impl.cc | 2 ++ src/asio_server_http2_impl.h | 1 + src/includes/nghttp2/asio_http2_server.h | 3 +++ 6 files changed, 20 insertions(+) diff --git a/src/asio_server.cc b/src/asio_server.cc index 33db41c5..74c92276 100644 --- a/src/asio_server.cc +++ b/src/asio_server.cc @@ -200,6 +200,15 @@ server::io_services() const { return io_service_pool_.io_services(); } +const std::vector server::ports() const { + auto ports = std::vector(acceptors_.size()); + auto index = 0; + for (const auto &acceptor : acceptors_) { + ports[index++] = acceptor.local_endpoint().port(); + } + return ports; +} + } // namespace server } // namespace asio_http2 } // namespace nghttp2 diff --git a/src/asio_server.h b/src/asio_server.h index ba840348..1190e322 100644 --- a/src/asio_server.h +++ b/src/asio_server.h @@ -79,6 +79,9 @@ public: const std::vector> & io_services() const; + /// Returns a vector with all the acceptors ports in use. + const std::vector ports() const; + private: /// Initiate an asynchronous accept operation. void start_accept(tcp::acceptor &acceptor, serve_mux &mux); diff --git a/src/asio_server_http2.cc b/src/asio_server_http2.cc index 1c2d172c..02d3d197 100644 --- a/src/asio_server_http2.cc +++ b/src/asio_server_http2.cc @@ -90,6 +90,8 @@ http2::io_services() const { return impl_->io_services(); } +std::vector http2::ports() const { return impl_->ports(); } + } // namespace server } // namespace asio_http2 diff --git a/src/asio_server_http2_impl.cc b/src/asio_server_http2_impl.cc index 83368d45..00afdd65 100644 --- a/src/asio_server_http2_impl.cc +++ b/src/asio_server_http2_impl.cc @@ -78,6 +78,8 @@ http2_impl::io_services() const { return server_->io_services(); } +std::vector http2_impl::ports() const { return server_->ports(); } + } // namespace server } // namespace asio_http2 diff --git a/src/asio_server_http2_impl.h b/src/asio_server_http2_impl.h index b55b68c5..93a6d2cc 100644 --- a/src/asio_server_http2_impl.h +++ b/src/asio_server_http2_impl.h @@ -54,6 +54,7 @@ public: void join(); const std::vector> & io_services() const; + std::vector ports() const; private: std::unique_ptr server_; diff --git a/src/includes/nghttp2/asio_http2_server.h b/src/includes/nghttp2/asio_http2_server.h index d8a32d69..d4ec489a 100644 --- a/src/includes/nghttp2/asio_http2_server.h +++ b/src/includes/nghttp2/asio_http2_server.h @@ -214,6 +214,9 @@ public: const std::vector> & io_services() const; + // Returns a vector with the ports in use + std::vector ports() const; + private: std::unique_ptr impl_; };