diff options
| author | zousar <[email protected]> | 2022-01-27 01:01:05 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-01-27 09:01:05 +0100 |
| commit | cf38d96543b2086a863ef4823ee769ec45cc45a4 (patch) | |
| tree | 1c5c56053f43271398d9f9a469383f29df76c570 /zenutil/zenserverprocess.cpp | |
| parent | Implement SkipData,QueryLocal,StoreLocal for HandleRpcGetCacheRecords (#41) (diff) | |
| download | zen-cf38d96543b2086a863ef4823ee769ec45cc45a4.tar.xz zen-cf38d96543b2086a863ef4823ee769ec45cc45a4.zip | |
Handle HTTP port collisions when initializing server (#40)
Diffstat (limited to 'zenutil/zenserverprocess.cpp')
| -rw-r--r-- | zenutil/zenserverprocess.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp index fe6236d18..5bddc72bc 100644 --- a/zenutil/zenserverprocess.cpp +++ b/zenutil/zenserverprocess.cpp @@ -230,11 +230,11 @@ ZenServerState::InitializeReadOnly() } ZenServerState::ZenServerEntry* -ZenServerState::Lookup(int ListenPort) +ZenServerState::Lookup(int DesiredListenPort) { for (int i = 0; i < m_MaxEntryCount; ++i) { - if (m_Data[i].ListenPort == ListenPort) + if (m_Data[i].DesiredListenPort == DesiredListenPort) { return &m_Data[i]; } @@ -244,7 +244,7 @@ ZenServerState::Lookup(int ListenPort) } ZenServerState::ZenServerEntry* -ZenServerState::Register(int ListenPort) +ZenServerState::Register(int DesiredListenPort) { if (m_Data == nullptr) { @@ -259,17 +259,18 @@ ZenServerState::Register(int ListenPort) { ZenServerEntry& Entry = m_Data[i]; - if (Entry.ListenPort.load(std::memory_order_relaxed) == 0) + if (Entry.DesiredListenPort.load(std::memory_order_relaxed) == 0) { uint16_t Expected = 0; - if (Entry.ListenPort.compare_exchange_strong(Expected, uint16_t(ListenPort))) + if (Entry.DesiredListenPort.compare_exchange_strong(Expected, uint16_t(DesiredListenPort))) { // Successfully allocated entry m_OurEntry = &Entry; - Entry.Pid = Pid; - Entry.Flags = 0; + Entry.Pid = Pid; + Entry.EffectiveListenPort = 0; + Entry.Flags = 0; const Oid SesId = GetSessionId(); memcpy(Entry.SessionId, &SesId, sizeof SesId); @@ -296,11 +297,11 @@ ZenServerState::Sweep() { ZenServerEntry& Entry = m_Data[i]; - if (Entry.ListenPort) + if (Entry.DesiredListenPort) { if (IsProcessRunning(Entry.Pid) == false) { - ZEN_DEBUG("Sweep - pid {} not running, reclaiming entry (port {})", Entry.Pid, Entry.ListenPort); + ZEN_DEBUG("Sweep - pid {} not running, reclaiming entry (port {})", Entry.Pid, Entry.DesiredListenPort); Entry.Reset(); } @@ -320,7 +321,7 @@ ZenServerState::Snapshot(std::function<void(const ZenServerEntry&)>&& Callback) { ZenServerEntry& Entry = m_Data[i]; - if (Entry.ListenPort) + if (Entry.DesiredListenPort) { Callback(Entry); } @@ -330,9 +331,10 @@ ZenServerState::Snapshot(std::function<void(const ZenServerEntry&)>&& Callback) void ZenServerState::ZenServerEntry::Reset() { - Pid = 0; - ListenPort = 0; - Flags = 0; + Pid = 0; + DesiredListenPort = 0; + Flags = 0; + EffectiveListenPort = 0; } void |