simplify the accounting of active_download and active_finished torrents
This commit is contained in:
parent
0e6e943318
commit
0951219ab6
|
@ -263,19 +263,9 @@ namespace libtorrent
|
|||
void force_recheck();
|
||||
void save_resume_data(int flags);
|
||||
|
||||
bool is_active_download() const
|
||||
{
|
||||
return (m_state == torrent_status::downloading
|
||||
|| m_state == torrent_status::downloading_metadata)
|
||||
&& m_allow_peers;
|
||||
}
|
||||
|
||||
bool is_active_finished() const
|
||||
{
|
||||
return (m_state == torrent_status::finished
|
||||
|| m_state == torrent_status::seeding)
|
||||
&& m_allow_peers;
|
||||
}
|
||||
bool is_active_download() const;
|
||||
bool is_active_finished() const;
|
||||
void update_guage();
|
||||
|
||||
bool need_save_resume_data() const
|
||||
{
|
||||
|
@ -1385,6 +1375,12 @@ namespace libtorrent
|
|||
// to never add the same torrent twice
|
||||
bool m_in_state_updates:1;
|
||||
|
||||
// these represent whether or not this torrent is counted
|
||||
// in the total counters of active seeds and downloads
|
||||
// in the session.
|
||||
bool m_is_active_download:1;
|
||||
bool m_is_active_finished:1;
|
||||
|
||||
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
||||
public:
|
||||
// set to false until we've loaded resume data
|
||||
|
|
|
@ -5251,8 +5251,6 @@ retry:
|
|||
|
||||
void session_impl::remove_torrent_impl(boost::shared_ptr<torrent> tptr, int options)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
// remove from uuid list
|
||||
if (!tptr->uuid().empty())
|
||||
{
|
||||
|
@ -5278,12 +5276,7 @@ retry:
|
|||
if (options & session::delete_files)
|
||||
t.delete_files();
|
||||
|
||||
bool is_active_download = tptr->is_active_download();
|
||||
bool is_active_finished = tptr->is_active_finished();
|
||||
|
||||
// update finished and downloading counters
|
||||
if (is_active_download) dec_active_downloading();
|
||||
if (is_active_finished) dec_active_finished();
|
||||
tptr->update_guage();
|
||||
|
||||
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
||||
sha1_hash i_hash = t.torrent_file().info_hash();
|
||||
|
|
|
@ -425,6 +425,8 @@ namespace libtorrent
|
|||
, m_merge_resume_trackers(p.flags & add_torrent_params::flag_merge_resume_trackers)
|
||||
, m_state_subscription(p.flags & add_torrent_params::flag_update_subscribe)
|
||||
, m_in_state_updates(false)
|
||||
, m_is_active_download(false)
|
||||
, m_is_active_finished(false)
|
||||
{
|
||||
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
||||
m_resume_data_loaded = false;
|
||||
|
@ -436,9 +438,7 @@ namespace libtorrent
|
|||
|
||||
if (!m_apply_ip_filter) ++m_ses.m_non_filtered_torrents;
|
||||
|
||||
// update finished and downloading counters
|
||||
if (is_active_download()) m_ses.inc_active_downloading();
|
||||
if (is_active_finished()) m_ses.inc_active_finished();
|
||||
update_guage();
|
||||
|
||||
if (!p.ti || !p.ti->is_valid())
|
||||
{
|
||||
|
@ -841,6 +841,54 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
bool torrent::is_active_download() const
|
||||
{
|
||||
return (m_state == torrent_status::downloading
|
||||
|| m_state == torrent_status::downloading_metadata)
|
||||
&& m_allow_peers
|
||||
&& !m_abort;
|
||||
}
|
||||
|
||||
bool torrent::is_active_finished() const
|
||||
{
|
||||
return (m_state == torrent_status::finished
|
||||
|| m_state == torrent_status::seeding)
|
||||
&& m_allow_peers
|
||||
&& !m_abort;
|
||||
}
|
||||
|
||||
void torrent::update_guage()
|
||||
{
|
||||
bool is_active_download = (m_state == torrent_status::downloading
|
||||
|| m_state == torrent_status::downloading_metadata)
|
||||
&& m_allow_peers
|
||||
&& !m_abort;
|
||||
|
||||
bool is_active_finished = (m_state == torrent_status::finished
|
||||
|| m_state == torrent_status::seeding)
|
||||
&& m_allow_peers
|
||||
&& !m_abort;
|
||||
|
||||
// update finished and downloading counters
|
||||
if (is_active_download != m_is_active_download)
|
||||
{
|
||||
if (is_active_download)
|
||||
m_ses.inc_active_downloading();
|
||||
else
|
||||
m_ses.dec_active_downloading();
|
||||
m_is_active_download = is_active_download;
|
||||
}
|
||||
|
||||
if (is_active_finished != m_is_active_finished)
|
||||
{
|
||||
if (is_active_finished)
|
||||
m_ses.inc_active_finished();
|
||||
else
|
||||
m_ses.dec_active_finished();
|
||||
m_is_active_finished = is_active_finished;
|
||||
}
|
||||
}
|
||||
|
||||
void torrent::start_download_url()
|
||||
{
|
||||
TORRENT_ASSERT(!m_url.empty());
|
||||
|
@ -3544,6 +3592,9 @@ namespace libtorrent
|
|||
if (m_abort) return;
|
||||
|
||||
m_abort = true;
|
||||
|
||||
update_guage();
|
||||
|
||||
// if the torrent is paused, it doesn't need
|
||||
// to announce with even=stopped again.
|
||||
if (!is_paused())
|
||||
|
@ -7346,19 +7397,10 @@ namespace libtorrent
|
|||
if (m_allow_peers == b
|
||||
&& m_graceful_pause_mode == graceful) return;
|
||||
|
||||
bool was_active_download = is_active_download();
|
||||
bool was_active_finished = is_active_finished();
|
||||
|
||||
m_allow_peers = b;
|
||||
if (!m_ses.is_paused())
|
||||
m_graceful_pause_mode = graceful;
|
||||
|
||||
// update finished and downloading counters
|
||||
if (was_active_download && !is_active_download()) m_ses.dec_active_downloading();
|
||||
else if (!was_active_download && is_active_download()) m_ses.inc_active_downloading();
|
||||
if (was_active_finished && !is_active_finished()) m_ses.dec_active_finished();
|
||||
else if (!was_active_finished && is_active_finished()) m_ses.inc_active_finished();
|
||||
|
||||
if (!b)
|
||||
{
|
||||
m_announce_to_dht = false;
|
||||
|
@ -7370,6 +7412,8 @@ namespace libtorrent
|
|||
{
|
||||
do_resume();
|
||||
}
|
||||
|
||||
update_guage();
|
||||
}
|
||||
|
||||
void torrent::resume()
|
||||
|
@ -8501,20 +8545,13 @@ namespace libtorrent
|
|||
if (m_ses.m_alerts.should_post<state_changed_alert>())
|
||||
m_ses.m_alerts.post_alert(state_changed_alert(get_handle(), s, (torrent_status::state_t)m_state));
|
||||
|
||||
bool was_active_download = is_active_download();
|
||||
bool was_active_finished = is_active_finished();
|
||||
|
||||
m_state = s;
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
|
||||
debug_log("set_state() %d", m_state);
|
||||
#endif
|
||||
|
||||
// update finished and downloading counters
|
||||
if (was_active_download && !is_active_download()) m_ses.dec_active_downloading();
|
||||
else if (!was_active_download && is_active_download()) m_ses.inc_active_downloading();
|
||||
if (was_active_finished && !is_active_finished()) m_ses.dec_active_finished();
|
||||
else if (!was_active_finished && is_active_finished()) m_ses.inc_active_finished();
|
||||
update_guage();
|
||||
|
||||
state_updated();
|
||||
|
||||
|
|
Loading…
Reference in New Issue