From 1fda861670f67b3220fc661e7975f160f99e6aed Mon Sep 17 00:00:00 2001 From: Per Larsson Date: Tue, 16 Nov 2021 21:07:17 +0100 Subject: Added upstream connect/transfer timeout options. --- zenserver/upstream/upstreamcache.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'zenserver/upstream/upstreamcache.cpp') diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp index 085932685..2741e3e51 100644 --- a/zenserver/upstream/upstreamcache.cpp +++ b/zenserver/upstream/upstreamcache.cpp @@ -442,9 +442,13 @@ namespace detail { }; public: - ZenUpstreamEndpoint(std::span Urls) : m_Log(zen::logging::Get("upstream")), m_DisplayName("ZEN") + ZenUpstreamEndpoint(const ZenClientOptions& Options) + : m_Log(zen::logging::Get("upstream")) + , m_DisplayName("ZEN") + , m_ConnectTimeout(Options.ConnectTimeout) + , m_Timeout(Options.Timeout) { - for (const auto& Url : Urls) + for (const auto& Url : Options.Urls) { m_Endpoints.push_back({.Url = Url}); } @@ -461,7 +465,7 @@ namespace detail { { m_ServiceUrl = Ep.Url; m_DisplayName = "ZEN - {}"_format(m_ServiceUrl); - m_Client = new ZenStructuredCacheClient(m_ServiceUrl); + m_Client = new ZenStructuredCacheClient({.Url = m_ServiceUrl, .ConnectTimeout = m_ConnectTimeout, .Timeout = m_Timeout}); m_HealthOk = true; return {.Ok = true}; @@ -486,7 +490,8 @@ namespace detail { { m_ServiceUrl = Ep.Url; m_DisplayName = "ZEN - {}"_format(m_ServiceUrl); - m_Client = new ZenStructuredCacheClient(m_ServiceUrl); + m_Client = + new ZenStructuredCacheClient({.Url = m_ServiceUrl, .ConnectTimeout = m_ConnectTimeout, .Timeout = m_Timeout}); m_HealthOk = true; return {.Ok = true}; @@ -825,7 +830,7 @@ namespace detail { { for (ZenEndpoint& Ep : m_Endpoints) { - ZenStructuredCacheClient Client(Ep.Url); + ZenStructuredCacheClient Client({.Url = Ep.Url, .ConnectTimeout = std::chrono::milliseconds(1000)}); ZenStructuredCacheSession Session(Client); const int32_t SampleCount = 2; @@ -858,6 +863,8 @@ namespace detail { std::string m_ServiceUrl; std::vector m_Endpoints; std::string m_DisplayName; + std::chrono::milliseconds m_ConnectTimeout; + std::chrono::milliseconds m_Timeout; RefPtr m_Client; UpstreamEndpointStats m_Stats; std::atomic_bool m_HealthOk{false}; @@ -1347,9 +1354,9 @@ MakeJupiterUpstreamEndpoint(const CloudCacheClientOptions& Options) } std::unique_ptr -MakeZenUpstreamEndpoint(std::span Urls) +MakeZenUpstreamEndpoint(const ZenClientOptions& Options) { - return std::make_unique(Urls); + return std::make_unique(Options); } } // namespace zen -- cgit v1.2.3