From b79dea94b2f537eda620ed48207369c076fcd11f Mon Sep 17 00:00:00 2001 From: rakshasa Date: Tue, 1 May 2012 00:29:50 +0900 Subject: [PATCH] Wait for disowned http requests to finish to ensure stopped event gets sent to tracker on client shutdown. --- src/control.cc | 12 +++++++++++- src/control.h | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/control.cc b/src/control.cc index 29603594..e1893883 100644 --- a/src/control.cc +++ b/src/control.cc @@ -44,6 +44,7 @@ #include "core/download_store.h" #include "core/view_manager.h" #include "core/dht_manager.h" +#include "core/http_queue.h" #include "display/canvas.h" #include "display/window.h" @@ -146,7 +147,16 @@ Control::cleanup_exception() { bool Control::is_shutdown_completed() { - return m_shutdownQuick && !worker_thread->is_active() && torrent::is_inactive(); + if (!m_shutdownQuick || worker_thread->is_active()) + return false; + + // Tracker requests can be disowned, so wait for these to + // finish. The edge case of torrent http downloads may delay + // shutdown. + if (!core()->http_stack()->empty() || !core()->http_queue()->empty()) + return false; + + return torrent::is_inactive(); } void diff --git a/src/control.h b/src/control.h index 29f3bcbd..681b6750 100644 --- a/src/control.h +++ b/src/control.h @@ -90,7 +90,6 @@ public: core::ViewManager* view_manager() { return m_viewManager; } core::DhtManager* dht_manager() { return m_dhtManager; } - ui::Root* ui() { return m_ui; } display::Manager* display() { return m_display; } input::Manager* input() { return m_input; }