From f5285d1f5aae2cc07996a9d3a62ba4e250a8177e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 2 Oct 2016 16:18:35 +0900 Subject: [PATCH] nghttpx: Add BlockAllocator to SharedDownstreamAddr --- src/shrpx_worker.cc | 9 ++++++--- src/shrpx_worker.h | 24 ++++++++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index 5da53dd8..3ea416d6 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -198,13 +198,16 @@ void Worker::replace_downstream_config( auto &dst_addr = shared_addr->addrs[j]; dst_addr.addr = src_addr.addr; - dst_addr.host = src_addr.host; - dst_addr.hostport = src_addr.hostport; + dst_addr.host = + make_string_ref(shared_addr->balloc, StringRef{src_addr.host}); + dst_addr.hostport = + make_string_ref(shared_addr->balloc, StringRef{src_addr.hostport}); dst_addr.port = src_addr.port; dst_addr.host_unix = src_addr.host_unix; dst_addr.proto = src_addr.proto; dst_addr.tls = src_addr.tls; - dst_addr.sni = src_addr.sni; + dst_addr.sni = + make_string_ref(shared_addr->balloc, StringRef{src_addr.sni}); dst_addr.fall = src_addr.fall; dst_addr.rise = src_addr.rise; diff --git a/src/shrpx_worker.h b/src/shrpx_worker.h index 948e2e35..c68c2485 100644 --- a/src/shrpx_worker.h +++ b/src/shrpx_worker.h @@ -48,6 +48,7 @@ #include "shrpx_ssl.h" #include "shrpx_live_check.h" #include "shrpx_connect_blocker.h" +#include "allocator.h" using namespace nghttp2; @@ -75,15 +76,15 @@ struct DownstreamAddr { Address addr; // backend address. If |host_unix| is true, this is UNIX domain // socket path. - ImmutableString host; - ImmutableString hostport; + StringRef host; + StringRef hostport; // backend port. 0 if |host_unix| is true. uint16_t port; // true if |host| contains UNIX domain socket path. bool host_unix; // sni field to send remote server if TLS is enabled. - ImmutableString sni; + StringRef sni; std::unique_ptr connect_blocker; std::unique_ptr live_check; @@ -128,8 +129,18 @@ struct WeightedPri { struct SharedDownstreamAddr { SharedDownstreamAddr() - : next{0}, http1_pri{}, http2_pri{}, affinity{AFFINITY_NONE} {} + : balloc(1024, 1024), + next{0}, + http1_pri{}, + http2_pri{}, + affinity{AFFINITY_NONE} {} + SharedDownstreamAddr(const SharedDownstreamAddr &) = delete; + SharedDownstreamAddr(SharedDownstreamAddr &&) = delete; + SharedDownstreamAddr &operator=(const SharedDownstreamAddr &) = delete; + SharedDownstreamAddr &operator=(SharedDownstreamAddr &&) = delete; + + BlockAllocator balloc; std::vector addrs; // Bunch of session affinity hash. Only used if affinity == // AFFINITY_IP. @@ -162,6 +173,11 @@ struct SharedDownstreamAddr { struct DownstreamAddrGroup { DownstreamAddrGroup() : retired{false} {}; + DownstreamAddrGroup(const DownstreamAddrGroup &) = delete; + DownstreamAddrGroup(DownstreamAddrGroup &&) = delete; + DownstreamAddrGroup &operator=(const DownstreamAddrGroup &) = delete; + DownstreamAddrGroup &operator=(DownstreamAddrGroup &&) = delete; + ImmutableString pattern; std::shared_ptr shared_addr; // true if this group is no longer used for new request. If this is