From 4c0e72df77ea663a92818de225735bc171074486 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Fri, 5 Dec 2025 13:40:08 +0100 Subject: implement --dedicated option on asio http server (#679) * implement --dedicated option on asio http server --- src/zenhttp/servers/httpsys.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/zenhttp/servers/httpsys.cpp') diff --git a/src/zenhttp/servers/httpsys.cpp b/src/zenhttp/servers/httpsys.cpp index 0be53ffee..9dbdd7167 100644 --- a/src/zenhttp/servers/httpsys.cpp +++ b/src/zenhttp/servers/httpsys.cpp @@ -939,7 +939,7 @@ HttpSysServer::HttpSysServer(const HttpSysConfig& InConfig) MaxThreadCount = MinThreadCount * 2; - if (m_InitialConfig.IsDedicatedServer) + if (m_InitialConfig.IsDedicatedServer && m_InitialConfig.ThreadCount == 0) { // In order to limit the potential impact of threads stuck // in locks we allow the thread pool to be oversubscribed @@ -1042,16 +1042,35 @@ HttpSysServer::InitializeServer(int BasePort) { Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0); - if ((Result == ERROR_SHARING_VIOLATION) && AllowPortProbing) + if ((Result == ERROR_SHARING_VIOLATION)) { - // Sharing violation implies the port is being used by another process - for (int PortOffset = 1; (Result == ERROR_SHARING_VIOLATION) && (PortOffset < 10); ++PortOffset) + ZEN_INFO("Desired port {} is in use (error: '{}'), retrying", EffectivePort, Result); + Sleep(500); + Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0); + + if (Result == ERROR_SHARING_VIOLATION) { - EffectivePort = BasePort + (PortOffset * 100); - WildcardUrlPath.Reset(); - WildcardUrlPath << u8"http://*:"sv << int64_t(EffectivePort) << u8"/"sv; + if (AllowPortProbing) + { + // Sharing violation implies the port is being used by another process + for (int PortOffset = 1; (Result == ERROR_SHARING_VIOLATION) && (PortOffset < 10); ++PortOffset) + { + EffectivePort = BasePort + (PortOffset * 100); + WildcardUrlPath.Reset(); + WildcardUrlPath << u8"http://*:"sv << int64_t(EffectivePort) << u8"/"sv; - Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0); + Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0); + } + } + else + { + for (uint32_t Retries = 0; (Result == ERROR_SHARING_VIOLATION) && (Retries < 3); Retries++) + { + ZEN_INFO("Desired port {} is in use (error: '{}'), retrying", EffectivePort, Result); + Sleep(500); + Result = HttpAddUrlToUrlGroup(m_HttpUrlGroupId, WildcardUrlPath.c_str(), HTTP_URL_CONTEXT(0), 0); + } + } } } } -- cgit v1.2.3