diff options
Diffstat (limited to 'src/zenhttp/httpsys.h')
| -rw-r--r-- | src/zenhttp/httpsys.h | 87 |
1 files changed, 7 insertions, 80 deletions
diff --git a/src/zenhttp/httpsys.h b/src/zenhttp/httpsys.h index 65239bae7..1553d56ef 100644 --- a/src/zenhttp/httpsys.h +++ b/src/zenhttp/httpsys.h @@ -12,89 +12,16 @@ # endif #endif -#if ZEN_WITH_HTTPSYS -# define _WINSOCKAPI_ -# include <zencore/windows.h> -# include <zencore/workthreadpool.h> -# include "iothreadpool.h" - -# include <http.h> - -namespace spdlog { -class logger; -} - namespace zen { -/** - * @brief Windows implementation of HTTP server based on http.sys - * - * This requires elevation to function - */ -class HttpSysServer : public HttpServer +struct HttpSysConfig { - friend class HttpSysTransaction; - -public: - struct Config - { - unsigned int ThreadCount = 0; - unsigned int AsyncWorkThreadCount = 0; - bool IsAsyncResponseEnabled = true; - bool IsRequestLoggingEnabled = false; - }; - explicit HttpSysServer(const Config& Config); - ~HttpSysServer(); - - // HttpServer interface implementation - - virtual int Initialize(int BasePort) override; - virtual void Run(bool TestMode) override; - virtual void RequestExit() override; - virtual void RegisterService(HttpService& Service) override; - virtual void Close() override; - - WorkerThreadPool& WorkPool(); - - inline bool IsOk() const { return m_IsOk; } - inline bool IsAsyncResponseEnabled() const { return m_IsAsyncResponseEnabled; } - -private: - int InitializeServer(int BasePort); - void Cleanup(); - - void StartServer(); - void OnHandlingNewRequest(); - void IssueNewRequestMaybe(); - - void RegisterService(const char* Endpoint, HttpService& Service); - void UnregisterService(const char* Endpoint, HttpService& Service); - -private: - spdlog::logger& m_Log; - spdlog::logger& m_RequestLog; - spdlog::logger& Log() { return m_Log; } - - bool m_IsOk = false; - bool m_IsHttpInitialized = false; - bool m_IsRequestLoggingEnabled = false; - bool m_IsAsyncResponseEnabled = true; - - WinIoThreadPool m_ThreadPool; - RwLock m_AsyncWorkPoolInitLock; - WorkerThreadPool* m_AsyncWorkPool = nullptr; - - std::vector<std::wstring> m_BaseUris; // eg: 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}; - std::atomic_int32_t m_IsShuttingDown{0}; - int32_t m_MinPendingRequests = 16; - int32_t m_MaxPendingRequests = 128; - Event m_ShutdownEvent; - const Config m_InitialConfig; + unsigned int ThreadCount = 0; + unsigned int AsyncWorkThreadCount = 0; + bool IsAsyncResponseEnabled = true; + bool IsRequestLoggingEnabled = false; }; +Ref<HttpServer> CreateHttpSysServer(HttpSysConfig Config); + } // namespace zen -#endif |