From c3fad0e98576ff5dee3ee63725459d46e201fa34 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 13 Oct 2023 14:46:49 +0200 Subject: support for multiple http servers (#473) * added support for having multiple http servers active in one session * added configuration API to pluggable transports * removed pimpl pattern from some pluggable transports implementations --- src/zenhttp/servers/httpmulti.cpp | 115 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/zenhttp/servers/httpmulti.cpp (limited to 'src/zenhttp/servers/httpmulti.cpp') diff --git a/src/zenhttp/servers/httpmulti.cpp b/src/zenhttp/servers/httpmulti.cpp new file mode 100644 index 000000000..6b7060d5e --- /dev/null +++ b/src/zenhttp/servers/httpmulti.cpp @@ -0,0 +1,115 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "httpmulti.h" + +#include + +#if ZEN_PLATFORM_WINDOWS +# include +#endif + +namespace zen { + +HttpMultiServer::HttpMultiServer() +{ +} + +HttpMultiServer::~HttpMultiServer() +{ +} + +void +HttpMultiServer::RegisterService(HttpService& Service) +{ + for (auto& Server : m_Servers) + { + Server->RegisterService(Service); + } +} + +int +HttpMultiServer::Initialize(int BasePort) +{ + ZEN_ASSERT(!m_IsInitialized); + + int EffectivePort = 0; + + for (auto& Server : m_Servers) + { + const int InitializeResult = Server->Initialize(BasePort); + + if (!EffectivePort) + { + EffectivePort = InitializeResult; + } + } + + m_IsInitialized = true; + + return EffectivePort; +} + +void +HttpMultiServer::Run(bool IsInteractiveSession) +{ + const bool TestMode = !IsInteractiveSession; + + int WaitTimeout = -1; + if (!TestMode) + { + WaitTimeout = 1000; + } + +#if ZEN_PLATFORM_WINDOWS + if (TestMode == false) + { + zen::logging::ConsoleLog().info("Zen Server running (multi server). Press ESC or Q to quit"); + } + + do + { + if (!TestMode && _kbhit() != 0) + { + char c = (char)_getch(); + + if (c == 27 || c == 'Q' || c == 'q') + { + RequestApplicationExit(0); + } + } + + m_ShutdownEvent.Wait(WaitTimeout); + } while (!IsApplicationExitRequested()); +#else + if (TestMode == false) + { + zen::logging::ConsoleLog().info("Zen Server running (null HTTP). Ctrl-C to quit"); + } + + do + { + m_ShutdownEvent.Wait(WaitTimeout); + } while (!IsApplicationExitRequested()); +#endif +} + +void +HttpMultiServer::RequestExit() +{ + m_ShutdownEvent.Set(); +} + +void +HttpMultiServer::Close() +{ +} + +void +HttpMultiServer::AddServer(Ref Server) +{ + ZEN_ASSERT(!m_IsInitialized); + + m_Servers.push_back(std::move(Server)); +} + +} // namespace zen -- cgit v1.2.3