aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/transports/dlltransport.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/transports/dlltransport.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/transports/dlltransport.cpp')
-rw-r--r--src/zenhttp/transports/dlltransport.cpp115
1 files changed, 54 insertions, 61 deletions
diff --git a/src/zenhttp/transports/dlltransport.cpp b/src/zenhttp/transports/dlltransport.cpp
index 04fb6caaa..5c0084e44 100644
--- a/src/zenhttp/transports/dlltransport.cpp
+++ b/src/zenhttp/transports/dlltransport.cpp
@@ -86,28 +86,29 @@ struct LoadedDll
Ref<TransportPlugin> Plugin;
};
-class DllTransportPluginImpl
+class DllTransportPluginImpl : public DllTransportPlugin, RefCounted
{
public:
- DllTransportPluginImpl(uint16_t BasePort, unsigned int ThreadCount);
+ DllTransportPluginImpl();
~DllTransportPluginImpl();
- uint16_t Start(TransportServer* ServerInterface);
- void Stop();
- bool IsAvailable();
- void LoadDll(std::string_view Name);
+ virtual uint32_t AddRef() const override;
+ virtual uint32_t Release() const override;
+ virtual void Configure(const char* OptionTag, const char* OptionValue) override;
+ virtual void Initialize(TransportServer* ServerInterface) override;
+ virtual void Shutdown() override;
+ virtual bool IsAvailable() override;
+
+ virtual void LoadDll(std::string_view Name) override;
+ virtual void ConfigureDll(std::string_view Name, const char* OptionTag, const char* OptionValue) override;
private:
TransportServer* m_ServerInterface = nullptr;
RwLock m_Lock;
std::vector<LoadedDll> m_Transports;
- uint16_t m_BasePort = 0;
- int m_ThreadCount = 0;
};
-DllTransportPluginImpl::DllTransportPluginImpl(uint16_t BasePort, unsigned int ThreadCount)
-: m_BasePort(BasePort)
-, m_ThreadCount(ThreadCount != 0 ? ThreadCount : Max(std::thread::hardware_concurrency(), 8u))
+DllTransportPluginImpl::DllTransportPluginImpl()
{
}
@@ -115,8 +116,28 @@ DllTransportPluginImpl::~DllTransportPluginImpl()
{
}
-uint16_t
-DllTransportPluginImpl::Start(TransportServer* ServerIface)
+uint32_t
+DllTransportPluginImpl::AddRef() const
+{
+ return RefCounted::AddRef();
+}
+
+uint32_t
+DllTransportPluginImpl::Release() const
+{
+ return RefCounted::Release();
+}
+
+void
+DllTransportPluginImpl::Configure(const char* OptionTag, const char* OptionValue)
+{
+ // No configuration options
+
+ ZEN_UNUSED(OptionTag, OptionValue);
+}
+
+void
+DllTransportPluginImpl::Initialize(TransportServer* ServerIface)
{
m_ServerInterface = ServerIface;
@@ -133,12 +154,10 @@ DllTransportPluginImpl::Start(TransportServer* ServerIface)
// TODO: report
}
}
-
- return m_BasePort;
}
void
-DllTransportPluginImpl::Stop()
+DllTransportPluginImpl::Shutdown()
{
RwLock::ExclusiveLockScope _(m_Lock);
@@ -162,8 +181,24 @@ DllTransportPluginImpl::IsAvailable()
}
void
+DllTransportPluginImpl::ConfigureDll(std::string_view Name, const char* OptionTag, const char* OptionValue)
+{
+ RwLock::ExclusiveLockScope _(m_Lock);
+
+ for (auto& Transport : m_Transports)
+ {
+ if (Transport.Name == Name)
+ {
+ Transport.Plugin->Configure(OptionTag, OptionValue);
+ }
+ }
+}
+
+void
DllTransportPluginImpl::LoadDll(std::string_view Name)
{
+ RwLock::ExclusiveLockScope _(m_Lock);
+
ExtendableStringBuilder<128> DllPath;
DllPath << Name << ".dll";
HMODULE DllHandle = LoadLibraryA(DllPath.c_str());
@@ -197,52 +232,10 @@ DllTransportPluginImpl::LoadDll(std::string_view Name)
m_Transports.emplace_back(std::move(NewDll));
}
-//////////////////////////////////////////////////////////////////////////
-
-DllTransportPlugin::DllTransportPlugin(uint16_t BasePort, unsigned int ThreadCount)
-: m_Impl(std::make_unique<DllTransportPluginImpl>(BasePort, ThreadCount))
-{
-}
-
-DllTransportPlugin::~DllTransportPlugin()
-{
- m_Impl->Stop();
-}
-
-uint32_t
-DllTransportPlugin::AddRef() const
-{
- return RefCounted::AddRef();
-}
-
-uint32_t
-DllTransportPlugin::Release() const
-{
- return RefCounted::Release();
-}
-
-void
-DllTransportPlugin::Initialize(TransportServer* ServerInterface)
-{
- m_Impl->Start(ServerInterface);
-}
-
-void
-DllTransportPlugin::Shutdown()
-{
- m_Impl->Stop();
-}
-
-bool
-DllTransportPlugin::IsAvailable()
-{
- return m_Impl->IsAvailable();
-}
-
-void
-DllTransportPlugin::LoadDll(std::string_view Name)
+DllTransportPlugin*
+CreateDllTransportPlugin()
{
- return m_Impl->LoadDll(Name);
+ return new DllTransportPluginImpl;
}
} // namespace zen