1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Cache download/upload limit values

PR #17640.
This commit is contained in:
Vladimir Golovnev 2022-09-01 06:54:51 +03:00 committed by GitHub
parent 77dd8bd27b
commit ca897a8a35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

@ -223,6 +223,13 @@ namespace
outVector.resize(size, defaultValue); outVector.resize(size, defaultValue);
return outVector; return outVector;
} }
// This is an imitation of limit normalization performed by libtorrent itself.
// We need perform it to keep cached values in line with the ones used by libtorrent.
int cleanLimitValue(const int value)
{
return ((value < 0) || (value == std::numeric_limits<int>::max())) ? 0 : value;
}
} }
// TorrentImpl // TorrentImpl
@ -252,6 +259,8 @@ TorrentImpl::TorrentImpl(SessionImpl *session, lt::session *nativeSession
, m_useAutoTMM(params.useAutoTMM) , m_useAutoTMM(params.useAutoTMM)
, m_isStopped(params.stopped) , m_isStopped(params.stopped)
, m_ltAddTorrentParams(params.ltAddTorrentParams) , m_ltAddTorrentParams(params.ltAddTorrentParams)
, m_downloadLimit(cleanLimitValue(m_ltAddTorrentParams.download_limit))
, m_uploadLimit(cleanLimitValue(m_ltAddTorrentParams.upload_limit))
{ {
if (m_ltAddTorrentParams.ti) if (m_ltAddTorrentParams.ti)
{ {
@ -1208,12 +1217,12 @@ qlonglong TorrentImpl::timeSinceActivity() const
int TorrentImpl::downloadLimit() const int TorrentImpl::downloadLimit() const
{ {
return m_nativeHandle.download_limit(); return m_downloadLimit;;
} }
int TorrentImpl::uploadLimit() const int TorrentImpl::uploadLimit() const
{ {
return m_nativeHandle.upload_limit(); return m_uploadLimit;
} }
bool TorrentImpl::superSeeding() const bool TorrentImpl::superSeeding() const
@ -2206,19 +2215,23 @@ void TorrentImpl::setSeedingTimeLimit(int limit)
void TorrentImpl::setUploadLimit(const int limit) void TorrentImpl::setUploadLimit(const int limit)
{ {
if (limit == uploadLimit()) const int cleanValue = cleanLimitValue(limit);
if (cleanValue == uploadLimit())
return; return;
m_nativeHandle.set_upload_limit(limit); m_uploadLimit = cleanValue;
m_nativeHandle.set_upload_limit(m_uploadLimit);
m_session->handleTorrentNeedSaveResumeData(this); m_session->handleTorrentNeedSaveResumeData(this);
} }
void TorrentImpl::setDownloadLimit(const int limit) void TorrentImpl::setDownloadLimit(const int limit)
{ {
if (limit == downloadLimit()) const int cleanValue = cleanLimitValue(limit);
if (cleanValue == downloadLimit())
return; return;
m_nativeHandle.set_download_limit(limit); m_downloadLimit = cleanValue;
m_nativeHandle.set_download_limit(m_downloadLimit);
m_session->handleTorrentNeedSaveResumeData(this); m_session->handleTorrentNeedSaveResumeData(this);
} }

View File

@ -337,6 +337,9 @@ namespace BitTorrent
lt::add_torrent_params m_ltAddTorrentParams; lt::add_torrent_params m_ltAddTorrentParams;
int m_downloadLimit = 0;
int m_uploadLimit = 0;
mutable QBitArray m_pieces; mutable QBitArray m_pieces;
}; };
} }