simplify logic for sending torrent_finished_alert and fix incorrect assert
This commit is contained in:
parent
57e95879ec
commit
d52a1f8c0a
|
@ -1382,9 +1382,6 @@ namespace libtorrent
|
||||||
public:
|
public:
|
||||||
// set to false until we've loaded resume data
|
// set to false until we've loaded resume data
|
||||||
bool m_resume_data_loaded;
|
bool m_resume_data_loaded;
|
||||||
|
|
||||||
// set to true when the finished alert is posted
|
|
||||||
bool m_finished_alert_posted;
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -435,7 +435,6 @@ namespace libtorrent
|
||||||
|
|
||||||
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
||||||
m_resume_data_loaded = false;
|
m_resume_data_loaded = false;
|
||||||
m_finished_alert_posted = false;
|
|
||||||
#endif
|
#endif
|
||||||
#if TORRENT_USE_UNC_PATHS
|
#if TORRENT_USE_UNC_PATHS
|
||||||
m_save_path = canonicalize_path(m_save_path);
|
m_save_path = canonicalize_path(m_save_path);
|
||||||
|
@ -2048,9 +2047,7 @@ namespace libtorrent
|
||||||
int blocks_in_last_piece = ((m_torrent_file->total_size() % m_torrent_file->piece_length())
|
int blocks_in_last_piece = ((m_torrent_file->total_size() % m_torrent_file->piece_length())
|
||||||
+ block_size() - 1) / block_size();
|
+ block_size() - 1) / block_size();
|
||||||
m_picker->init(blocks_per_piece, blocks_in_last_piece, m_torrent_file->num_pieces());
|
m_picker->init(blocks_per_piece, blocks_in_last_piece, m_torrent_file->num_pieces());
|
||||||
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
|
||||||
m_finished_alert_posted = false;
|
|
||||||
#endif
|
|
||||||
// assume that we don't have anything
|
// assume that we don't have anything
|
||||||
TORRENT_ASSERT(m_picker->num_have() == 0);
|
TORRENT_ASSERT(m_picker->num_have() == 0);
|
||||||
m_files_checked = false;
|
m_files_checked = false;
|
||||||
|
@ -6267,19 +6264,9 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
TORRENT_ASSERT(!m_finished_alert_posted);
|
|
||||||
TORRENT_ASSERT(is_finished());
|
TORRENT_ASSERT(is_finished());
|
||||||
TORRENT_ASSERT(m_state != torrent_status::finished && m_state != torrent_status::seeding);
|
TORRENT_ASSERT(m_state != torrent_status::finished && m_state != torrent_status::seeding);
|
||||||
|
|
||||||
if (alerts().should_post<torrent_finished_alert>())
|
|
||||||
{
|
|
||||||
alerts().post_alert(torrent_finished_alert(
|
|
||||||
get_handle()));
|
|
||||||
}
|
|
||||||
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
|
||||||
m_finished_alert_posted = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
set_state(torrent_status::finished);
|
set_state(torrent_status::finished);
|
||||||
set_queue_position(-1);
|
set_queue_position(-1);
|
||||||
|
|
||||||
|
@ -6340,9 +6327,6 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS
|
|
||||||
m_finished_alert_posted = false;
|
|
||||||
#endif
|
|
||||||
TORRENT_ASSERT(!is_finished());
|
TORRENT_ASSERT(!is_finished());
|
||||||
set_state(torrent_status::downloading);
|
set_state(torrent_status::downloading);
|
||||||
set_queue_position((std::numeric_limits<int>::max)());
|
set_queue_position((std::numeric_limits<int>::max)());
|
||||||
|
@ -6622,12 +6606,6 @@ namespace libtorrent
|
||||||
else
|
else
|
||||||
TORRENT_ASSERT(m_queued_for_checking);
|
TORRENT_ASSERT(m_queued_for_checking);
|
||||||
|
|
||||||
if (!m_finished_alert_posted)
|
|
||||||
{
|
|
||||||
TORRENT_ASSERT(m_state != torrent_status::seeding
|
|
||||||
&& m_state != torrent_status::finished);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_ses.m_queued_for_checking.empty())
|
if (!m_ses.m_queued_for_checking.empty())
|
||||||
{
|
{
|
||||||
// if there are torrents waiting to be checked
|
// if there are torrents waiting to be checked
|
||||||
|
@ -8583,12 +8561,6 @@ namespace libtorrent
|
||||||
if (s == torrent_status::seeding)
|
if (s == torrent_status::seeding)
|
||||||
TORRENT_ASSERT(is_seed());
|
TORRENT_ASSERT(is_seed());
|
||||||
|
|
||||||
if (!m_finished_alert_posted)
|
|
||||||
{
|
|
||||||
TORRENT_ASSERT(s != torrent_status::seeding
|
|
||||||
&& s != torrent_status::finished);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s == torrent_status::seeding)
|
if (s == torrent_status::seeding)
|
||||||
TORRENT_ASSERT(is_seed());
|
TORRENT_ASSERT(is_seed());
|
||||||
if (s == torrent_status::finished)
|
if (s == torrent_status::finished)
|
||||||
|
@ -8598,8 +8570,20 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (int(m_state) == s) return;
|
if (int(m_state) == s) return;
|
||||||
|
|
||||||
if (m_ses.m_alerts.should_post<state_changed_alert>())
|
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));
|
{
|
||||||
|
m_ses.m_alerts.post_alert(state_changed_alert(get_handle()
|
||||||
|
, s, (torrent_status::state_t)m_state));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s == torrent_status::finished
|
||||||
|
&& m_ses.m_alerts.should_post<torrent_finished_alert>())
|
||||||
|
{
|
||||||
|
alerts().post_alert(torrent_finished_alert(
|
||||||
|
get_handle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
m_state = s;
|
m_state = s;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue