aboutsummaryrefslogtreecommitdiff
path: root/zenhttp/httpuws.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-10 19:48:26 +0200
committerStefan Boberg <[email protected]>2021-09-10 19:48:26 +0200
commite04a36f90f9e326a2e77237ba4e18399a8f60172 (patch)
tree15c2126f15ad86bf3f9d1b00a5322deb1c6a125c /zenhttp/httpuws.cpp
parentclang-format (diff)
downloadzen-e04a36f90f9e326a2e77237ba4e18399a8f60172.tar.xz
zen-e04a36f90f9e326a2e77237ba4e18399a8f60172.zip
Added beginnings of a uWS http front-end
Diffstat (limited to 'zenhttp/httpuws.cpp')
-rw-r--r--zenhttp/httpuws.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/zenhttp/httpuws.cpp b/zenhttp/httpuws.cpp
new file mode 100644
index 000000000..a35caa120
--- /dev/null
+++ b/zenhttp/httpuws.cpp
@@ -0,0 +1,81 @@
+#include "httpuws.h"
+
+#pragma warning(push)
+#pragma warning(disable : 4267 4706)
+#include <uwebsockets/App.h>
+#pragma warning(pop)
+
+#include <conio.h>
+#include <zencore/logging.h>
+
+#if ZEN_PLATFORM_WINDOWS
+# pragma comment(lib, "Iphlpapi.lib")
+#endif
+
+namespace zen {
+
+HttpUwsServer::HttpUwsServer()
+{
+}
+
+HttpUwsServer::~HttpUwsServer()
+{
+}
+
+void
+HttpUwsServer::RegisterService(HttpService& Service)
+{
+ ZEN_UNUSED(Service);
+}
+
+void
+HttpUwsServer::Initialize(int BasePort)
+{
+ m_BasePort = BasePort;
+}
+
+void
+HttpUwsServer::Run(bool TestMode)
+{
+ if (TestMode == false)
+ {
+ zen::logging::ConsoleLog().info("Zen Server running (null HTTP). Press ESC or Q to quit");
+ }
+
+ ::uWS::App().get("/*", [](uWS::HttpResponse<false>* res, uWS::HttpRequest* req) {
+ res->end("Hello world!");
+ ZEN_UNUSED(req);
+ }).listen(m_BasePort, [](auto* listen_socket) {
+ ZEN_UNUSED(listen_socket);
+ }).run();
+
+ do
+ {
+ int WaitTimeout = -1;
+
+ if (!TestMode)
+ {
+ WaitTimeout = 1000;
+ }
+
+ if (!TestMode && _kbhit() != 0)
+ {
+ char c = (char)_getch();
+
+ if (c == 27 || c == 'Q' || c == 'q')
+ {
+ RequestApplicationExit(0);
+ }
+ }
+
+ m_ShutdownEvent.Wait(WaitTimeout);
+ } while (!IsApplicationExitRequested());
+}
+
+void
+HttpUwsServer::RequestExit()
+{
+ m_ShutdownEvent.Set();
+}
+
+} // namespace zen