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

Use signed integer type for counters

This commit is contained in:
Chocobo1 2022-04-02 16:31:59 +08:00
parent bbd781c420
commit 2854630b1c
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
8 changed files with 51 additions and 56 deletions

View File

@ -34,10 +34,10 @@ namespace BitTorrent
{ {
struct CacheStatus struct CacheStatus
{ {
quint64 totalUsedBuffers = 0; qint64 totalUsedBuffers = 0;
quint64 jobQueueLength = 0; qint64 jobQueueLength = 0;
quint64 averageJobTime = 0; qint64 averageJobTime = 0;
quint64 queuedBytes = 0; qint64 queuedBytes = 0;
qreal readRatio = 0; // TODO: remove when LIBTORRENT_VERSION_NUM >= 20000 qreal readRatio = 0; // TODO: remove when LIBTORRENT_VERSION_NUM >= 20000
}; };
} }

View File

@ -4702,12 +4702,12 @@ void Session::startUpTorrents()
} }
} }
quint64 Session::getAlltimeDL() const qint64 Session::getAlltimeDL() const
{ {
return m_statistics->getAlltimeDL(); return m_statistics->getAlltimeDL();
} }
quint64 Session::getAlltimeUL() const qint64 Session::getAlltimeUL() const
{ {
return m_statistics->getAlltimeUL(); return m_statistics->getAlltimeUL();
} }
@ -5201,10 +5201,10 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
const int64_t dhtDownload = stats[m_metricIndices.dht.dhtBytesIn]; const int64_t dhtDownload = stats[m_metricIndices.dht.dhtBytesIn];
const int64_t dhtUpload = stats[m_metricIndices.dht.dhtBytesOut]; const int64_t dhtUpload = stats[m_metricIndices.dht.dhtBytesOut];
auto calcRate = [interval](const quint64 previous, const quint64 current) const auto calcRate = [interval](const qint64 previous, const qint64 current) -> qint64
{ {
Q_ASSERT(current >= previous); Q_ASSERT(current >= previous);
return static_cast<quint64>((current - previous) / interval); return ((current - previous) / interval);
}; };
m_status.payloadDownloadRate = calcRate(m_status.totalPayloadDownload, totalPayloadDownload); m_status.payloadDownloadRate = calcRate(m_status.totalPayloadDownload, totalPayloadDownload);

View File

@ -469,8 +469,8 @@ namespace BitTorrent
bool hasRunningSeed() const; bool hasRunningSeed() const;
const SessionStatus &status() const; const SessionStatus &status() const;
const CacheStatus &cacheStatus() const; const CacheStatus &cacheStatus() const;
quint64 getAlltimeDL() const; qint64 getAlltimeDL() const;
quint64 getAlltimeUL() const; qint64 getAlltimeUL() const;
bool isListening() const; bool isListening() const;
MaxRatioAction maxRatioAction() const; MaxRatioAction maxRatioAction() const;

View File

@ -39,37 +39,37 @@ namespace BitTorrent
// Current download rate for the BT // Current download rate for the BT
// session. Payload means that it only take into // session. Payload means that it only take into
// account "useful" part of the rate // account "useful" part of the rate
quint64 payloadDownloadRate = 0; qint64 payloadDownloadRate = 0;
// Current upload rate for the BT // Current upload rate for the BT
// session. Payload means that it only take into // session. Payload means that it only take into
// account "useful" part of the rate // account "useful" part of the rate
quint64 payloadUploadRate = 0; qint64 payloadUploadRate = 0;
// Additional download/upload rates // Additional download/upload rates
quint64 uploadRate = 0; qint64 uploadRate = 0;
quint64 downloadRate = 0; qint64 downloadRate = 0;
quint64 ipOverheadUploadRate = 0; qint64 ipOverheadUploadRate = 0;
quint64 ipOverheadDownloadRate = 0; qint64 ipOverheadDownloadRate = 0;
quint64 dhtUploadRate = 0; qint64 dhtUploadRate = 0;
quint64 dhtDownloadRate = 0; qint64 dhtDownloadRate = 0;
quint64 trackerUploadRate = 0; qint64 trackerUploadRate = 0;
quint64 trackerDownloadRate = 0; qint64 trackerDownloadRate = 0;
quint64 totalDownload = 0; qint64 totalDownload = 0;
quint64 totalUpload = 0; qint64 totalUpload = 0;
quint64 totalPayloadDownload = 0; qint64 totalPayloadDownload = 0;
quint64 totalPayloadUpload = 0; qint64 totalPayloadUpload = 0;
quint64 ipOverheadUpload = 0; qint64 ipOverheadUpload = 0;
quint64 ipOverheadDownload = 0; qint64 ipOverheadDownload = 0;
quint64 dhtUpload = 0; qint64 dhtUpload = 0;
quint64 dhtDownload = 0; qint64 dhtDownload = 0;
quint64 trackerUpload = 0; qint64 trackerUpload = 0;
quint64 trackerDownload = 0; qint64 trackerDownload = 0;
quint64 totalWasted = 0; qint64 totalWasted = 0;
quint64 diskReadQueue = 0; qint64 diskReadQueue = 0;
quint64 diskWriteQueue = 0; qint64 diskWriteQueue = 0;
quint64 dhtNodes = 0; qint64 dhtNodes = 0;
quint64 peersCount = 0; qint64 peersCount = 0;
}; };
} }

View File

@ -42,10 +42,6 @@ using namespace BitTorrent;
Statistics::Statistics(Session *session) Statistics::Statistics(Session *session)
: QObject(session) : QObject(session)
, m_session(session) , m_session(session)
, m_sessionUL(0)
, m_sessionDL(0)
, m_lastWrite(0)
, m_dirty(false)
{ {
load(); load();
connect(&m_timer, &QTimer::timeout, this, &Statistics::gather); connect(&m_timer, &QTimer::timeout, this, &Statistics::gather);
@ -59,12 +55,12 @@ Statistics::~Statistics()
save(); save();
} }
quint64 Statistics::getAlltimeDL() const qint64 Statistics::getAlltimeDL() const
{ {
return m_alltimeDL + m_sessionDL; return m_alltimeDL + m_sessionDL;
} }
quint64 Statistics::getAlltimeUL() const qint64 Statistics::getAlltimeUL() const
{ {
return m_alltimeUL + m_sessionUL; return m_alltimeUL + m_sessionUL;
} }
@ -95,8 +91,8 @@ void Statistics::save() const
SettingsPtr s = Profile::instance()->applicationSettings(u"qBittorrent-data"_qs); SettingsPtr s = Profile::instance()->applicationSettings(u"qBittorrent-data"_qs);
QVariantHash v; QVariantHash v;
v.insert(u"AlltimeDL"_qs, m_alltimeDL + m_sessionDL); v.insert(u"AlltimeDL"_qs, (m_alltimeDL + m_sessionDL));
v.insert(u"AlltimeUL"_qs, m_alltimeUL + m_sessionUL); v.insert(u"AlltimeUL"_qs, (m_alltimeUL + m_sessionUL));
s->setValue(u"Stats/AllStats"_qs, v); s->setValue(u"Stats/AllStats"_qs, v);
m_dirty = false; m_dirty = false;
m_lastWrite = now; m_lastWrite = now;

View File

@ -45,8 +45,8 @@ public:
explicit Statistics(BitTorrent::Session *session); explicit Statistics(BitTorrent::Session *session);
~Statistics(); ~Statistics();
quint64 getAlltimeDL() const; qint64 getAlltimeDL() const;
quint64 getAlltimeUL() const; qint64 getAlltimeUL() const;
private slots: private slots:
void gather(); void gather();
@ -56,13 +56,12 @@ private:
void load(); void load();
BitTorrent::Session *m_session; BitTorrent::Session *m_session;
// Will overflow at 15.9 EiB qint64 m_alltimeUL = 0;
quint64 m_alltimeUL; qint64 m_alltimeDL = 0;
quint64 m_alltimeDL; qint64 m_sessionUL = 0;
quint64 m_sessionUL; qint64 m_sessionDL = 0;
quint64 m_sessionDL; mutable qint64 m_lastWrite = 0;
mutable qint64 m_lastWrite; mutable bool m_dirty = false;
mutable bool m_dirty;
QTimer m_timer; QTimer m_timer;
}; };

View File

@ -76,8 +76,8 @@ void StatsDialog::update()
const BitTorrent::CacheStatus &cs = BitTorrent::Session::instance()->cacheStatus(); const BitTorrent::CacheStatus &cs = BitTorrent::Session::instance()->cacheStatus();
// All-time DL/UL // All-time DL/UL
quint64 atd = BitTorrent::Session::instance()->getAlltimeDL(); const qint64 atd = BitTorrent::Session::instance()->getAlltimeDL();
quint64 atu = BitTorrent::Session::instance()->getAlltimeUL(); const qint64 atu = BitTorrent::Session::instance()->getAlltimeUL();
m_ui->labelAlltimeDL->setText(Utils::Misc::friendlyUnit(atd)); m_ui->labelAlltimeDL->setText(Utils::Misc::friendlyUnit(atd));
m_ui->labelAlltimeUL->setText(Utils::Misc::friendlyUnit(atu)); m_ui->labelAlltimeUL->setText(Utils::Misc::friendlyUnit(atu));
// Total waste (this session) // Total waste (this session)

View File

@ -126,8 +126,8 @@ namespace
map[KEY_TRANSFER_DLRATELIMIT] = session->downloadSpeedLimit(); map[KEY_TRANSFER_DLRATELIMIT] = session->downloadSpeedLimit();
map[KEY_TRANSFER_UPRATELIMIT] = session->uploadSpeedLimit(); map[KEY_TRANSFER_UPRATELIMIT] = session->uploadSpeedLimit();
const quint64 atd = session->getAlltimeDL(); const qint64 atd = session->getAlltimeDL();
const quint64 atu = session->getAlltimeUL(); const qint64 atu = session->getAlltimeUL();
map[KEY_TRANSFER_ALLTIME_DL] = atd; map[KEY_TRANSFER_ALLTIME_DL] = atd;
map[KEY_TRANSFER_ALLTIME_UL] = atu; map[KEY_TRANSFER_ALLTIME_UL] = atu;
map[KEY_TRANSFER_TOTAL_WASTE_SESSION] = sessionStatus.totalWasted; map[KEY_TRANSFER_TOTAL_WASTE_SESSION] = sessionStatus.totalWasted;