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/httpserver.cpp | 97 ++++++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 34 deletions(-) (limited to 'src/zenhttp/httpserver.cpp') diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp index cd62ea157..aa8bdddd6 100644 --- a/src/zenhttp/httpserver.cpp +++ b/src/zenhttp/httpserver.cpp @@ -3,6 +3,7 @@ #include #include "servers/httpasio.h" +#include "servers/httpmulti.h" #include "servers/httpnull.h" #include "servers/httpsys.h" #include "zenhttp/httpplugin.h" @@ -719,39 +720,13 @@ enum class HttpServerClass kHttpAsio, kHttpSys, kHttpPlugin, + kHttpMulti, kHttpNull }; Ref -CreateHttpServer(const HttpServerConfig& Config) +CreateHttpServerClass(HttpServerClass Class, const HttpServerConfig& Config) { - using namespace std::literals; - - HttpServerClass Class = HttpServerClass::kHttpNull; - -#if ZEN_WITH_HTTPSYS - Class = HttpServerClass::kHttpSys; -#else - Class = HttpServerClass::kHttpAsio; -#endif - - if (Config.ServerClass == "asio"sv) - { - Class = HttpServerClass::kHttpAsio; - } - else if (Config.ServerClass == "httpsys"sv) - { - Class = HttpServerClass::kHttpSys; - } - else if (Config.ServerClass == "plugin"sv) - { - Class = HttpServerClass::kHttpPlugin; - } - else if (Config.ServerClass == "null"sv) - { - Class = HttpServerClass::kHttpNull; - } - switch (Class) { default: @@ -759,25 +734,42 @@ CreateHttpServer(const HttpServerConfig& Config) ZEN_INFO("using asio HTTP server implementation"); return CreateHttpAsioServer(Config.ThreadCount); + case HttpServerClass::kHttpMulti: + { + ZEN_INFO("using multi HTTP server implementation"); + Ref Server{new HttpMultiServer()}; + + // This is hardcoded for now, but should be configurable in the future + Server->AddServer(CreateHttpServerClass(HttpServerClass::kHttpSys, Config)); + Server->AddServer(CreateHttpServerClass(HttpServerClass::kHttpPlugin, Config)); + + return Server; + } + #if ZEN_WITH_PLUGINS case HttpServerClass::kHttpPlugin: { ZEN_INFO("using plugin HTTP server implementation"); - Ref Server{new HttpPluginServer(Config.ThreadCount)}; + Ref Server{CreateHttpPluginServer()}; -# if 1 - Ref WinsockPlugin{CreateSocketTransportPlugin(8558, Config.ThreadCount)}; + // This is hardcoded for now, but should be configurable in the future + +# if 0 + Ref WinsockPlugin{CreateSocketTransportPlugin()}; + WinsockPlugin->Configure("port", "8055"); Server->AddPlugin(WinsockPlugin); # endif # if 0 - Ref AsioPlugin{CreateAsioTransportPlugin(8558, Config.ThreadCount)}; + Ref AsioPlugin{CreateAsioTransportPlugin()}; + AsioPlugin->Configure("port", "8055"); Server->AddPlugin(AsioPlugin); # endif -# if 0 - Ref DllPlugin{new DllTransportPlugin(8558, Config.ThreadCount)}; +# if 1 + Ref DllPlugin{CreateDllTransportPlugin()}; DllPlugin->LoadDll("winsock"); + DllPlugin->ConfigureDll("winsock", "port", "8055"); Server->AddPlugin(DllPlugin); # endif @@ -801,6 +793,43 @@ CreateHttpServer(const HttpServerConfig& Config) } } +Ref +CreateHttpServer(const HttpServerConfig& Config) +{ + using namespace std::literals; + + HttpServerClass Class = HttpServerClass::kHttpNull; + +#if ZEN_WITH_HTTPSYS + Class = HttpServerClass::kHttpSys; +#else + Class = HttpServerClass::kHttpAsio; +#endif + + if (Config.ServerClass == "asio"sv) + { + Class = HttpServerClass::kHttpAsio; + } + else if (Config.ServerClass == "httpsys"sv) + { + Class = HttpServerClass::kHttpSys; + } + else if (Config.ServerClass == "plugin"sv) + { + Class = HttpServerClass::kHttpPlugin; + } + else if (Config.ServerClass == "null"sv) + { + Class = HttpServerClass::kHttpNull; + } + else if (Config.ServerClass == "multi"sv) + { + Class = HttpServerClass::kHttpMulti; + } + + return CreateHttpServerClass(Class, Config); +} + ////////////////////////////////////////////////////////////////////////// bool -- cgit v1.2.3