diff options
| author | Nils Maier <maierman@web.de> | 2013-08-17 23:04:15 +0200 |
|---|---|---|
| committer | Nils Maier <maierman@web.de> | 2013-08-18 06:04:20 +0200 |
| commit | 79fcafc31f593b4217657d4cd10effc832d7b7c3 (patch) | |
| tree | 21942df817054ebbe9ac4e830a1c82aed878ae59 /src/MultiUrlRequestInfo.cc | |
| parent | 9e25335850c859ff54677807c7b8613414622917 (diff) | |
Win: Use SetConsoleCtrlHandler for SIGINT/SIGTERM
Diffstat (limited to 'src/MultiUrlRequestInfo.cc')
| -rw-r--r-- | src/MultiUrlRequestInfo.cc | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/MultiUrlRequestInfo.cc b/src/MultiUrlRequestInfo.cc index 7eb171bf..8f54c4e3 100644 --- a/src/MultiUrlRequestInfo.cc +++ b/src/MultiUrlRequestInfo.cc @@ -86,21 +86,44 @@ extern volatile sig_atomic_t globalHaltRequested; } // namespace global namespace { -void handler(int signal) { + +#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 == 0 || global::globalHaltRequested == 2) { + if(global::globalHaltRequested <= 2) { global::globalHaltRequested = 3; } - } else { - if(global::globalHaltRequested == 0) { - global::globalHaltRequested = 1; - } else 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 |
