improve type safety of internal leave_seed_mode() function

This commit is contained in:
arvidn 2018-07-07 13:16:47 +02:00 committed by Arvid Norberg
parent 6d2f804d9f
commit e45df614fe
3 changed files with 16 additions and 12 deletions

View File

@ -1063,7 +1063,10 @@ namespace libtorrent {
queue_position_t sequence_number() const { return m_sequence_number; }
bool seed_mode() const { return m_seed_mode; }
void leave_seed_mode(bool skip_checking);
enum class seed_mode_t { check_files, skip_checking };
void leave_seed_mode(seed_mode_t checking);
bool all_verified() const
{ return int(m_num_verified) == m_torrent_file->num_pieces(); }

View File

@ -5254,7 +5254,7 @@ namespace libtorrent {
if (error)
{
t->handle_disk_error("hash", error, this);
t->leave_seed_mode(false);
t->leave_seed_mode(torrent::seed_mode_t::check_files);
return;
}
@ -5267,7 +5267,7 @@ namespace libtorrent {
, "piece: %d failed", static_cast<int>(piece));
#endif
t->leave_seed_mode(false);
t->leave_seed_mode(torrent::seed_mode_t::check_files);
}
else
{
@ -5282,7 +5282,7 @@ namespace libtorrent {
, "piece: %d passed", static_cast<int>(piece));
#endif
if (t->seed_mode() && t->all_verified())
t->leave_seed_mode(true);
t->leave_seed_mode(torrent::seed_mode_t::skip_checking);
}
// try to service the requests again, now that the piece

View File

@ -566,11 +566,11 @@ bool is_downloading_state(int const st)
m_current_gauge_state = static_cast<std::uint32_t>(new_gauge_state);
}
void torrent::leave_seed_mode(bool skip_checking)
void torrent::leave_seed_mode(seed_mode_t const checking)
{
if (!m_seed_mode) return;
if (!skip_checking)
if (checking == seed_mode_t::check_files)
{
// this means the user promised we had all the
// files, but it turned out we didn't. This is
@ -585,12 +585,13 @@ bool is_downloading_state(int const st)
#ifndef TORRENT_DISABLE_LOGGING
debug_log("*** LEAVING SEED MODE (%s)"
, skip_checking ? "as seed" : "as non-seed");
, checking == seed_mode_t::skip_checking ? "as seed" : "as non-seed");
#endif
m_seed_mode = false;
// seed is false if we turned out not
// to be a seed after all
if (!skip_checking && state() != torrent_status::checking_resume_data)
if (checking == seed_mode_t::check_files
&& state() != torrent_status::checking_resume_data)
{
m_have_all = false;
set_state(torrent_status::downloading);
@ -947,7 +948,7 @@ bool is_downloading_state(int const st)
if ((mask & torrent_flags::seed_mode)
&& !(flags & torrent_flags::seed_mode))
{
leave_seed_mode(false);
leave_seed_mode(seed_mode_t::check_files);
}
if (mask & torrent_flags::upload_mode)
set_upload_mode(bool(flags & torrent_flags::upload_mode));
@ -2134,7 +2135,7 @@ bool is_downloading_state(int const st)
// being in seed mode and missing a piece is not compatible.
// Leave seed mode if that happens
if (m_seed_mode) leave_seed_mode(true);
if (m_seed_mode) leave_seed_mode(seed_mode_t::skip_checking);
if (has_picker() && m_picker->have_piece(piece))
{
@ -2205,7 +2206,7 @@ bool is_downloading_state(int const st)
// we're checking everything anyway, no point in assuming we are a seed
// now.
leave_seed_mode(true);
leave_seed_mode(seed_mode_t::skip_checking);
m_ses.disk_thread().async_release_files(m_storage);
@ -7444,7 +7445,7 @@ bool is_downloading_state(int const st)
// we're downloading now, which means we're no longer in seed mode
if (m_seed_mode)
leave_seed_mode(false);
leave_seed_mode(seed_mode_t::check_files);
TORRENT_ASSERT(!is_finished());
set_state(torrent_status::downloading);