diff options
| author | Stefan Boberg <[email protected]> | 2021-05-26 19:53:54 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-26 19:53:54 +0200 |
| commit | 61ac355b77782526b94f8aa5f923cca06927d34a (patch) | |
| tree | 0bbeb182cc0265bad8d7a47a9f61bd50519d9af7 /zenserver/zenserver.cpp | |
| parent | Fixed up project.basic test to account for changes made to the project store ... (diff) | |
| download | zen-61ac355b77782526b94f8aa5f923cca06927d34a.tar.xz zen-61ac355b77782526b94f8aa5f923cca06927d34a.zip | |
Added EnableMesh setting, fixed lifetime management
restructured handling of parent process lifetime management and added logic so that the parent process tracking works even when nothing else is using the asio I/O context
Diffstat (limited to 'zenserver/zenserver.cpp')
| -rw-r--r-- | zenserver/zenserver.cpp | 47 |
1 files changed, 37 insertions, 10 deletions
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) { |