Hardening idle_seconds
This commit is contained in:
parent
6c1cee5f79
commit
1974d62c7a
|
@ -446,7 +446,7 @@ void tr_torrent::stop_if_seed_limit_reached()
|
|||
session->onRatioLimitHit(this);
|
||||
}
|
||||
/* if we're seeding and reach our inactivity limit, stop the torrent */
|
||||
else if (auto const secs_left = idle_seconds_left(tr_time()); secs_left && *secs_left == 0U)
|
||||
else if (auto const secs_left = idle_seconds_left(tr_time()); secs_left && *secs_left <= 0U)
|
||||
{
|
||||
tr_logAddInfoTor(this, _("Seeding idle limit reached; pausing torrent"));
|
||||
|
||||
|
@ -1281,7 +1281,7 @@ bool tr_torrentCanManualUpdate(tr_torrent const* tor)
|
|||
|
||||
tr_stat tr_torrent::stats() const
|
||||
{
|
||||
static auto constexpr IsStalled = [](tr_torrent const* const tor, std::optional<size_t> idle_secs)
|
||||
static auto constexpr IsStalled = [](tr_torrent const* const tor, std::optional<time_t> idle_secs)
|
||||
{
|
||||
return tor->session->queueStalledEnabled() && idle_secs > tor->session->queueStalledMinutes() * 60U;
|
||||
};
|
||||
|
@ -1299,7 +1299,7 @@ tr_stat tr_torrent::stats() const
|
|||
stats.activity = activity;
|
||||
stats.error = this->error().error_type();
|
||||
stats.queuePosition = queue_position();
|
||||
stats.idleSecs = idle_seconds ? static_cast<time_t>(*idle_seconds) : -1;
|
||||
stats.idleSecs = idle_seconds ? *idle_seconds : -1;
|
||||
stats.isStalled = IsStalled(this, idle_seconds);
|
||||
stats.errorString = this->error().errmsg().c_str();
|
||||
|
||||
|
|
|
@ -818,7 +818,7 @@ struct tr_torrent
|
|||
return idle_limit_minutes_;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr std::optional<size_t> idle_seconds(time_t now) const noexcept
|
||||
[[nodiscard]] constexpr std::optional<time_t> idle_seconds(time_t now) const noexcept
|
||||
{
|
||||
auto const activity = this->activity();
|
||||
|
||||
|
@ -827,7 +827,7 @@ struct tr_torrent
|
|||
if (auto const latest = std::max(date_started_, date_active_); latest != 0)
|
||||
{
|
||||
TR_ASSERT(now >= latest);
|
||||
return now - latest;
|
||||
return std::max(now - latest, time_t{ 0 });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1126,7 +1126,7 @@ private:
|
|||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr std::optional<size_t> idle_seconds_left(time_t now) const noexcept
|
||||
[[nodiscard]] constexpr std::optional<time_t> idle_seconds_left(time_t now) const noexcept
|
||||
{
|
||||
auto const idle_limit_minutes = effective_idle_limit_minutes();
|
||||
if (!idle_limit_minutes)
|
||||
|
@ -1140,7 +1140,7 @@ private:
|
|||
return {};
|
||||
}
|
||||
|
||||
auto const idle_limit_seconds = size_t{ *idle_limit_minutes } * 60U;
|
||||
auto const idle_limit_seconds = time_t{ *idle_limit_minutes } * 60U;
|
||||
return idle_limit_seconds > *idle_seconds ? idle_limit_seconds - *idle_seconds : 0U;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue