aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/zenserverprocess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenutil/zenserverprocess.cpp')
-rw-r--r--src/zenutil/zenserverprocess.cpp52
1 files changed, 48 insertions, 4 deletions
diff --git a/src/zenutil/zenserverprocess.cpp b/src/zenutil/zenserverprocess.cpp
index ead919cb9..d1a91b93f 100644
--- a/src/zenutil/zenserverprocess.cpp
+++ b/src/zenutil/zenserverprocess.cpp
@@ -476,7 +476,7 @@ ZenServerInstance::SignalShutdown()
void
ZenServerInstance::Shutdown()
{
- if (m_Process.IsValid())
+ if (m_Process.IsValid() && m_ShutdownOnDestroy)
{
if (m_Terminate)
{
@@ -494,7 +494,7 @@ ZenServerInstance::Shutdown()
}
void
-ZenServerInstance::SpawnServer(int BasePort, std::string_view AdditionalServerArgs)
+ZenServerInstance::SpawnServer(int BasePort, std::string_view AdditionalServerArgs, int WaitTimeoutMs)
{
ZEN_ASSERT(!m_Process.IsValid()); // Only spawn once
@@ -587,12 +587,55 @@ ZenServerInstance::SpawnServer(int BasePort, std::string_view AdditionalServerAr
ZEN_DEBUG("Server '{}' spawned OK", LogId);
- if (IsTest)
+ m_Process.Initialize(ChildPid);
+
+ if (IsTest == false)
{
- m_Process.Initialize(ChildPid);
+ DisableShutdownOnDestroy();
}
m_ReadyEvent = std::move(ChildEvent);
+
+ if (WaitTimeoutMs)
+ {
+ if (!WaitUntilReady(WaitTimeoutMs))
+ {
+ throw std::runtime_error(fmt::format("server start timeout after {}", NiceTimeSpanMs(WaitTimeoutMs)));
+ }
+
+ // Determine effective base port
+
+ ZenServerState State;
+ if (!State.InitializeReadOnly())
+ {
+ // TODO: return success/error code instead?
+ throw std::runtime_error("no zen state found");
+ }
+
+ const ZenServerState::ZenServerEntry* Entry = nullptr;
+
+ if (BasePort)
+ {
+ Entry = State.Lookup(BasePort);
+ }
+ else
+ {
+ State.Snapshot([&](const ZenServerState::ZenServerEntry& InEntry) {
+ if (InEntry.Pid == static_cast<uint32_t>(GetProcessId(ChildPid)))
+ {
+ Entry = &InEntry;
+ }
+ });
+ }
+
+ if (!Entry)
+ {
+ // TODO: return success/error code instead?
+ throw std::runtime_error("no server entry found");
+ }
+
+ m_BasePort = Entry->EffectiveListenPort;
+ }
}
void
@@ -634,6 +677,7 @@ ZenServerInstance::AttachToRunningServer(int BasePort)
m_Process.Initialize(Entry->Pid);
CreateShutdownEvent(Entry->EffectiveListenPort);
+ m_BasePort = Entry->EffectiveListenPort;
}
void