aboutsummaryrefslogtreecommitdiff
path: root/zenhttp/httpsys.h
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-09 15:14:08 +0200
committerStefan Boberg <[email protected]>2021-09-09 15:14:08 +0200
commit6ec26c46d694a1d5291790a9c70bec25dce4b513 (patch)
tree4177d45f9703d11f00e495f0fde77f4445453d2d /zenhttp/httpsys.h
parentHttpServer::AddEndpoint -> HttpServer::RegisterService (diff)
downloadzen-6ec26c46d694a1d5291790a9c70bec25dce4b513.tar.xz
zen-6ec26c46d694a1d5291790a9c70bec25dce4b513.zip
Factored out http server related code into zenhttp module since it feels out of place in zencore
Diffstat (limited to 'zenhttp/httpsys.h')
-rw-r--r--zenhttp/httpsys.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/zenhttp/httpsys.h b/zenhttp/httpsys.h
new file mode 100644
index 000000000..ed4a6a182
--- /dev/null
+++ b/zenhttp/httpsys.h
@@ -0,0 +1,61 @@
+#pragma once
+
+#include <zenhttp/httpserver.h>
+
+#define _WINSOCKAPI_
+#include <zencore/windows.h>
+#include "iothreadpool.h"
+
+#include <atlbase.h>
+#include <http.h>
+
+namespace zen {
+
+/**
+ * @brief Windows implementation of HTTP server based on http.sys
+ *
+ * This requires elevation to function
+ */
+class HttpSysServer : public HttpServer
+{
+ friend class HttpSysTransaction;
+
+public:
+ explicit HttpSysServer(int ThreadCount);
+ ~HttpSysServer();
+
+ // HttpServer interface implementation
+
+ virtual void Initialize(int BasePort) override;
+ virtual void Run(bool TestMode) override;
+ virtual void RequestExit() override;
+ virtual void RegisterService(HttpService& Service) override;
+
+private:
+ void Initialize(const wchar_t* UrlPath);
+
+ void StartServer();
+ void OnHandlingRequest();
+ void IssueNewRequestMaybe();
+
+ inline bool IsOk() const { return m_IsOk; }
+
+ void RegisterService(const char* Endpoint, HttpService& Service);
+ void RemoveEndpoint(const char* Endpoint, HttpService& Service);
+
+private:
+ bool m_IsOk = false;
+ bool m_IsHttpInitialized = false;
+ WinIoThreadPool m_ThreadPool;
+
+ std::wstring m_BaseUri; // http://*:nnnn/
+ HTTP_SERVER_SESSION_ID m_HttpSessionId = 0;
+ HTTP_URL_GROUP_ID m_HttpUrlGroupId = 0;
+ HANDLE m_RequestQueueHandle = 0;
+ std::atomic_int32_t m_PendingRequests{0};
+ int32_t m_MinPendingRequests = 16;
+ int32_t m_MaxPendingRequests = 128;
+ Event m_ShutdownEvent;
+};
+
+} // namespace zen