Merge pull request #1053 from aria2/fix-libaria2-signal-handler

Fix bug that signal handler does not work with libaria2
pull/1057/head
Tatsuhiro Tsujikawa 2017-11-01 00:44:35 +09:00 committed by GitHub
commit d508e41198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -150,14 +150,22 @@ void executeCommand(std::deque<std::unique_ptr<Command>>& commands,
namespace {
class GlobalHaltRequestedFinalizer {
public:
GlobalHaltRequestedFinalizer() = default;
~GlobalHaltRequestedFinalizer() { global::globalHaltRequested = 5; }
GlobalHaltRequestedFinalizer(bool oneshot) : oneshot_(oneshot) {}
~GlobalHaltRequestedFinalizer()
{
if (!oneshot_) {
global::globalHaltRequested = 5;
}
}
private:
bool oneshot_;
};
} // namespace
int DownloadEngine::run(bool oneshot)
{
GlobalHaltRequestedFinalizer ghrf;
GlobalHaltRequestedFinalizer ghrf(oneshot);
while (!commands_.empty() || !routineCommands_.empty()) {
if (!commands_.empty()) {
waitData();