aboutsummaryrefslogtreecommitdiff
path: root/zenutil/zenserverprocess.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-08-09 16:31:55 +0200
committerStefan Boberg <[email protected]>2021-08-09 16:31:55 +0200
commit5e12cf0c02b2e6687a246f7a5ae5fe2b6c62f079 (patch)
treea19c21ea012bd61921165635990a94802c8aabc3 /zenutil/zenserverprocess.cpp
parentBasic implementation of zen top/ps (currently identical but won't be) functio... (diff)
downloadzen-5e12cf0c02b2e6687a246f7a5ae5fe2b6c62f079.tar.xz
zen-5e12cf0c02b2e6687a246f7a5ae5fe2b6c62f079.zip
Added ZenServerInstance::AttachToRunningServer
Diffstat (limited to 'zenutil/zenserverprocess.cpp')
-rw-r--r--zenutil/zenserverprocess.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp
index 8427e612e..2a6b583de 100644
--- a/zenutil/zenserverprocess.cpp
+++ b/zenutil/zenserverprocess.cpp
@@ -491,6 +491,36 @@ ZenServerInstance::SpawnServer(int BasePort)
}
void
+ZenServerInstance::AttachToRunningServer(int BasePort)
+{
+ ZenServerState State;
+ if (!State.InitializeReadOnly())
+ {
+ // TODO: return success/error code instead?
+ throw std::exception("No zen state found");
+ }
+
+ const ZenServerState::ZenServerEntry* Entry = nullptr;
+
+ if (BasePort)
+ {
+ Entry = State.Lookup(BasePort);
+ }
+ else
+ {
+ State.Snapshot([&](const ZenServerState::ZenServerEntry& InEntry) { Entry = &InEntry; });
+ }
+
+ if (!Entry)
+ {
+ // TODO: return success/error code instead?
+ throw std::exception("No server found");
+ }
+
+ m_Process.Initialize(Entry->Pid);
+}
+
+void
ZenServerInstance::WaitUntilReady()
{
m_ReadyEvent.Wait();