aboutsummaryrefslogtreecommitdiff
path: root/zenserver/zenserver.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2022-02-21 15:14:11 +0100
committerPer Larsson <[email protected]>2022-02-21 15:14:11 +0100
commitdb1c9605e3afbaf86f4231ba4eb7976d896f286b (patch)
tree54b451da4247c69575ff1a05ed006ecef3905c85 /zenserver/zenserver.cpp
parentIf open(O_CREAT) is used then a file mode must be given (diff)
parentRemoved optional offset for GetView. (diff)
downloadzen-db1c9605e3afbaf86f4231ba4eb7976d896f286b.tar.xz
zen-db1c9605e3afbaf86f4231ba4eb7976d896f286b.zip
Initial support for websockets.
Diffstat (limited to 'zenserver/zenserver.cpp')
-rw-r--r--zenserver/zenserver.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index ea0f52db2..78a62e202 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -15,6 +15,7 @@
#include <zencore/timer.h>
#include <zencore/trace.h>
#include <zenhttp/httpserver.h>
+#include <zenhttp/websocket.h>
#include <zenstore/basicfile.h>
#include <zenstore/cas.h>
#include <zenstore/cidstore.h>
@@ -204,6 +205,15 @@ public:
m_Http = zen::CreateHttpServer(ServerOptions.HttpServerClass);
int EffectiveBasePort = m_Http->Initialize(ServerOptions.BasePort);
+ if (ServerOptions.WebSocketPort != 0)
+ {
+ const uint32 ThreadCount =
+ ServerOptions.WebSocketThreads > 0 ? uint32_t(ServerOptions.WebSocketThreads) : std::thread::hardware_concurrency();
+
+ m_WebSocket = zen::WebSocketServer::Create(
+ {.Port = gsl::narrow<uint16_t>(ServerOptions.WebSocketPort), .ThreadCount = Max(ThreadCount, uint32_t(16))});
+ }
+
// Setup authentication manager
{
std::string EncryptionKey = ServerOptions.EncryptionKey;
@@ -304,6 +314,11 @@ public:
m_Http->RegisterService(m_TestingService);
m_Http->RegisterService(m_AdminService);
+ if (m_WebSocket)
+ {
+ m_WebSocket->RegisterService(m_TestingService);
+ }
+
if (m_HttpProjectService)
{
m_Http->RegisterService(*m_HttpProjectService);
@@ -396,6 +411,11 @@ public:
OnReady();
+ if (m_WebSocket)
+ {
+ m_WebSocket->Run();
+ }
+
m_Http->Run(IsInteractiveMode);
SetNewState(kShuttingDown);
@@ -559,6 +579,7 @@ private:
}
zen::Ref<zen::HttpServer> m_Http;
+ std::unique_ptr<zen::WebSocketServer> m_WebSocket;
std::unique_ptr<zen::AuthMgr> m_AuthMgr;
std::unique_ptr<zen::HttpAuthService> m_AuthService;
zen::HttpStatusService m_StatusService;