Fix ratio handling

PR #22638.
This commit is contained in:
Vladimir Golovnev
2025-05-01 14:18:18 +03:00
committed by GitHub
parent e7dee969e1
commit 6cd6267c26
11 changed files with 16 additions and 21 deletions

View File

@@ -1242,7 +1242,7 @@ qreal SessionImpl::globalMaxRatio() const
void SessionImpl::setGlobalMaxRatio(qreal ratio)
{
if (ratio < 0)
ratio = -1.;
ratio = Torrent::NO_RATIO_LIMIT;
if (ratio != globalMaxRatio())
{
@@ -2331,7 +2331,7 @@ void SessionImpl::processTorrentShareLimits(TorrentImpl *torrent)
QString description;
if (const qreal ratio = torrent->realRatio();
(ratioLimit >= 0) && (ratio <= Torrent::MAX_RATIO) && (ratio >= ratioLimit))
(ratioLimit >= 0) && (ratio >= ratioLimit))
{
reached = true;
description = tr("Torrent reached the share ratio limit.");

View File

@@ -29,6 +29,8 @@
#include "torrent.h"
#include <limits>
#include <QHash>
#include "infohash.h"
@@ -51,7 +53,7 @@ namespace BitTorrent
const int Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME = -2;
const int Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT = -1;
const qreal Torrent::MAX_RATIO = 9999;
const qreal Torrent::MAX_RATIO = std::numeric_limits<qreal>::infinity();
TorrentID Torrent::id() const
{

View File

@@ -1515,7 +1515,8 @@ qreal TorrentImpl::realRatio() const
const qreal ratio = upload / static_cast<qreal>(download);
Q_ASSERT(ratio >= 0);
return (ratio > MAX_RATIO) ? MAX_RATIO : ratio;
return ratio;
}
int TorrentImpl::uploadPayloadRate() const
@@ -2677,8 +2678,6 @@ void TorrentImpl::setRatioLimit(qreal limit)
{
if (limit < USE_GLOBAL_RATIO)
limit = NO_RATIO_LIMIT;
else if (limit > MAX_RATIO)
limit = MAX_RATIO;
if (m_ratioLimit != limit)
{