aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zenutil/include/zenserverprocess.h13
-rw-r--r--zenutil/zenserverprocess.cpp30
2 files changed, 37 insertions, 6 deletions
diff --git a/zenutil/include/zenserverprocess.h b/zenutil/include/zenserverprocess.h
index 60ed273cb..d2101c8e8 100644
--- a/zenutil/include/zenserverprocess.h
+++ b/zenutil/include/zenserverprocess.h
@@ -49,6 +49,7 @@ struct ZenServerInstance
}
void SpawnServer(int BasePort = 0);
+ void AttachToRunningServer(int BasePort = 0);
private:
ZenServerEnvironment& m_Env;
@@ -87,12 +88,12 @@ public:
static_assert(sizeof(ZenServerEntry) == 32);
- void Initialize();
- [[nodiscard]] bool InitializeReadOnly();
- ZenServerEntry* Lookup(int ListenPort);
- ZenServerEntry* Register(int ListenPort);
- void Sweep();
- void Snapshot(std::function<void(const ZenServerEntry&)>&& Callback);
+ void Initialize();
+ [[nodiscard]] bool InitializeReadOnly();
+ [[nodiscard]] ZenServerEntry* Lookup(int ListenPort);
+ ZenServerEntry* Register(int ListenPort);
+ void Sweep();
+ void Snapshot(std::function<void(const ZenServerEntry&)>&& Callback);
private:
void* m_hMapFile = nullptr;
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();