aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/transports/asiotransport.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/asiotransport.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/asiotransport.cpp')
-rw-r--r--src/zenhttp/transports/asiotransport.cpp38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/zenhttp/transports/asiotransport.cpp b/src/zenhttp/transports/asiotransport.cpp
index b8fef8f5f..ab053a748 100644
--- a/src/zenhttp/transports/asiotransport.cpp
+++ b/src/zenhttp/transports/asiotransport.cpp
@@ -31,18 +31,19 @@ struct AsioTransportAcceptor;
class AsioTransportPlugin : public TransportPlugin, RefCounted
{
public:
- AsioTransportPlugin(uint16_t BasePort, unsigned int ThreadCount);
+ AsioTransportPlugin();
~AsioTransportPlugin();
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;
private:
bool m_IsOk = true;
- uint16_t m_BasePort = 0;
+ uint16_t m_BasePort = 8558;
int m_ThreadCount = 0;
asio::io_service m_IoService;
@@ -349,9 +350,7 @@ AsioTransportConnection::OnResponseDataSent(const asio::error_code& Ec, std::siz
//////////////////////////////////////////////////////////////////////////
-AsioTransportPlugin::AsioTransportPlugin(uint16_t BasePort, unsigned int ThreadCount)
-: m_BasePort(BasePort)
-, m_ThreadCount(ThreadCount != 0 ? ThreadCount : Max(std::thread::hardware_concurrency(), 8u))
+AsioTransportPlugin::AsioTransportPlugin() : m_ThreadCount(Max(std::thread::hardware_concurrency(), 8u))
{
}
@@ -372,6 +371,31 @@ AsioTransportPlugin::Release() const
}
void
+AsioTransportPlugin::Configure(const char* OptionTag, const char* OptionValue)
+{
+ using namespace std::literals;
+
+ if (OptionTag == "port"sv)
+ {
+ if (auto PortNum = ParseInt<uint16_t>(OptionValue))
+ {
+ m_BasePort = *PortNum;
+ }
+ }
+ else if (OptionTag == "threads"sv)
+ {
+ if (auto ThreadCount = ParseInt<int>(OptionValue))
+ {
+ m_ThreadCount = *ThreadCount;
+ }
+ }
+ else
+ {
+ // Unknown configuration option
+ }
+}
+
+void
AsioTransportPlugin::Initialize(TransportServer* ServerInterface)
{
ZEN_ASSERT(m_ThreadCount > 0);
@@ -429,9 +453,9 @@ AsioTransportPlugin::IsAvailable()
}
TransportPlugin*
-CreateAsioTransportPlugin(uint16_t BasePort, unsigned int ThreadCount)
+CreateAsioTransportPlugin()
{
- return new AsioTransportPlugin(BasePort, ThreadCount);
+ return new AsioTransportPlugin();
}
} // namespace zen