aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/httpasio.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-10-11 10:43:11 +0200
committerGitHub <[email protected]>2023-10-11 10:43:11 +0200
commitb124b83b31f368231fa417213e9ecf7df69b2d33 (patch)
tree6674550ae05d08d474d629d6790ecdb1e1782fda /src/zenhttp/httpasio.cpp
parentupdated plugin API class names (#462) (diff)
downloadzen-b124b83b31f368231fa417213e9ecf7df69b2d33.tar.xz
zen-b124b83b31f368231fa417213e9ecf7df69b2d33.zip
hide HttpAsioServer interface behind factory function (#463)
Diffstat (limited to 'src/zenhttp/httpasio.cpp')
-rw-r--r--src/zenhttp/httpasio.cpp27
1 files changed, 27 insertions, 0 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