aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2020-06-15 17:35:46 +0200
committerMauro Sardara <msardara@cisco.com>2020-06-15 17:35:46 +0200
commit39a761498b941932820a70ad179c276c183d6d1f (patch)
tree9efddd149f51f6687fb6f5538c733ebbaa980d19
parent658de14e6d5b1d2e0282dbba74bf41f08928f479 (diff)
[HICN-629] Add multithreading feature to hicn-http-proxy with SO_REUSEPORT socket option.
Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: I8930178ba09ca23bd593f2a4008cf0d75f502684
-rw-r--r--apps/http-proxy/includes/hicn/http-proxy/http_proxy.h11
-rw-r--r--apps/http-proxy/src/http_proxy.cc32
2 files changed, 24 insertions, 19 deletions
diff --git a/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h b/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h
index 15a468842..a4139a620 100644
--- a/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h
+++ b/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h
@@ -32,13 +32,18 @@ class TcpListener {
using AcceptCallback = std::function<void(asio::ip::tcp::socket&&)>;
TcpListener(asio::io_service& io_service, short port, AcceptCallback callback)
- : acceptor_(io_service,
- asio::ip::tcp::endpoint(
- asio::ip::address::from_string("127.0.0.1"), port)),
+ : acceptor_(io_service),
#if ((ASIO_VERSION / 100 % 1000) < 12)
socket_(io_service),
#endif
callback_(callback) {
+ acceptor_.open(asio::ip::tcp::v4());
+ typedef asio::detail::socket_option::boolean<SOL_SOCKET, SO_REUSEPORT>
+ reuse_port;
+ acceptor_.set_option(reuse_port(true));
+ acceptor_.bind(asio::ip::tcp::endpoint(
+ asio::ip::address::from_string("127.0.0.1"), port));
+ acceptor_.listen();
}
public:
diff --git a/apps/http-proxy/src/http_proxy.cc b/apps/http-proxy/src/http_proxy.cc
index 4484b5a1a..c252afe88 100644
--- a/apps/http-proxy/src/http_proxy.cc
+++ b/apps/http-proxy/src/http_proxy.cc
@@ -15,13 +15,11 @@
#include <hicn/http-proxy/http_proxy.h>
#include <hicn/http-proxy/http_session.h>
-
+#include <hicn/http-proxy/utils.h>
#include <hicn/transport/core/interest.h>
#include <hicn/transport/utils/log.h>
#include <hicn/transport/utils/string_utils.h>
-#include <hicn/http-proxy/utils.h>
-
namespace transport {
using core::Interest;
@@ -266,21 +264,23 @@ TcpReceiver::TcpReceiver(std::uint16_t port, const std::string& prefix,
prefix_(prefix),
ipv6_first_word_(ipv6_first_word),
prefix_hash_(generatePrefix(prefix_, ipv6_first_word_)),
- forwarder_config_(thread_.getIoService(), [this](std::error_code ec) {
- if (!ec) {
- listener_.doAccept();
- for (int i = 0; i < 10; i++) {
- http_clients_.emplace_back(
- new HTTPClientConnectionCallback(*this, thread_));
- }
- }
- }),
+ forwarder_config_(
+ thread_.getIoService(),
+ [this](std::error_code ec) {
+ if (!ec) {
+ listener_.doAccept();
+ for (int i = 0; i < 10; i++) {
+ http_clients_.emplace_back(
+ new HTTPClientConnectionCallback(*this, thread_));
+ }
+ }
+ }),
stopped_(false) {
forwarder_config_.tryToConnectToForwarder();
}
void TcpReceiver::stop() {
- thread_.add([this](){
+ thread_.add([this]() {
stopped_ = true;
/* Stop the listener */
@@ -295,9 +295,9 @@ void TcpReceiver::stop() {
}
/* Delete unused clients */
- for (auto& client : http_clients_) {
- delete client;
- }
+ for (auto& client : http_clients_) {
+ delete client;
+ }
});
}