From a3fd34018790e49f8878270bcae0219ec19c34b6 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 27 Oct 2019 13:46:52 +0800 Subject: [PATCH] Revise Session::getPendingAlerts function signature --- src/base/bittorrent/session.cpp | 22 ++++++++++------------ src/base/bittorrent/session.h | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 78f171a57..3f0ba8738 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -2195,14 +2195,13 @@ void Session::saveResumeData() generateResumeData(true); while (m_numResumeData > 0) { - std::vector alerts; - getPendingAlerts(alerts, 30 * 1000); + const std::vector alerts = getPendingAlerts(lt::seconds(30)); if (alerts.empty()) { fprintf(stderr, " aborting with %d outstanding torrents to save resume data for\n", m_numResumeData); break; } - for (const auto a : alerts) { + for (const lt::alert *a : alerts) { switch (a->type()) { case lt::save_resume_data_failed_alert::alert_type: case lt::save_resume_data_alert::alert_type: @@ -3812,13 +3811,14 @@ void Session::handleIPFilterError() emit IPFilterParsed(true, 0); } -void Session::getPendingAlerts(std::vector &out, const ulong time) +std::vector Session::getPendingAlerts(const lt::time_duration time) const { - Q_ASSERT(out.empty()); + if (time > lt::time_duration::zero()) + m_nativeSession->wait_for_alert(time); - if (time > 0) - m_nativeSession->wait_for_alert(lt::milliseconds(time)); - m_nativeSession->pop_alerts(&out); + std::vector alerts; + m_nativeSession->pop_alerts(&alerts); + return alerts; } bool Session::isCreateTorrentSubfolder() const @@ -3834,10 +3834,8 @@ void Session::setCreateTorrentSubfolder(const bool value) // Read alerts sent by the BitTorrent session void Session::readAlerts() { - std::vector alerts; - getPendingAlerts(alerts); - - for (const auto a : alerts) + const std::vector alerts = getPendingAlerts(); + for (const lt::alert *a : alerts) handleAlert(a); } diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index a065f1ed8..a5f1ba95f 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -568,7 +568,7 @@ namespace BitTorrent void saveTorrentsQueue(); void removeTorrentsQueue(); - void getPendingAlerts(std::vector &out, ulong time = 0); + std::vector getPendingAlerts(lt::time_duration time = lt::time_duration::zero()) const; // BitTorrent lt::session *m_nativeSession = nullptr;