Bläddra i källkod

Fix bug that signal handler does not work with libaria2

This commit fixes the bug that signal handler does not work with
libaria2 when aria2::RUN_ONCE is passed to aria2::run().
Tatsuhiro Tsujikawa 8 år sedan
förälder
incheckning
85b102a2a0
1 ändrade filer med 11 tillägg och 3 borttagningar
  1. 11 3
      src/DownloadEngine.cc

+ 11 - 3
src/DownloadEngine.cc

@@ -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();