Browse Source

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.
adaptive-webui-19844
Chocobo1 2 years ago
parent
commit
a44bca3f07
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 27
      src/base/bittorrent/sessionimpl.cpp

27
src/base/bittorrent/sessionimpl.cpp

@ -2892,28 +2892,41 @@ void SessionImpl::saveResumeData() @@ -2892,28 +2892,41 @@ void SessionImpl::saveResumeData()
++m_numResumeData;
}
QElapsedTimer timer;
timer.start();
while (m_numResumeData > 0)
{
const std::vector<lt::alert *> 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<lt::alert *> 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<const lt::torrent_alert *>(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;
}
}
}

Loading…
Cancel
Save