use the strong type for pause flags

This commit is contained in:
arvidn 2018-07-15 23:34:47 +02:00 committed by Arvid Norberg
parent 4633258fbe
commit 4aa3c4573a
5 changed files with 19 additions and 23 deletions

View File

@ -505,16 +505,11 @@ namespace libtorrent {
error_code error() const { return m_error; }
void flush_cache();
void pause(bool graceful = false);
void pause(pause_flags_t flags = {});
void resume();
enum pause_flags_t
{
flag_graceful_pause = 1,
flag_clear_disk_cache = 2
};
void set_session_paused(bool b);
void set_paused(bool b, int flags = flag_clear_disk_cache);
void set_paused(bool b, pause_flags_t flags = torrent_handle::clear_disk_cache);
void set_announce_to_dht(bool b) { m_announce_to_dht = b; }
void set_announce_to_trackers(bool b) { m_announce_to_trackers = b; }
void set_announce_to_lsd(bool b) { m_announce_to_lsd = b; }
@ -523,7 +518,7 @@ namespace libtorrent {
time_point32 started() const { return m_started; }
void step_session_time(int seconds);
void do_pause(bool clear_disk_cache = true);
void do_pause(pause_flags_t flags = torrent_handle::clear_disk_cache);
void do_resume();
seconds32 finished_time() const;

View File

@ -552,6 +552,7 @@ TORRENT_IPV6_NAMESPACE_END
// disconnected. This is a graceful shut down of the torrent in the sense
// that no downloaded bytes are wasted.
static constexpr pause_flags_t graceful_pause = 0_bit;
static constexpr pause_flags_t clear_disk_cache = 1_bit;
// ``pause()``, and ``resume()`` will disconnect all peers and reconnect
// all peers respectively. When a torrent is paused, it will however

View File

@ -3762,8 +3762,8 @@ namespace aux {
t->log_to_all_peers("auto manager pausing torrent");
#endif
// use graceful pause for auto-managed torrents
t->set_paused(true, torrent::flag_graceful_pause
| torrent::flag_clear_disk_cache);
t->set_paused(true, torrent_handle::graceful_pause
| torrent_handle::clear_disk_cache);
t->set_announce_to_dht(false);
t->set_announce_to_trackers(false);
t->set_announce_to_lsd(false);

View File

@ -2276,7 +2276,7 @@ bool is_downloading_state(int const st)
m_num_checked_pieces = piece_index_t(0);
set_state(torrent_status::checking_files);
if (m_auto_managed) pause(true);
if (m_auto_managed) pause(torrent_handle::graceful_pause);
if (should_check_files()) start_checking();
else m_ses.trigger_auto_manage();
}
@ -2460,7 +2460,7 @@ bool is_downloading_state(int const st)
// managed logic runs again (which is triggered further down)
// setting flags to 0 prevents the disk cache from being evicted as a
// result of this
set_paused(true, 0);
set_paused(true, {});
}
// we're done checking! (this should cause a call to trigger_auto_manage)
@ -8494,7 +8494,7 @@ bool is_downloading_state(int const st)
return m_paused || m_session_paused;
}
void torrent::pause(bool const graceful)
void torrent::pause(pause_flags_t const flags)
{
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
@ -8505,11 +8505,10 @@ bool is_downloading_state(int const st)
set_need_save_resume();
}
int const flags = graceful ? flag_graceful_pause : 0;
set_paused(true, flags | flag_clear_disk_cache);
set_paused(true, flags | torrent_handle::clear_disk_cache);
}
void torrent::do_pause(bool const clear_disk_cache)
void torrent::do_pause(pause_flags_t const flags)
{
TORRENT_ASSERT(is_single_thread());
if (!is_paused()) return;
@ -8579,7 +8578,7 @@ bool is_downloading_state(int const st)
{
// this will make the storage close all
// files and flush all cached data
if (m_storage && clear_disk_cache)
if (m_storage && (flags & torrent_handle::clear_disk_cache))
{
// the torrent_paused alert will be posted from on_torrent_paused
m_ses.disk_thread().async_stop_torrent(m_storage
@ -8682,7 +8681,7 @@ bool is_downloading_state(int const st)
else do_resume();
}
void torrent::set_paused(bool const b, int flags)
void torrent::set_paused(bool const b, pause_flags_t flags)
{
TORRENT_ASSERT(is_single_thread());
@ -8692,7 +8691,7 @@ bool is_downloading_state(int const st)
// if there are no peers, we must not enter graceful pause mode, and post
// the torrent_paused_alert immediately instead.
if (num_peers() == 0)
flags &= ~flag_graceful_pause;
flags &= ~torrent_handle::graceful_pause;
if (m_paused == b)
{
@ -8701,7 +8700,7 @@ bool is_downloading_state(int const st)
// paused mode, we need to actually pause the torrent properly
if (m_paused == true
&& m_graceful_pause_mode == true
&& (flags & flag_graceful_pause) == 0)
&& !(flags & torrent_handle::graceful_pause))
{
m_graceful_pause_mode = false;
update_gauge();
@ -8718,9 +8717,9 @@ bool is_downloading_state(int const st)
// the effective state of the torrent did not change
if (paused_before == is_paused()) return;
m_graceful_pause_mode = (flags & flag_graceful_pause) ? true : false;
m_graceful_pause_mode = bool(flags & torrent_handle::graceful_pause);
if (b) do_pause((flags & flag_clear_disk_cache) != 0);
if (b) do_pause(flags & torrent_handle::clear_disk_cache);
else do_resume();
}

View File

@ -64,6 +64,7 @@ namespace libtorrent {
constexpr resume_data_flags_t torrent_handle::only_if_modified;
constexpr add_piece_flags_t torrent_handle::overwrite_existing;
constexpr pause_flags_t torrent_handle::graceful_pause;
constexpr pause_flags_t torrent_handle::clear_disk_cache;
constexpr deadline_flags_t torrent_handle::alert_when_available;
constexpr status_flags_t torrent_handle::query_distributed_copies;
@ -276,7 +277,7 @@ namespace libtorrent {
void torrent_handle::pause(pause_flags_t const flags) const
{
async_call(&torrent::pause, bool(flags & graceful_pause));
async_call(&torrent::pause, flags & graceful_pause);
}
torrent_flags_t torrent_handle::flags() const