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 /zenserver/zenserver.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 'zenserver/zenserver.cpp')
| -rw-r--r-- | zenserver/zenserver.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 6a42a4044..c6a27ec44 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -155,7 +155,7 @@ namespace utils { class ZenServer : public IHttpStatusProvider { public: - void Initialize(const ZenServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry) + int Initialize(const ZenServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry) { m_UseSentry = ServerOptions.NoSentry == false; m_ServerEntry = ServerEntry; @@ -200,8 +200,8 @@ public: // Ok so now we're configured, let's kick things off - m_Http = zen::CreateHttpServer(ServerOptions.HttpServerClass); - m_Http->Initialize(ServerOptions.BasePort); + m_Http = zen::CreateHttpServer(ServerOptions.HttpServerClass); + int EffectiveBasePort = m_Http->Initialize(ServerOptions.BasePort); m_AuthService = std::make_unique<zen::HttpAuthService>(); m_Http->RegisterService(*m_AuthService); @@ -262,7 +262,7 @@ public: #if ZEN_ENABLE_MESH if (ServerOptions.MeshEnabled) { - StartMesh(BasePort); + StartMesh(EffectiveBasePort); } else { @@ -309,6 +309,8 @@ public: .Enabled = ServerOptions.GcConfig.Enabled, }; m_GcScheduler.Initialize(GcConfig); + + return EffectiveBasePort; } void InitializeState(const ZenServerOptions& ServerOptions); @@ -889,6 +891,20 @@ ZenEntryPoint::Run() Entry->AddSponsorProcess(ServerOptions.OwnerPid); } + ZenServer Server; + Server.SetDataRoot(ServerOptions.DataDir); + Server.SetContentRoot(ServerOptions.ContentDir); + Server.SetTestMode(ServerOptions.IsTest); + Server.SetDedicatedMode(ServerOptions.IsDedicated); + int EffectiveBasePort = Server.Initialize(ServerOptions, Entry); + + Entry->EffectiveListenPort = uint16_t(EffectiveBasePort); + if (EffectiveBasePort != ServerOptions.BasePort) + { + ZEN_INFO(ZEN_APP_NAME " - relocated to base port {}", EffectiveBasePort); + ServerOptions.BasePort = EffectiveBasePort; + } + std::unique_ptr<std::thread> ShutdownThread; std::unique_ptr<zen::NamedEvent> ShutdownEvent; @@ -896,13 +912,6 @@ ZenEntryPoint::Run() ShutdownEventName << "Zen_" << ServerOptions.BasePort << "_Shutdown"; ShutdownEvent.reset(new zen::NamedEvent{ShutdownEventName}); - ZenServer Server; - Server.SetDataRoot(ServerOptions.DataDir); - Server.SetContentRoot(ServerOptions.ContentDir); - Server.SetTestMode(ServerOptions.IsTest); - Server.SetDedicatedMode(ServerOptions.IsDedicated); - Server.Initialize(ServerOptions, Entry); - // Monitor shutdown signals ShutdownThread.reset(new std::thread{[&] { |