diff options
| author | Stefan Boberg <[email protected]> | 2023-10-11 10:43:11 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-11 10:43:11 +0200 |
| commit | b124b83b31f368231fa417213e9ecf7df69b2d33 (patch) | |
| tree | 6674550ae05d08d474d629d6790ecdb1e1782fda /src | |
| parent | updated plugin API class names (#462) (diff) | |
| download | zen-b124b83b31f368231fa417213e9ecf7df69b2d33.tar.xz zen-b124b83b31f368231fa417213e9ecf7df69b2d33.zip | |
hide HttpAsioServer interface behind factory function (#463)
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenhttp/httpasio.cpp | 27 | ||||
| -rw-r--r-- | src/zenhttp/httpasio.h | 24 | ||||
| -rw-r--r-- | src/zenhttp/httpserver.cpp | 2 |
3 files changed, 29 insertions, 24 deletions
diff --git a/src/zenhttp/httpasio.cpp b/src/zenhttp/httpasio.cpp index 562f75e3d..f23e0edb1 100644 --- a/src/zenhttp/httpasio.cpp +++ b/src/zenhttp/httpasio.cpp @@ -929,6 +929,27 @@ HttpAsioServerImpl::RouteRequest(std::string_view Url) ////////////////////////////////////////////////////////////////////////// namespace zen { + +class HttpAsioServer : public HttpServer +{ +public: + HttpAsioServer(unsigned int ThreadCount); + ~HttpAsioServer(); + + virtual void RegisterService(HttpService& Service) override; + virtual int Initialize(int BasePort) override; + virtual void Run(bool IsInteractiveSession) override; + virtual void RequestExit() override; + virtual void Close() override; + +private: + Event m_ShutdownEvent; + int m_BasePort = 0; + unsigned int m_ThreadCount = 0; + + std::unique_ptr<asio_http::HttpAsioServerImpl> m_Impl; +}; + HttpAsioServer::HttpAsioServer(unsigned int ThreadCount) : m_ThreadCount(ThreadCount != 0 ? ThreadCount : Max(std::thread::hardware_concurrency(), 8u)) , m_Impl(std::make_unique<asio_http::HttpAsioServerImpl>()) @@ -1021,4 +1042,10 @@ HttpAsioServer::RequestExit() m_ShutdownEvent.Set(); } +Ref<HttpServer> +CreateHttpAsioServer(unsigned int ThreadCount) +{ + return Ref<HttpServer>{new HttpAsioServer(ThreadCount)}; +} + } // namespace zen diff --git a/src/zenhttp/httpasio.h b/src/zenhttp/httpasio.h index e8d13a57f..57068f7c5 100644 --- a/src/zenhttp/httpasio.h +++ b/src/zenhttp/httpasio.h @@ -9,28 +9,6 @@ namespace zen { -namespace asio_http { - struct HttpAsioServerImpl; -} // namespace asio_http - -class HttpAsioServer : public HttpServer -{ -public: - HttpAsioServer(unsigned int ThreadCount); - ~HttpAsioServer(); - - virtual void RegisterService(HttpService& Service) override; - virtual int Initialize(int BasePort) override; - virtual void Run(bool IsInteractiveSession) override; - virtual void RequestExit() override; - virtual void Close() override; - -private: - Event m_ShutdownEvent; - int m_BasePort = 0; - unsigned int m_ThreadCount = 0; - - std::unique_ptr<asio_http::HttpAsioServerImpl> m_Impl; -}; +Ref<HttpServer> CreateHttpAsioServer(unsigned int ThreadCount); } // namespace zen diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp index 3713d2a44..f22438a58 100644 --- a/src/zenhttp/httpserver.cpp +++ b/src/zenhttp/httpserver.cpp @@ -757,7 +757,7 @@ CreateHttpServer(const HttpServerConfig& Config) default: case HttpServerClass::kHttpAsio: ZEN_INFO("using asio HTTP server implementation"); - return Ref<HttpServer>(new HttpAsioServer(Config.ThreadCount)); + return CreateHttpAsioServer(Config.ThreadCount); #if ZEN_WITH_PLUGINS case HttpServerClass::kHttpPlugin: |