// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include #ifndef ZEN_WITH_HTTPSYS # if ZEN_PLATFORM_WINDOWS # define ZEN_WITH_HTTPSYS 1 # else # define ZEN_WITH_HTTPSYS 0 # endif #endif #if ZEN_WITH_HTTPSYS # define _WINSOCKAPI_ # include # include "iothreadpool.h" # include # include 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(unsigned 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 Cleanup(); void StartServer(); void OnHandlingRequest(); void IssueNewRequestMaybe(); inline bool IsOk() const { return m_IsOk; } void RegisterService(const char* Endpoint, HttpService& Service); void UnregisterService(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}; std::atomic m_IsShuttingDown{0}; int32_t m_MinPendingRequests = 16; int32_t m_MaxPendingRequests = 128; Event m_ShutdownEvent; }; } // namespace zen #endif