forked from premiere/premiere-libtorrent
make resume_data_flags type safe
This commit is contained in:
parent
8d0f38930e
commit
5222d92e9f
|
@ -299,6 +299,7 @@ void bind_converters()
|
|||
to_python_converter<lt::file_open_mode_t, from_bitfield_flag<lt::file_open_mode_t>>();
|
||||
to_python_converter<lt::picker_flags_t, from_bitfield_flag<lt::picker_flags_t>>();
|
||||
to_python_converter<lt::alert_category_t, from_bitfield_flag<lt::alert_category_t>>();
|
||||
to_python_converter<lt::resume_data_flags_t, from_bitfield_flag<lt::resume_data_flags_t>>();
|
||||
|
||||
// work-around types
|
||||
to_python_converter<lt::aux::noexcept_movable<lt::address>, address_to_tuple<
|
||||
|
@ -348,4 +349,5 @@ void bind_converters()
|
|||
to_bitfield_flag<lt::file_open_mode_t>();
|
||||
to_bitfield_flag<lt::picker_flags_t>();
|
||||
to_bitfield_flag<lt::alert_category_t>();
|
||||
to_bitfield_flag<lt::resume_data_flags_t>();
|
||||
}
|
||||
|
|
|
@ -428,6 +428,7 @@ void add_piece(torrent_handle& th, piece_index_t piece, char const *data, int fl
|
|||
}
|
||||
|
||||
class dummy {};
|
||||
class dummy4 {};
|
||||
|
||||
using by_value = return_value_policy<return_by_value>;
|
||||
void bind_torrent_handle()
|
||||
|
@ -603,11 +604,12 @@ void bind_torrent_handle()
|
|||
.value("graceful_pause", torrent_handle::graceful_pause)
|
||||
;
|
||||
|
||||
enum_<torrent_handle::save_resume_flags_t>("save_resume_flags_t")
|
||||
.value("flush_disk_cache", torrent_handle::flush_disk_cache)
|
||||
.value("save_info_dict", torrent_handle::save_info_dict)
|
||||
.value("only_if_modified", torrent_handle::only_if_modified)
|
||||
;
|
||||
{
|
||||
scope s = class_<dummy4>("save_resume_flags_t");
|
||||
s.attr("flush_disk_cache") = torrent_handle::flush_disk_cache;
|
||||
s.attr("save_info_dict") = torrent_handle::save_info_dict;
|
||||
s.attr("only_if_modified") = torrent_handle::only_if_modified;
|
||||
}
|
||||
|
||||
enum_<torrent_handle::deadline_flags>("deadline_flags")
|
||||
.value("alert_when_available", torrent_handle::alert_when_available)
|
||||
|
|
|
@ -529,7 +529,7 @@ namespace libtorrent {
|
|||
bool is_paused() const;
|
||||
bool is_torrent_paused() const { return m_paused; }
|
||||
void force_recheck();
|
||||
void save_resume_data(int flags);
|
||||
void save_resume_data(resume_data_flags_t flags);
|
||||
|
||||
bool need_save_resume_data() const { return m_need_save_resume_data; }
|
||||
|
||||
|
@ -1532,7 +1532,7 @@ namespace libtorrent {
|
|||
|
||||
// these are the flags sent in on a call to save_resume_data
|
||||
// we need to save them to check them in write_resume_data
|
||||
std::uint32_t m_save_resume_flags:8;
|
||||
resume_data_flags_t m_save_resume_flags;
|
||||
|
||||
// ----
|
||||
|
||||
|
|
|
@ -57,10 +57,12 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/torrent_flags.hpp"
|
||||
#include "libtorrent/peer_info.hpp" // for peer_source_flags_t
|
||||
|
||||
namespace libtorrent { namespace aux {
|
||||
namespace libtorrent {
|
||||
namespace aux {
|
||||
|
||||
struct session_impl;
|
||||
}
|
||||
struct session_impl;
|
||||
|
||||
}
|
||||
|
||||
class entry;
|
||||
struct open_file_state;
|
||||
|
@ -80,6 +82,9 @@ namespace libtorrent { namespace aux {
|
|||
void TORRENT_NO_RETURN throw_invalid_handle();
|
||||
#endif
|
||||
|
||||
struct resume_data_flags_tag;
|
||||
using resume_data_flags_t = flags::bitfield_flag<std::uint8_t, resume_data_flags_tag>;
|
||||
|
||||
// holds the state of a block in a piece. Who we requested
|
||||
// it from and how far along we are at downloading it.
|
||||
struct TORRENT_EXPORT block_info
|
||||
|
@ -611,35 +616,27 @@ namespace libtorrent { namespace aux {
|
|||
// will start connecting to peers again, as normal.
|
||||
void force_recheck() const;
|
||||
|
||||
// flags used in the save_resume_data call to control additional
|
||||
// actions or fields to save.
|
||||
enum save_resume_flags_t
|
||||
{
|
||||
// the disk cache will be flushed before creating the resume data.
|
||||
// This avoids a problem with file timestamps in the resume data in
|
||||
// case the cache hasn't been flushed yet.
|
||||
flush_disk_cache = 1,
|
||||
// the disk cache will be flushed before creating the resume data.
|
||||
// This avoids a problem with file timestamps in the resume data in
|
||||
// case the cache hasn't been flushed yet.
|
||||
static constexpr resume_data_flags_t flush_disk_cache{1};
|
||||
|
||||
// the resume data will contain the metadata from the torrent file as
|
||||
// well. This is default for any torrent that's added without a
|
||||
// torrent file (such as a magnet link or a URL).
|
||||
save_info_dict = 2,
|
||||
// the resume data will contain the metadata from the torrent file as
|
||||
// well. This is default for any torrent that's added without a
|
||||
// torrent file (such as a magnet link or a URL).
|
||||
static constexpr resume_data_flags_t save_info_dict{2};
|
||||
|
||||
// if nothing significant has changed in the torrent since the last
|
||||
// time resume data was saved, fail this attempt. Significant changes
|
||||
// primarily include more data having been downloaded, file or piece
|
||||
// priorities having changed etc. If the resume data doesn't need
|
||||
// saving, a save_resume_data_failed_alert is posted with the error
|
||||
// resume_data_not_modified.
|
||||
only_if_modified = 4
|
||||
};
|
||||
// if nothing significant has changed in the torrent since the last
|
||||
// time resume data was saved, fail this attempt. Significant changes
|
||||
// primarily include more data having been downloaded, file or piece
|
||||
// priorities having changed etc. If the resume data doesn't need
|
||||
// saving, a save_resume_data_failed_alert is posted with the error
|
||||
// resume_data_not_modified.
|
||||
static constexpr resume_data_flags_t only_if_modified{4};
|
||||
|
||||
// ``save_resume_data()`` asks libtorrent to generate fast-resume data for
|
||||
// this torrent.
|
||||
//
|
||||
// The ``flags`` argument is a bitmask of flags ORed together. see
|
||||
// save_resume_flags_t
|
||||
//
|
||||
// This operation is asynchronous, ``save_resume_data`` will return
|
||||
// immediately. The resume data is delivered when it's done through an
|
||||
// save_resume_data_alert.
|
||||
|
@ -760,7 +757,7 @@ namespace libtorrent { namespace aux {
|
|||
// the alert, but it has not been received yet. Those torrents would
|
||||
// report that they don't need to save resume data again, and skipped by
|
||||
// the initial loop, and thwart the counter otherwise.
|
||||
void save_resume_data(int flags = 0) const;
|
||||
void save_resume_data(resume_data_flags_t flags = {}) const;
|
||||
|
||||
// This function returns true if any whole chunk has been downloaded
|
||||
// since the torrent was first loaded or since the last time the resume
|
||||
|
|
|
@ -194,7 +194,7 @@ namespace libtorrent {
|
|||
, m_stop_when_ready(p.flags & torrent_flags::stop_when_ready)
|
||||
, m_need_save_resume_data(p.flags & torrent_flags::need_save_resume)
|
||||
, m_max_uploads((1 << 24) - 1)
|
||||
, m_save_resume_flags(0)
|
||||
, m_save_resume_flags()
|
||||
, m_num_uploads(0)
|
||||
, m_need_connect_boost(true)
|
||||
, m_lsd_seq(0)
|
||||
|
@ -8326,7 +8326,7 @@ namespace libtorrent {
|
|||
// TODO: add a flag to ignore stats, and only care about resume data for
|
||||
// content. For unchanged files, don't trigger a load of the metadata
|
||||
// just to save an empty resume data file
|
||||
void torrent::save_resume_data(int const flags)
|
||||
void torrent::save_resume_data(resume_data_flags_t const flags)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
INVARIANT_CHECK;
|
||||
|
@ -8346,7 +8346,7 @@ namespace libtorrent {
|
|||
}
|
||||
|
||||
m_need_save_resume_data = false;
|
||||
m_save_resume_flags = aux::numeric_cast<std::uint8_t>(flags);
|
||||
m_save_resume_flags = flags;
|
||||
state_updated();
|
||||
|
||||
if ((flags & torrent_handle::flush_disk_cache) && m_storage)
|
||||
|
|
|
@ -58,6 +58,10 @@ using libtorrent::aux::session_impl;
|
|||
|
||||
namespace libtorrent {
|
||||
|
||||
constexpr resume_data_flags_t torrent_handle::flush_disk_cache;
|
||||
constexpr resume_data_flags_t torrent_handle::save_info_dict;
|
||||
constexpr resume_data_flags_t torrent_handle::only_if_modified;
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
void TORRENT_NO_RETURN throw_invalid_handle()
|
||||
{
|
||||
|
@ -344,7 +348,7 @@ namespace libtorrent {
|
|||
#endif
|
||||
}
|
||||
|
||||
void torrent_handle::save_resume_data(int f) const
|
||||
void torrent_handle::save_resume_data(resume_data_flags_t f) const
|
||||
{
|
||||
async_call(&torrent::save_resume_data, f);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue