/* */ #include "MultiUrlRequestInfo.h" #include #include #include #include "RequestGroupMan.h" #include "DownloadEngine.h" #include "LogFactory.h" #include "Logger.h" #include "RequestGroup.h" #include "prefs.h" #include "DownloadEngineFactory.h" #include "RecoverableException.h" #include "message.h" #include "util.h" #include "Option.h" #include "ConsoleStatCalc.h" #include "NullStatCalc.h" #include "CookieStorage.h" #include "File.h" #include "Netrc.h" #include "AuthConfigFactory.h" #include "SessionSerializer.h" #include "TimeA2.h" #include "fmt.h" #include "SocketCore.h" #include "NullOutputFile.h" #include "UriListParser.h" #include "SingletonHolder.h" #include "Notifier.h" #include "console.h" #ifdef ENABLE_WEBSOCKET # include "WebSocketSessionMan.h" #else // !ENABLE_WEBSOCKET # include "NullWebSocketSessionMan.h" #endif // !ENABLE_WEBSOCKET #ifdef ENABLE_SSL # include "TLSContext.h" #endif // ENABLE_SSL #ifdef ENABLE_ASYNC_DNS #include "AsyncNameResolver.h" #endif // ENABLE_ASYNC_DNS namespace aria2 { namespace global { extern volatile sig_atomic_t globalHaltRequested; } // namespace global namespace { #ifdef _WIN32 static const DWORD mainThread = GetCurrentThreadId(); #endif static void handler(int signal) { if( #ifdef SIGHUP signal == SIGHUP || #endif // SIGHUP signal == SIGTERM) { if(global::globalHaltRequested <= 2) { global::globalHaltRequested = 3; } #ifdef _WIN32 if (::GetCurrentThreadId() != mainThread) { // SIGTERM may arrive on another thread (via SetConsoleCtrlHandler), and // the process will be forcefully terminated as soon as that thread is // done. So better make sure it isn't done prematurely. ;) while (global::globalHaltRequested != 5) { ::Sleep(100); // Yeah, semi-busy waiting for now. } } #endif return; } // SIGINT if (global::globalHaltRequested == 0) { global::globalHaltRequested = 1; return; } if (global::globalHaltRequested == 2) { global::globalHaltRequested = 3; return; } } } // namespace namespace { std::unique_ptr getStatCalc(const std::shared_ptr