aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/servers/httpnull.cpp
blob: 9bb7ef3bc9b3020f5b491c605a4c06fbae5e1280 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright Epic Games, Inc. All Rights Reserved.

#include "httpnull.h"

#include <zencore/logging.h>

#if ZEN_PLATFORM_WINDOWS
#	include <conio.h>
#endif

namespace zen {

HttpNullServer::HttpNullServer()
{
}

HttpNullServer::~HttpNullServer()
{
}

void
HttpNullServer::OnRegisterService(HttpService& Service)
{
	ZEN_UNUSED(Service);
}

void
HttpNullServer::OnSetHttpRequestFilter(IHttpRequestFilter* RequestFilter)
{
	ZEN_UNUSED(RequestFilter);
}

int
HttpNullServer::OnInitialize(int BasePort, std::filesystem::path DataDir)
{
	ZEN_UNUSED(DataDir);
	return BasePort;
}

void
HttpNullServer::OnRun(bool IsInteractiveSession)
{
	const int WaitTimeout		= 1000;
	bool	  ShutdownRequested = false;

#if ZEN_PLATFORM_WINDOWS
	if (IsInteractiveSession)
	{
		ZEN_CONSOLE("Zen Server running (null HTTP). Press ESC or Q to quit");
	}

	do
	{
		if (IsInteractiveSession && _kbhit() != 0)
		{
			char c = (char)_getch();

			if (c == 27 || c == 'Q' || c == 'q')
			{
				m_ShutdownEvent.Set();
				RequestApplicationExit(0);
			}
		}

		ShutdownRequested = m_ShutdownEvent.Wait(WaitTimeout);
	} while (!ShutdownRequested);
#else
	if (IsInteractiveSession)
	{
		ZEN_CONSOLE("Zen Server running (null HTTP). Ctrl-C to quit");
	}

	do
	{
		ShutdownRequested = m_ShutdownEvent.Wait(WaitTimeout);
	} while (!ShutdownRequested);
#endif
}

void
HttpNullServer::OnRequestExit()
{
	m_ShutdownEvent.Set();
}

void
HttpNullServer::OnClose()
{
}

}  // namespace zen