aboutsummaryrefslogtreecommitdiff
path: root/zencore/httpsys.h
blob: 8a7b372ddf0c532cc28c638affd3963a30d340f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include <zencore/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
{
	friend class HttpSysTransaction;

public:
	HttpSysServer(WinIoThreadPool& InThreadPool);
	~HttpSysServer();

	void Initialize(const wchar_t* UrlPath);
	void Run(bool TestMode);

	void RequestExit() { m_ShutdownEvent.Set(); }

	void StartServer();
	void StopServer();

	void OnHandlingRequest();
	void IssueNewRequestMaybe();

	inline bool IsOk() const { return m_IsOk; }

	void AddEndpoint(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 = 4;
	int32_t				   m_MaxPendingRequests = 32;
	Event				   m_ShutdownEvent;
};

}