aboutsummaryrefslogtreecommitdiff
path: root/zenserver
diff options
context:
space:
mode:
Diffstat (limited to 'zenserver')
-rw-r--r--zenserver/config.h13
-rw-r--r--zenserver/zenserver.cpp47
2 files changed, 44 insertions, 16 deletions
diff --git a/zenserver/config.h b/zenserver/config.h
index c96dc139a..fb866f134 100644
--- a/zenserver/config.h
+++ b/zenserver/config.h
@@ -9,12 +9,13 @@ struct ZenServerOptions
{
bool IsDebug = false;
bool IsTest = false;
- int BasePort = 1337; // Service listen port (used for both UDP and TCP)
- int OwnerPid = 0; // Parent process id (zero for standalone)
- std::string ChildId; // Id assigned by parent process (used for lifetime management)
- std::string LogId; // Id for tagging log output
- std::filesystem::path DataDir; // Root directory for state (used for testing)
- std::string FlockId; // Id for grouping test instances into sets
+ int BasePort = 1337; // Service listen port (used for both UDP and TCP)
+ int OwnerPid = 0; // Parent process id (zero for standalone)
+ std::string ChildId; // Id assigned by parent process (used for lifetime management)
+ std::string LogId; // Id for tagging log output
+ std::filesystem::path DataDir; // Root directory for state (used for testing)
+ std::string FlockId; // Id for grouping test instances into sets
+ bool EnableMesh = false; // Experimental p2p mesh discovery
};
void ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions);
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index e57a6142d..c0b0dddec 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -67,6 +67,15 @@ public:
if (ParentPid)
{
m_Process.Initialize(ParentPid);
+
+ if (!m_Process.IsValid())
+ {
+ spdlog::warn("Unable to initialize process handle for specified parent pid #{}", ParentPid);
+ }
+ else
+ {
+ spdlog::info("Using parent pid #{} to control process lifetime", ParentPid);
+ }
}
// Prototype config system, let's see how this pans out
@@ -138,10 +147,12 @@ public:
{
m_Http.AddEndpoint(*m_HttpLaunchService);
}
+ }
- // Experimental
- //
- // m_ZenMesh.Start(1337);
+ void StartMesh(int BasePort)
+ {
+ spdlog::info("initializing mesh discovery");
+ m_ZenMesh.Start(uint16_t(BasePort));
}
void Run()
@@ -181,10 +192,20 @@ public:
void SetTestMode(bool State) { m_TestMode = State; }
void SetDataRoot(std::filesystem::path Root) { m_DataRoot = Root; }
+ void EnsureIoRunner()
+ {
+ if (!m_IoRunner.joinable())
+ {
+ m_IoRunner = std::move(std::jthread{[this] { m_IoContext.run(); }});
+ }
+ }
+
void EnqueueTimer()
{
m_PidCheckTimer.expires_after(std::chrono::seconds(1));
m_PidCheckTimer.async_wait([this](const asio::error_code&) { CheckOwnerPid(); });
+
+ EnsureIoRunner();
}
void CheckOwnerPid()
@@ -204,6 +225,7 @@ public:
private:
bool m_TestMode = false;
std::filesystem::path m_DataRoot;
+ std::jthread m_IoRunner;
asio::io_context m_IoContext;
asio::steady_timer m_PidCheckTimer{m_IoContext};
zen::Process m_Process;
@@ -243,10 +265,15 @@ main(int argc, char* argv[])
std::unique_ptr<std::thread> ShutdownThread;
std::unique_ptr<zen::NamedEvent> ShutdownEvent;
- ZenServer Cache;
- Cache.SetDataRoot(GlobalOptions.DataDir);
- Cache.SetTestMode(GlobalOptions.IsTest);
- Cache.Initialize(GlobalOptions.BasePort, GlobalOptions.OwnerPid);
+ ZenServer Server;
+ Server.SetDataRoot(GlobalOptions.DataDir);
+ Server.SetTestMode(GlobalOptions.IsTest);
+ Server.Initialize(GlobalOptions.BasePort, GlobalOptions.OwnerPid);
+
+ if (GlobalOptions.EnableMesh)
+ {
+ Server.StartMesh(GlobalOptions.BasePort);
+ }
if (!GlobalOptions.ChildId.empty())
{
@@ -260,12 +287,12 @@ main(int argc, char* argv[])
ShutdownThread.reset(new std::thread{[&] {
ShutdownEvent->Wait();
spdlog::info("shutdown signal received");
- Cache.RequestExit(0);
+ Server.RequestExit(0);
}});
}
- Cache.Run();
- Cache.Cleanup();
+ Server.Run();
+ Server.Cleanup();
if (ShutdownEvent)
{