From a44bca3f070b828f46049b831f13a66e5b04c111 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 14 Oct 2022 20:52:12 +0800 Subject: [PATCH] Revise "save resume data" handling on shutdown When shutting down, instead of waiting for all types of alert from libtorrent, now it only waits for specific alert types. This potentially help shorten the shutdown waiting time. --- src/base/bittorrent/sessionimpl.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 6a1fd4a49..478ee59cc 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -2892,28 +2892,41 @@ void SessionImpl::saveResumeData() ++m_numResumeData; } + QElapsedTimer timer; + timer.start(); + while (m_numResumeData > 0) { - const std::vector alerts = getPendingAlerts(lt::seconds {30}); - if (alerts.empty()) - { - LogMsg(tr("Aborted saving resume data. Number of outstanding torrents: %1").arg(QString::number(m_numResumeData)) - , Log::CRITICAL); - break; - } + const lt::seconds waitTime {5}; + const lt::seconds expireTime {30}; + const std::vector alerts = getPendingAlerts(waitTime); + bool hasWantedAlert = false; for (const lt::alert *a : alerts) { switch (a->type()) { case lt::save_resume_data_failed_alert::alert_type: + hasWantedAlert = true; --m_numResumeData; break; case lt::save_resume_data_alert::alert_type: + hasWantedAlert = true; dispatchTorrentAlert(static_cast(a)); break; } } + + if (hasWantedAlert) + { + timer.start(); + } + else if (timer.hasExpired(lt::total_milliseconds(expireTime))) + { + LogMsg(tr("Aborted saving resume data. Number of outstanding torrents: %1").arg(QString::number(m_numResumeData)) + , Log::CRITICAL); + break; + } } }