mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 23:37:59 +00:00
Merge pull request #17885 from Chocobo1/shutdown
Revise "save resume data" handling on shutdown
This commit is contained in:
commit
dcfd367ff8
@ -1030,11 +1030,12 @@ void SessionImpl::setGlobalMaxSeedingMinutes(int minutes)
|
|||||||
// Main destructor
|
// Main destructor
|
||||||
SessionImpl::~SessionImpl()
|
SessionImpl::~SessionImpl()
|
||||||
{
|
{
|
||||||
saveStatistics();
|
// Do some bittorrent related saving
|
||||||
|
// After this, (ideally) no more important alerts will be generated/handled
|
||||||
// Do some BT related saving
|
|
||||||
saveResumeData();
|
saveResumeData();
|
||||||
|
|
||||||
|
saveStatistics();
|
||||||
|
|
||||||
// We must delete FilterParserThread
|
// We must delete FilterParserThread
|
||||||
// before we delete lt::session
|
// before we delete lt::session
|
||||||
delete m_filterParser;
|
delete m_filterParser;
|
||||||
@ -2444,6 +2445,12 @@ void SessionImpl::handleTorrentSaveResumeDataRequested(const TorrentImpl *torren
|
|||||||
++m_numResumeData;
|
++m_numResumeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SessionImpl::handleTorrentSaveResumeDataFailed(const TorrentImpl *torrent)
|
||||||
|
{
|
||||||
|
Q_UNUSED(torrent);
|
||||||
|
--m_numResumeData;
|
||||||
|
}
|
||||||
|
|
||||||
QVector<Torrent *> SessionImpl::torrents() const
|
QVector<Torrent *> SessionImpl::torrents() const
|
||||||
{
|
{
|
||||||
QVector<Torrent *> result;
|
QVector<Torrent *> result;
|
||||||
@ -2892,28 +2899,37 @@ void SessionImpl::saveResumeData()
|
|||||||
++m_numResumeData;
|
++m_numResumeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QElapsedTimer timer;
|
||||||
|
timer.start();
|
||||||
|
|
||||||
while (m_numResumeData > 0)
|
while (m_numResumeData > 0)
|
||||||
{
|
{
|
||||||
const std::vector<lt::alert *> alerts = getPendingAlerts(lt::seconds {30});
|
const lt::seconds waitTime {5};
|
||||||
if (alerts.empty())
|
const lt::seconds expireTime {30};
|
||||||
|
const std::vector<lt::alert *> alerts = getPendingAlerts(waitTime);
|
||||||
|
|
||||||
|
bool hasWantedAlert = false;
|
||||||
|
for (const lt::alert *a : alerts)
|
||||||
|
{
|
||||||
|
if (const int alertType = a->type();
|
||||||
|
(alertType == lt::save_resume_data_alert::alert_type)
|
||||||
|
|| (alertType == lt::save_resume_data_failed_alert::alert_type))
|
||||||
|
{
|
||||||
|
hasWantedAlert = true;
|
||||||
|
handleAlert(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
LogMsg(tr("Aborted saving resume data. Number of outstanding torrents: %1").arg(QString::number(m_numResumeData))
|
||||||
, Log::CRITICAL);
|
, Log::CRITICAL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const lt::alert *a : alerts)
|
|
||||||
{
|
|
||||||
switch (a->type())
|
|
||||||
{
|
|
||||||
case lt::save_resume_data_failed_alert::alert_type:
|
|
||||||
--m_numResumeData;
|
|
||||||
break;
|
|
||||||
case lt::save_resume_data_alert::alert_type:
|
|
||||||
dispatchTorrentAlert(static_cast<const lt::torrent_alert *>(a));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,6 +410,7 @@ namespace BitTorrent
|
|||||||
// Torrent interface
|
// Torrent interface
|
||||||
void handleTorrentNeedSaveResumeData(const TorrentImpl *torrent);
|
void handleTorrentNeedSaveResumeData(const TorrentImpl *torrent);
|
||||||
void handleTorrentSaveResumeDataRequested(const TorrentImpl *torrent);
|
void handleTorrentSaveResumeDataRequested(const TorrentImpl *torrent);
|
||||||
|
void handleTorrentSaveResumeDataFailed(const TorrentImpl *torrent);
|
||||||
void handleTorrentShareLimitChanged(TorrentImpl *const torrent);
|
void handleTorrentShareLimitChanged(TorrentImpl *const torrent);
|
||||||
void handleTorrentNameChanged(TorrentImpl *const torrent);
|
void handleTorrentNameChanged(TorrentImpl *const torrent);
|
||||||
void handleTorrentSavePathChanged(TorrentImpl *const torrent);
|
void handleTorrentSavePathChanged(TorrentImpl *const torrent);
|
||||||
|
@ -1949,8 +1949,13 @@ void TorrentImpl::prepareResumeData(const lt::add_torrent_params ¶ms)
|
|||||||
|
|
||||||
void TorrentImpl::handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p)
|
void TorrentImpl::handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p)
|
||||||
{
|
{
|
||||||
Q_UNUSED(p);
|
if (p->error != lt::errors::resume_data_not_modified)
|
||||||
Q_ASSERT_X(false, Q_FUNC_INFO, "This point should be unreachable since libtorrent 1.2.11");
|
{
|
||||||
|
LogMsg(tr("Generate resume data failed. Torrent: \"%1\". Reason: \"%2\"")
|
||||||
|
.arg(name(), QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_session->handleTorrentSaveResumeDataFailed(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentImpl::handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p)
|
void TorrentImpl::handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p)
|
||||||
|
Loading…
Reference in New Issue
Block a user