aboutsummaryrefslogtreecommitdiff
path: root/zenserver
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2022-02-21 15:00:02 +0100
committerPer Larsson <[email protected]>2022-02-21 15:00:02 +0100
commit41782efc63d7f88525596d6724a1bb86d6fdcfa4 (patch)
tree80567b8cc256c361abb8f81b53680f2fa6ec6fcc /zenserver
parentRefactored websocket message. (diff)
downloadzen-41782efc63d7f88525596d6724a1bb86d6fdcfa4.tar.xz
zen-41782efc63d7f88525596d6724a1bb86d6fdcfa4.zip
Added option to enable websockets.
Diffstat (limited to 'zenserver')
-rw-r--r--zenserver/config.cpp14
-rw-r--r--zenserver/config.h24
-rw-r--r--zenserver/zenserver.cpp20
3 files changed, 44 insertions, 14 deletions
diff --git a/zenserver/config.cpp b/zenserver/config.cpp
index cb6d5ea6d..bcacc16c0 100644
--- a/zenserver/config.cpp
+++ b/zenserver/config.cpp
@@ -193,6 +193,20 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
cxxopts::value<int>(ServerOptions.BasePort)->default_value("1337"),
"<port number>");
+ options.add_option("network",
+ "",
+ "websocket-port",
+ "Websocket server port",
+ cxxopts::value<int>(ServerOptions.WebSocketPort)->default_value("0"),
+ "<port number>");
+
+ options.add_option("network",
+ "",
+ "websocket-threads",
+ "Number of websocket I/O thread(s) (0 == hardware concurrency)",
+ cxxopts::value<int>(ServerOptions.WebSocketThreads)->default_value("0"),
+ "");
+
#if ZEN_ENABLE_MESH
options.add_option("network",
"m",
diff --git a/zenserver/config.h b/zenserver/config.h
index 69e65498c..fd569bdb1 100644
--- a/zenserver/config.h
+++ b/zenserver/config.h
@@ -87,17 +87,19 @@ struct ZenServerOptions
{
ZenUpstreamCacheConfig UpstreamCacheConfig;
ZenGcConfig GcConfig;
- std::filesystem::path DataDir; // Root directory for state (used for testing)
- std::filesystem::path ContentDir; // Root directory for serving frontend content (experimental)
- std::filesystem::path AbsLogFile; // Absolute path to main log file
- std::filesystem::path ConfigFile; // Path to Lua config file
- std::string ChildId; // Id assigned by parent process (used for lifetime management)
- std::string LogId; // Id for tagging log output
- std::string HttpServerClass; // Choice of HTTP server implementation
- std::string EncryptionKey; // 256 bit AES encryption key
- std::string EncryptionIV; // 128 bit AES initialization vector
- int BasePort = 1337; // Service listen port (used for both UDP and TCP)
- int OwnerPid = 0; // Parent process id (zero for standalone)
+ std::filesystem::path DataDir; // Root directory for state (used for testing)
+ std::filesystem::path ContentDir; // Root directory for serving frontend content (experimental)
+ std::filesystem::path AbsLogFile; // Absolute path to main log file
+ std::filesystem::path ConfigFile; // Path to Lua config file
+ std::string ChildId; // Id assigned by parent process (used for lifetime management)
+ std::string LogId; // Id for tagging log output
+ std::string HttpServerClass; // Choice of HTTP server implementation
+ std::string EncryptionKey; // 256 bit AES encryption key
+ std::string EncryptionIV; // 128 bit AES initialization vector
+ int BasePort = 1337; // Service listen port (used for both UDP and TCP)
+ int OwnerPid = 0; // Parent process id (zero for standalone)
+ int WebSocketPort = 0; // Web socket port (Zero = disabled)
+ int WebSocketThreads = 0;
bool InstallService = false; // Flag used to initiate service install (temporary)
bool UninstallService = false; // Flag used to initiate service uninstall (temporary)
bool IsDebug = false;
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index 08abfdecd..78a62e202 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -205,7 +205,14 @@ public:
m_Http = zen::CreateHttpServer(ServerOptions.HttpServerClass);
int EffectiveBasePort = m_Http->Initialize(ServerOptions.BasePort);
- m_WebSocket = zen::WebSocketServer::Create();
+ 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
{
@@ -305,9 +312,13 @@ public:
m_Http->RegisterService(m_TestService); // NOTE: this is intentionally not limited to test mode as it's useful for diagnostics
m_Http->RegisterService(m_TestingService);
- m_WebSocket->RegisterService(m_TestingService);
m_Http->RegisterService(m_AdminService);
+ if (m_WebSocket)
+ {
+ m_WebSocket->RegisterService(m_TestingService);
+ }
+
if (m_HttpProjectService)
{
m_Http->RegisterService(*m_HttpProjectService);
@@ -400,7 +411,10 @@ public:
OnReady();
- m_WebSocket->Run({.Port = 8848});
+ if (m_WebSocket)
+ {
+ m_WebSocket->Run();
+ }
m_Http->Run(IsInteractiveMode);