aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/httpserver.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-10-13 14:46:49 +0200
committerGitHub <[email protected]>2023-10-13 14:46:49 +0200
commitc3fad0e98576ff5dee3ee63725459d46e201fa34 (patch)
tree91455786fac76ffb6a83ff24620329780ce08545 /src/zenhttp/httpserver.cpp
parentimproved http.sys initialization diagnostics and amended logic for dedicated ... (diff)
downloadzen-c3fad0e98576ff5dee3ee63725459d46e201fa34.tar.xz
zen-c3fad0e98576ff5dee3ee63725459d46e201fa34.zip
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
Diffstat (limited to 'src/zenhttp/httpserver.cpp')
-rw-r--r--src/zenhttp/httpserver.cpp97
1 files changed, 63 insertions, 34 deletions
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 <zenhttp/httpserver.h>
#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<HttpServer>
-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<HttpMultiServer> 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<HttpPluginServer> Server{new HttpPluginServer(Config.ThreadCount)};
+ Ref<HttpPluginServer> Server{CreateHttpPluginServer()};
-# if 1
- Ref<TransportPlugin> WinsockPlugin{CreateSocketTransportPlugin(8558, Config.ThreadCount)};
+ // This is hardcoded for now, but should be configurable in the future
+
+# if 0
+ Ref<TransportPlugin> WinsockPlugin{CreateSocketTransportPlugin()};
+ WinsockPlugin->Configure("port", "8055");
Server->AddPlugin(WinsockPlugin);
# endif
# if 0
- Ref<TransportPlugin> AsioPlugin{CreateAsioTransportPlugin(8558, Config.ThreadCount)};
+ Ref<TransportPlugin> AsioPlugin{CreateAsioTransportPlugin()};
+ AsioPlugin->Configure("port", "8055");
Server->AddPlugin(AsioPlugin);
# endif
-# if 0
- Ref<DllTransportPlugin> DllPlugin{new DllTransportPlugin(8558, Config.ThreadCount)};
+# if 1
+ Ref<DllTransportPlugin> DllPlugin{CreateDllTransportPlugin()};
DllPlugin->LoadDll("winsock");
+ DllPlugin->ConfigureDll("winsock", "port", "8055");
Server->AddPlugin(DllPlugin);
# endif
@@ -801,6 +793,43 @@ CreateHttpServer(const HttpServerConfig& Config)
}
}
+Ref<HttpServer>
+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