From 7905d0d21af95c6016768d7a8a81dd9204b34d24 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 10 Oct 2023 13:30:07 +0200 Subject: experimental pluggable transport support (#436) this change adds a `--http=plugin` mode where we support pluggable transports. Currently this defaults to a barebones blocking winsock implementation but there is also support for dynamic loading of transport plugins, which will be further developed in the near future. --- src/zenhttp/httpserver.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/zenhttp/httpserver.cpp') diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp index a98a3c9bb..523befa72 100644 --- a/src/zenhttp/httpserver.cpp +++ b/src/zenhttp/httpserver.cpp @@ -6,6 +6,13 @@ #include "httpnull.h" #include "httpsys.h" +#include "zenhttp/httpplugin.h" + +#if ZEN_WITH_PLUGINS +# include "dlltransport.h" +# include "winsocktransport.h" +#endif + #include #include #include @@ -711,6 +718,7 @@ enum class HttpServerClass { kHttpAsio, kHttpSys, + kHttpPlugin, kHttpNull }; @@ -723,7 +731,7 @@ CreateHttpServer(const HttpServerConfig& Config) #if ZEN_WITH_HTTPSYS Class = HttpServerClass::kHttpSys; -#elif 1 +#else Class = HttpServerClass::kHttpAsio; #endif @@ -735,6 +743,10 @@ CreateHttpServer(const HttpServerConfig& Config) { Class = HttpServerClass::kHttpSys; } + else if (Config.ServerClass == "plugin"sv) + { + Class = HttpServerClass::kHttpPlugin; + } else if (Config.ServerClass == "null"sv) { Class = HttpServerClass::kHttpNull; @@ -747,6 +759,27 @@ CreateHttpServer(const HttpServerConfig& Config) ZEN_INFO("using asio HTTP server implementation"); return Ref(new HttpAsioServer(Config.ThreadCount)); +#if ZEN_WITH_PLUGINS + case HttpServerClass::kHttpPlugin: + { + ZEN_INFO("using plugin HTTP server implementation"); + Ref Server{new HttpPluginServer(Config.ThreadCount)}; + +# if 1 + Ref WinsockPlugin{CreateSocketTransportPlugin(1337, Config.ThreadCount)}; + Server->AddPlugin(WinsockPlugin); +# endif + +# if 0 + Ref DllPlugin{new DllTransportPlugin(1337, Config.ThreadCount)}; + DllPlugin->LoadDll("winsock"); + Server->AddPlugin(DllPlugin); +# endif + + return Server; + } +#endif + #if ZEN_WITH_HTTPSYS case HttpServerClass::kHttpSys: ZEN_INFO("using http.sys server implementation"); -- cgit v1.2.3