From 4dfbf3338252459ed75758496245683301bc5ae6 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 22 Sep 2025 15:41:20 -0400 Subject: [PATCH] common Daemon.GetGracefulShutdownInterval --- Win32/DaemonWin32.cpp | 7 ++++++- Win32/Win32App.cpp | 2 +- daemon/Daemon.h | 17 ++++++++++++++--- daemon/HTTPServer.cpp | 10 +--------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Win32/DaemonWin32.cpp b/Win32/DaemonWin32.cpp index 48f65c27..6fde9199 100644 --- a/Win32/DaemonWin32.cpp +++ b/Win32/DaemonWin32.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2023, The PurpleI2P Project +* Copyright (c) 2013-2025, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -98,6 +98,11 @@ namespace util } #endif } + + int DaemonWin32::GetGracefulShutdownInterval () const + { + return i2p::win32::GetGracefulShutdownRemainingTime (); + } } } #endif //_WIN32 diff --git a/Win32/Win32App.cpp b/Win32/Win32App.cpp index 2afc1651..ae878652 100644 --- a/Win32/Win32App.cpp +++ b/Win32/Win32App.cpp @@ -195,7 +195,7 @@ namespace win32 s << "; "; s << "Success Rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate() << "%\n"; s << "Uptime: "; ShowUptime(s, i2p::context.GetUptime ()); - auto gracefulTimeLeft = GetGracefulShutdownRemainingTime (); + auto gracefulTimeLeft = Daemon.GetGracefulShutdownInterval (); if (gracefulTimeLeft > 0) { s << "Graceful shutdown, time left: "; ShowUptime(s, gracefulTimeLeft); diff --git a/daemon/Daemon.h b/daemon/Daemon.h index 4634414b..1e9aeb76 100644 --- a/daemon/Daemon.h +++ b/daemon/Daemon.h @@ -29,7 +29,10 @@ namespace util virtual void run () {}; virtual void setDataDir (std::string path); - + virtual int GetGracefulShutdownInterval () const { return 0; }; + + public: + bool isDaemon; bool running; @@ -74,15 +77,21 @@ namespace util static DaemonWin32 instance; return instance; } - + bool init(int argc, char* argv[]); bool start(); bool stop(); void run (); + int GetGracefulShutdownInterval () const; + + public: + bool isGraceful; - DaemonWin32 ():isGraceful(false) {} + private: + + DaemonWin32 (): isGraceful(false) {} }; #elif (defined(ANDROID) && !defined(ANDROID_BINARY)) #define Daemon i2p::util::DaemonAndroid::Instance() @@ -112,6 +121,8 @@ namespace util bool stop(); void run (); + int GetGracefulShutdownInterval () const { return gracefulShutdownInterval; }; + private: std::string pidfile; diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index 46041457..92711cee 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -300,21 +300,13 @@ namespace http { ShowNetworkStatus (s, i2p::context.GetStatusV6 (), i2p::context.GetTestingV6(), i2p::context.GetErrorV6 ()); s << "
\r\n"; } -#if ((!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID)) || defined(ANDROID_BINARY)) - if (auto remains = Daemon.gracefulShutdownInterval) { - s << "" << tr("Stopping in") << ": "; - ShowUptime(s, remains); - s << "
\r\n"; - } -#elif defined(WIN32_APP) - auto remains = i2p::win32::GetGracefulShutdownRemainingTime (); + auto remains = Daemon.GetGracefulShutdownInterval (); if (remains > 0) { s << "" << tr("Stopping in") << ": "; ShowUptime(s, remains); s << "
\r\n"; } -#endif auto family = i2p::context.GetFamily (); if (family.length () > 0) s << ""<< tr("Family") << ": " << family << "
\r\n";