some cleanup of type-safe flags

This commit is contained in:
arvidn 2017-07-30 09:13:22 -07:00 committed by Arvid Norberg
parent 322007bb6a
commit 6fa181ece8
19 changed files with 195 additions and 173 deletions

View File

@ -241,7 +241,11 @@ struct from_bitfield_flag
static PyObject* convert(T const v) static PyObject* convert(T const v)
{ {
object o(static_cast<underlying_type>(v)); // this is because python uses "long int" to represent integral values
// internally, it cannot hold large unsigned values
auto const val = static_cast<underlying_type>(v)
& static_cast<std::uint64_t>(std::numeric_limits<long int>::max());
object o(val);
return incref(o.ptr()); return incref(o.ptr());
} }
}; };

View File

@ -98,89 +98,89 @@ namespace libtorrent {
// * .torrent files errors // * .torrent files errors
// * listen socket errors // * listen socket errors
// * port mapping errors // * port mapping errors
static constexpr alert_category_t error_notification{0x1}; static constexpr alert_category_t error_notification = 0_bit;
// Enables alerts when peers send invalid requests, get banned or // Enables alerts when peers send invalid requests, get banned or
// snubbed. // snubbed.
static constexpr alert_category_t peer_notification{0x2}; static constexpr alert_category_t peer_notification = 1_bit;
// Enables alerts for port mapping events. For NAT-PMP and UPnP. // Enables alerts for port mapping events. For NAT-PMP and UPnP.
static constexpr alert_category_t port_mapping_notification{0x4}; static constexpr alert_category_t port_mapping_notification = 2_bit;
// Enables alerts for events related to the storage. File errors and // Enables alerts for events related to the storage. File errors and
// synchronization events for moving the storage, renaming files etc. // synchronization events for moving the storage, renaming files etc.
static constexpr alert_category_t storage_notification{0x8}; static constexpr alert_category_t storage_notification = 3_bit;
// Enables all tracker events. Includes announcing to trackers, // Enables all tracker events. Includes announcing to trackers,
// receiving responses, warnings and errors. // receiving responses, warnings and errors.
static constexpr alert_category_t tracker_notification{0x10}; static constexpr alert_category_t tracker_notification = 4_bit;
// Low level alerts for when peers are connected and disconnected. // Low level alerts for when peers are connected and disconnected.
static constexpr alert_category_t debug_notification{0x20}; static constexpr alert_category_t debug_notification = 5_bit;
// Enables alerts for when a torrent or the session changes state. // Enables alerts for when a torrent or the session changes state.
static constexpr alert_category_t status_notification{0x40}; static constexpr alert_category_t status_notification = 6_bit;
// Alerts for when blocks are requested and completed. Also when // Alerts for when blocks are requested and completed. Also when
// pieces are completed. // pieces are completed.
static constexpr alert_category_t progress_notification{0x80}; static constexpr alert_category_t progress_notification = 7_bit;
// Alerts when a peer is blocked by the ip blocker or port blocker. // Alerts when a peer is blocked by the ip blocker or port blocker.
static constexpr alert_category_t ip_block_notification{0x100}; static constexpr alert_category_t ip_block_notification = 8_bit;
// Alerts when some limit is reached that might limit the download // Alerts when some limit is reached that might limit the download
// or upload rate. // or upload rate.
static constexpr alert_category_t performance_warning{0x200}; static constexpr alert_category_t performance_warning = 9_bit;
// Alerts on events in the DHT node. For incoming searches or // Alerts on events in the DHT node. For incoming searches or
// bootstrapping being done etc. // bootstrapping being done etc.
static constexpr alert_category_t dht_notification{0x400}; static constexpr alert_category_t dht_notification = 10_bit;
// If you enable these alerts, you will receive a stats_alert // If you enable these alerts, you will receive a stats_alert
// approximately once every second, for every active torrent. // approximately once every second, for every active torrent.
// These alerts contain all statistics counters for the interval since // These alerts contain all statistics counters for the interval since
// the lasts stats alert. // the lasts stats alert.
static constexpr alert_category_t stats_notification{0x800}; static constexpr alert_category_t stats_notification = 11_bit;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
// Alerts on RSS related events, like feeds being updated, feed error // Alerts on RSS related events, like feeds being updated, feed error
// conditions and successful RSS feed updates. Enabling this category // conditions and successful RSS feed updates. Enabling this category
// will make you receive rss_alert alerts. // will make you receive rss_alert alerts.
static constexpr alert_category_t TORRENT_DEPRECATED_MEMBER rss_notification{0x1000}; static constexpr alert_category_t TORRENT_DEPRECATED_MEMBER rss_notification = 12_bit;
#endif #endif
// Enables debug logging alerts. These are available unless libtorrent // Enables debug logging alerts. These are available unless libtorrent
// was built with logging disabled (``TORRENT_DISABLE_LOGGING``). The // was built with logging disabled (``TORRENT_DISABLE_LOGGING``). The
// alerts being posted are log_alert and are session wide. // alerts being posted are log_alert and are session wide.
static constexpr alert_category_t session_log_notification{0x2000}; static constexpr alert_category_t session_log_notification = 13_bit;
// Enables debug logging alerts for torrents. These are available // Enables debug logging alerts for torrents. These are available
// unless libtorrent was built with logging disabled // unless libtorrent was built with logging disabled
// (``TORRENT_DISABLE_LOGGING``). The alerts being posted are // (``TORRENT_DISABLE_LOGGING``). The alerts being posted are
// torrent_log_alert and are torrent wide debug events. // torrent_log_alert and are torrent wide debug events.
static constexpr alert_category_t torrent_log_notification{0x4000}; static constexpr alert_category_t torrent_log_notification = 14_bit;
// Enables debug logging alerts for peers. These are available unless // Enables debug logging alerts for peers. These are available unless
// libtorrent was built with logging disabled // libtorrent was built with logging disabled
// (``TORRENT_DISABLE_LOGGING``). The alerts being posted are // (``TORRENT_DISABLE_LOGGING``). The alerts being posted are
// peer_log_alert and low-level peer events and messages. // peer_log_alert and low-level peer events and messages.
static constexpr alert_category_t peer_log_notification{0x8000}; static constexpr alert_category_t peer_log_notification = 15_bit;
// enables the incoming_request_alert. // enables the incoming_request_alert.
static constexpr alert_category_t incoming_request_notification{0x10000}; static constexpr alert_category_t incoming_request_notification = 16_bit;
// enables dht_log_alert, debug logging for the DHT // enables dht_log_alert, debug logging for the DHT
static constexpr alert_category_t dht_log_notification{0x20000}; static constexpr alert_category_t dht_log_notification = 17_bit;
// enable events from pure dht operations not related to torrents // enable events from pure dht operations not related to torrents
static constexpr alert_category_t dht_operation_notification{0x40000}; static constexpr alert_category_t dht_operation_notification = 18_bit;
// enables port mapping log events. This log is useful // enables port mapping log events. This log is useful
// for debugging the UPnP or NAT-PMP implementation // for debugging the UPnP or NAT-PMP implementation
static constexpr alert_category_t port_mapping_log_notification{0x80000}; static constexpr alert_category_t port_mapping_log_notification = 19_bit;
// enables verbose logging from the piece picker. // enables verbose logging from the piece picker.
static constexpr alert_category_t picker_log_notification{0x100000}; static constexpr alert_category_t picker_log_notification = 20_bit;
// The full bitmask, representing all available categories. // The full bitmask, representing all available categories.
// //
@ -188,7 +188,7 @@ namespace libtorrent {
// interpreted as -1. For instance, boost.python // interpreted as -1. For instance, boost.python
// does that and fails when assigning it to an // does that and fails when assigning it to an
// unsigned parameter. // unsigned parameter.
static constexpr alert_category_t all_categories{0x7fffffff}; static constexpr alert_category_t all_categories = alert_category_t::all();
// hidden // hidden
alert(); alert();

View File

@ -2526,22 +2526,22 @@ namespace libtorrent {
static constexpr alert_category_t static_category = alert::picker_log_notification; static constexpr alert_category_t static_category = alert::picker_log_notification;
virtual std::string message() const override; virtual std::string message() const override;
static constexpr picker_flags_t partial_ratio{0x1}; static constexpr picker_flags_t partial_ratio = 0_bit;
static constexpr picker_flags_t prioritize_partials{0x2}; static constexpr picker_flags_t prioritize_partials = 1_bit;
static constexpr picker_flags_t rarest_first_partials{0x4}; static constexpr picker_flags_t rarest_first_partials = 2_bit;
static constexpr picker_flags_t rarest_first{0x8}; static constexpr picker_flags_t rarest_first = 3_bit;
static constexpr picker_flags_t reverse_rarest_first{0x10}; static constexpr picker_flags_t reverse_rarest_first = 4_bit;
static constexpr picker_flags_t suggested_pieces{0x20}; static constexpr picker_flags_t suggested_pieces = 5_bit;
static constexpr picker_flags_t prio_sequential_pieces{0x40}; static constexpr picker_flags_t prio_sequential_pieces = 6_bit;
static constexpr picker_flags_t sequential_pieces{0x80}; static constexpr picker_flags_t sequential_pieces = 7_bit;
static constexpr picker_flags_t reverse_pieces{0x100}; static constexpr picker_flags_t reverse_pieces = 8_bit;
static constexpr picker_flags_t time_critical{0x200}; static constexpr picker_flags_t time_critical = 9_bit;
static constexpr picker_flags_t random_pieces{0x400}; static constexpr picker_flags_t random_pieces = 10_bit;
static constexpr picker_flags_t prefer_contiguous{0x800}; static constexpr picker_flags_t prefer_contiguous = 11_bit;
static constexpr picker_flags_t reverse_sequential{0x1000}; static constexpr picker_flags_t reverse_sequential = 12_bit;
static constexpr picker_flags_t backup1{0x2000}; static constexpr picker_flags_t backup1 = 13_bit;
static constexpr picker_flags_t backup2{0x4000}; static constexpr picker_flags_t backup2 = 14_bit;
static constexpr picker_flags_t end_game{0x8000}; static constexpr picker_flags_t end_game = 15_bit;
// this is a bitmask of which features were enabled for this particular // this is a bitmask of which features were enabled for this particular
// pick. The bits are defined in the picker_flags_t enum. // pick. The bits are defined in the picker_flags_t enum.

View File

@ -48,9 +48,9 @@ namespace libtorrent {
namespace string namespace string
{ {
// use lower case alphabet used with i2p // use lower case alphabet used with i2p
constexpr encode_string_flags_t lowercase{0x1}; constexpr encode_string_flags_t lowercase = 0_bit;
// don't insert padding // don't insert padding
constexpr encode_string_flags_t no_padding{0x2}; constexpr encode_string_flags_t no_padding = 1_bit;
// shortcut used for addresses as sha256 hashes // shortcut used for addresses as sha256 hashes
constexpr encode_string_flags_t i2p = lowercase | no_padding; constexpr encode_string_flags_t i2p = lowercase | no_padding;
} }

View File

@ -69,33 +69,33 @@ namespace libtorrent {
namespace file_open_mode namespace file_open_mode
{ {
// open the file for reading only // open the file for reading only
constexpr file_open_mode_t read_only{0}; constexpr file_open_mode_t read_only{};
// open the file for writing only // open the file for writing only
constexpr file_open_mode_t write_only{1}; constexpr file_open_mode_t write_only = 0_bit;
// open the file for reading and writing // open the file for reading and writing
constexpr file_open_mode_t read_write{2}; constexpr file_open_mode_t read_write = 1_bit;
// the mask for the bits determining read or write mode // the mask for the bits determining read or write mode
constexpr file_open_mode_t rw_mask = read_only | write_only | read_write; constexpr file_open_mode_t rw_mask = read_only | write_only | read_write;
// open the file in sparse mode (if supported by the // open the file in sparse mode (if supported by the
// filesystem). // filesystem).
constexpr file_open_mode_t sparse{0x4}; constexpr file_open_mode_t sparse = 2_bit;
// don't update the access timestamps on the file (if // don't update the access timestamps on the file (if
// supported by the operating system and filesystem). // supported by the operating system and filesystem).
// this generally improves disk performance. // this generally improves disk performance.
constexpr file_open_mode_t no_atime{0x8}; constexpr file_open_mode_t no_atime = 3_bit;
// open the file for random access. This disables read-ahead // open the file for random access. This disables read-ahead
// logic // logic
constexpr file_open_mode_t random_access{0x10}; constexpr file_open_mode_t random_access = 5_bit;
// prevent the file from being opened by another process // prevent the file from being opened by another process
// while it's still being held open by this handle // while it's still being held open by this handle
constexpr file_open_mode_t locked{0x20}; constexpr file_open_mode_t locked = 6_bit;
} }
// this contains information about a file that's currently open by the // this contains information about a file that's currently open by the

View File

@ -128,32 +128,32 @@ namespace libtorrent {
namespace open_mode { namespace open_mode {
// open the file for reading only // open the file for reading only
constexpr open_mode_t read_only{0}; constexpr open_mode_t read_only{};
// open the file for writing only // open the file for writing only
constexpr open_mode_t write_only{1}; constexpr open_mode_t write_only = 0_bit;
// open the file for reading and writing // open the file for reading and writing
constexpr open_mode_t read_write{2}; constexpr open_mode_t read_write = 1_bit;
constexpr open_mode_t rw_mask = read_only | write_only | read_write; constexpr open_mode_t rw_mask = read_only | write_only | read_write;
// open the file in sparse mode (if supported by the // open the file in sparse mode (if supported by the
// filesystem). // filesystem).
constexpr open_mode_t sparse{0x4}; constexpr open_mode_t sparse = 2_bit;
// don't update the access timestamps on the file (if // don't update the access timestamps on the file (if
// supported by the operating system and filesystem). // supported by the operating system and filesystem).
// this generally improves disk performance. // this generally improves disk performance.
constexpr open_mode_t no_atime{0x8}; constexpr open_mode_t no_atime = 3_bit;
// open the file for random access. This disables read-ahead // open the file for random access. This disables read-ahead
// logic // logic
constexpr open_mode_t random_access{0x10}; constexpr open_mode_t random_access = 4_bit;
// prevent the file from being opened by another process // prevent the file from being opened by another process
// while it's still being held open by this handle // while it's still being held open by this handle
constexpr open_mode_t lock_file{0x20}; constexpr open_mode_t lock_file = 5_bit;
// don't put any pressure on the OS disk cache // don't put any pressure on the OS disk cache
// because of access to this file. We expect our // because of access to this file. We expect our
@ -161,16 +161,16 @@ namespace libtorrent {
// a cache at the bittorrent block level. This // a cache at the bittorrent block level. This
// may improve overall system performance by // may improve overall system performance by
// leaving running applications in the page cache // leaving running applications in the page cache
constexpr open_mode_t no_cache{0x40}; constexpr open_mode_t no_cache = 6_bit;
// this is only used for readv/writev flags // this is only used for readv/writev flags
constexpr open_mode_t coalesce_buffers{0x100}; constexpr open_mode_t coalesce_buffers = 7_bit;
// when creating a file, set the hidden attribute (windows only) // when creating a file, set the hidden attribute (windows only)
constexpr open_mode_t attribute_hidden{0x200}; constexpr open_mode_t attribute_hidden = 8_bit;
// when creating a file, set the executable attribute // when creating a file, set the executable attribute
constexpr open_mode_t attribute_executable{0x400}; constexpr open_mode_t attribute_executable = 9_bit;
// the mask of all attribute bits // the mask of all attribute bits
constexpr open_mode_t attribute_mask = attribute_hidden | attribute_executable; constexpr open_mode_t attribute_mask = attribute_hidden | attribute_executable;

View File

@ -37,18 +37,33 @@ POSSIBILITY OF SUCH DAMAGE.
#include <iosfwd> #include <iosfwd>
namespace libtorrent { namespace libtorrent {
struct bit_t
{
explicit constexpr bit_t(int b) : m_bit_idx(b) {}
explicit constexpr operator int() const { return m_bit_idx; }
private:
int m_bit_idx;
};
constexpr bit_t operator "" _bit(unsigned long long int b) { return bit_t{static_cast<int>(b)}; }
namespace flags { namespace flags {
template<typename UnderlyingType, typename Tag template<typename UnderlyingType, typename Tag
, typename Cond = typename std::enable_if<std::is_integral<UnderlyingType>::value>::type> , typename Cond = typename std::enable_if<std::is_integral<UnderlyingType>::value>::type>
struct bitfield_flag struct bitfield_flag
{ {
static_assert(std::is_unsigned<UnderlyingType>::value
, "flags must use unsigned integers as underlying types");
using underlying_type = UnderlyingType; using underlying_type = UnderlyingType;
constexpr bitfield_flag(bitfield_flag const& rhs) noexcept = default; constexpr bitfield_flag(bitfield_flag const& rhs) noexcept = default;
constexpr bitfield_flag(bitfield_flag&& rhs) noexcept = default; constexpr bitfield_flag(bitfield_flag&& rhs) noexcept = default;
constexpr bitfield_flag() noexcept : m_val(0) {} constexpr bitfield_flag() noexcept : m_val(0) {}
explicit constexpr bitfield_flag(UnderlyingType val) noexcept : m_val(val) {} explicit constexpr bitfield_flag(UnderlyingType const val) noexcept : m_val(val) {}
constexpr bitfield_flag(bit_t const bit) noexcept : m_val(static_cast<UnderlyingType>(UnderlyingType{1} << static_cast<int>(bit))) {}
#ifdef TORRENT_NO_DEPRECATE #ifdef TORRENT_NO_DEPRECATE
explicit constexpr operator UnderlyingType() const noexcept { return m_val; } explicit constexpr operator UnderlyingType() const noexcept { return m_val; }
#else #else
@ -56,6 +71,11 @@ struct bitfield_flag
#endif #endif
explicit constexpr operator bool() const noexcept { return m_val != 0; } explicit constexpr operator bool() const noexcept { return m_val != 0; }
static constexpr bitfield_flag all()
{
return bitfield_flag(~UnderlyingType{0});
}
bool constexpr operator==(bitfield_flag const f) const noexcept bool constexpr operator==(bitfield_flag const f) const noexcept
{ return m_val == f.m_val; } { return m_val == f.m_val; }
@ -115,7 +135,5 @@ private:
} // flags } // flags
} // libtorrent } // libtorrent
#undef ENUM_OPERATOR
#endif #endif

View File

@ -587,8 +587,8 @@ namespace aux {
// if the block was already time-critical, it returns false. // if the block was already time-critical, it returns false.
bool make_time_critical(piece_block const& block); bool make_time_critical(piece_block const& block);
static constexpr request_flags_t time_critical{1}; static constexpr request_flags_t time_critical = 0_bit;
static constexpr request_flags_t busy{2}; static constexpr request_flags_t busy = 1_bit;
// adds a block to the request queue // adds a block to the request queue
// returns true if successful, false otherwise // returns true if successful, false otherwise

View File

@ -94,44 +94,44 @@ namespace libtorrent {
time_duration download_queue_time; time_duration download_queue_time;
// **we** are interested in pieces from this peer. // **we** are interested in pieces from this peer.
static constexpr peer_flags_t interesting{0x1}; static constexpr peer_flags_t interesting = 0_bit;
// **we** have choked this peer. // **we** have choked this peer.
static constexpr peer_flags_t choked{0x2}; static constexpr peer_flags_t choked = 1_bit;
// the peer is interested in **us** // the peer is interested in **us**
static constexpr peer_flags_t remote_interested{0x4}; static constexpr peer_flags_t remote_interested = 2_bit;
// the peer has choked **us**. // the peer has choked **us**.
static constexpr peer_flags_t remote_choked{0x8}; static constexpr peer_flags_t remote_choked = 3_bit;
// means that this peer supports the // means that this peer supports the
// `extension protocol`__. // `extension protocol`__.
// //
// __ extension_protocol.html // __ extension_protocol.html
static constexpr peer_flags_t supports_extensions{0x10}; static constexpr peer_flags_t supports_extensions = 4_bit;
// The connection was initiated by us, the peer has a // The connection was initiated by us, the peer has a
// listen port open, and that port is the same as in the // listen port open, and that port is the same as in the
// address of this peer. If this flag is not set, this // address of this peer. If this flag is not set, this
// peer connection was opened by this peer connecting to // peer connection was opened by this peer connecting to
// us. // us.
static constexpr peer_flags_t local_connection{0x20}; static constexpr peer_flags_t local_connection = 5_bit;
// The connection is opened, and waiting for the // The connection is opened, and waiting for the
// handshake. Until the handshake is done, the peer // handshake. Until the handshake is done, the peer
// cannot be identified. // cannot be identified.
static constexpr peer_flags_t handshake{0x40}; static constexpr peer_flags_t handshake = 6_bit;
// The connection is in a half-open state (i.e. it is // The connection is in a half-open state (i.e. it is
// being connected). // being connected).
static constexpr peer_flags_t connecting{0x80}; static constexpr peer_flags_t connecting = 7_bit;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
// The connection is currently queued for a connection // The connection is currently queued for a connection
// attempt. This may happen if there is a limit set on // attempt. This may happen if there is a limit set on
// the number of half-open TCP connections. // the number of half-open TCP connections.
static constexpr peer_flags_t queued{0x100}; static constexpr peer_flags_t queued = 8_bit;
#endif #endif
// The peer has participated in a piece that failed the // The peer has participated in a piece that failed the
@ -139,83 +139,83 @@ namespace libtorrent {
// only requesting whole pieces from this peer until // only requesting whole pieces from this peer until
// it either fails that piece or proves that it doesn't // it either fails that piece or proves that it doesn't
// send bad data. // send bad data.
static constexpr peer_flags_t on_parole{0x200}; static constexpr peer_flags_t on_parole = 9_bit;
// This peer is a seed (it has all the pieces). // This peer is a seed (it has all the pieces).
static constexpr peer_flags_t seed{0x400}; static constexpr peer_flags_t seed = 10_bit;
// This peer is subject to an optimistic unchoke. It has // This peer is subject to an optimistic unchoke. It has
// been unchoked for a while to see if it might unchoke // been unchoked for a while to see if it might unchoke
// us in return an earn an upload/unchoke slot. If it // us in return an earn an upload/unchoke slot. If it
// doesn't within some period of time, it will be choked // doesn't within some period of time, it will be choked
// and another peer will be optimistically unchoked. // and another peer will be optimistically unchoked.
static constexpr peer_flags_t optimistic_unchoke{0x800}; static constexpr peer_flags_t optimistic_unchoke = 11_bit;
// This peer has recently failed to send a block within // This peer has recently failed to send a block within
// the request timeout from when the request was sent. // the request timeout from when the request was sent.
// We're currently picking one block at a time from this // We're currently picking one block at a time from this
// peer. // peer.
static constexpr peer_flags_t snubbed{0x1000}; static constexpr peer_flags_t snubbed = 12_bit;
// This peer has either explicitly (with an extension) // This peer has either explicitly (with an extension)
// or implicitly (by becoming a seed) told us that it // or implicitly (by becoming a seed) told us that it
// will not downloading anything more, regardless of // will not downloading anything more, regardless of
// which pieces we have. // which pieces we have.
static constexpr peer_flags_t upload_only{0x2000}; static constexpr peer_flags_t upload_only = 13_bit;
// This means the last time this peer picket a piece, // This means the last time this peer picket a piece,
// it could not pick as many as it wanted because there // it could not pick as many as it wanted because there
// were not enough free ones. i.e. all pieces this peer // were not enough free ones. i.e. all pieces this peer
// has were already requested from other peers. // has were already requested from other peers.
static constexpr peer_flags_t endgame_mode{0x4000}; static constexpr peer_flags_t endgame_mode = 14_bit;
// This flag is set if the peer was in holepunch mode // This flag is set if the peer was in holepunch mode
// when the connection succeeded. This typically only // when the connection succeeded. This typically only
// happens if both peers are behind a NAT and the peers // happens if both peers are behind a NAT and the peers
// connect via the NAT holepunch mechanism. // connect via the NAT holepunch mechanism.
static constexpr peer_flags_t holepunched{0x8000}; static constexpr peer_flags_t holepunched = 15_bit;
// indicates that this socket is running on top of the // indicates that this socket is running on top of the
// I2P transport. // I2P transport.
static constexpr peer_flags_t i2p_socket{0x10000}; static constexpr peer_flags_t i2p_socket = 16_bit;
// indicates that this socket is a uTP socket // indicates that this socket is a uTP socket
static constexpr peer_flags_t utp_socket{0x20000}; static constexpr peer_flags_t utp_socket = 17_bit;
// indicates that this socket is running on top of an SSL // indicates that this socket is running on top of an SSL
// (TLS) channel // (TLS) channel
static constexpr peer_flags_t ssl_socket{0x40000}; static constexpr peer_flags_t ssl_socket = 18_bit;
// this connection is obfuscated with RC4 // this connection is obfuscated with RC4
static constexpr peer_flags_t rc4_encrypted{0x100000}; static constexpr peer_flags_t rc4_encrypted = 19_bit;
// the handshake of this connection was obfuscated // the handshake of this connection was obfuscated
// with a Diffie-Hellman exchange // with a Diffie-Hellman exchange
static constexpr peer_flags_t plaintext_encrypted{0x200000}; static constexpr peer_flags_t plaintext_encrypted = 20_bit;
// tells you in which state the peer is in. It is set to // tells you in which state the peer is in. It is set to
// any combination of the peer_flags_t flags above. // any combination of the peer_flags_t flags above.
peer_flags_t flags; peer_flags_t flags;
// The peer was received from the tracker. // The peer was received from the tracker.
static constexpr peer_source_flags_t tracker{0x1}; static constexpr peer_source_flags_t tracker = 0_bit;
// The peer was received from the kademlia DHT. // The peer was received from the kademlia DHT.
static constexpr peer_source_flags_t dht{0x2}; static constexpr peer_source_flags_t dht = 1_bit;
// The peer was received from the peer exchange // The peer was received from the peer exchange
// extension. // extension.
static constexpr peer_source_flags_t pex{0x4}; static constexpr peer_source_flags_t pex = 2_bit;
// The peer was received from the local service // The peer was received from the local service
// discovery (The peer is on the local network). // discovery (The peer is on the local network).
static constexpr peer_source_flags_t lsd{0x8}; static constexpr peer_source_flags_t lsd = 3_bit;
// The peer was added from the fast resume data. // The peer was added from the fast resume data.
static constexpr peer_source_flags_t resume_data{0x10}; static constexpr peer_source_flags_t resume_data = 4_bit;
// we received an incoming connection from this peer // we received an incoming connection from this peer
static constexpr peer_source_flags_t incoming{0x20}; static constexpr peer_source_flags_t incoming = 5_bit;
// a combination of flags describing from which sources this peer // a combination of flags describing from which sources this peer
// was received. A combination of the peer_source_flags_t above. // was received. A combination of the peer_source_flags_t above.
@ -381,20 +381,20 @@ namespace libtorrent {
// The peer is not waiting for any external events to // The peer is not waiting for any external events to
// send or receive data. // send or receive data.
static constexpr bandwidth_state_flags_t bw_idle{0}; static constexpr bandwidth_state_flags_t bw_idle = 0_bit;
// The peer is waiting for the rate limiter. // The peer is waiting for the rate limiter.
static constexpr bandwidth_state_flags_t bw_limit{1}; static constexpr bandwidth_state_flags_t bw_limit = 1_bit;
// The peer has quota and is currently waiting for a // The peer has quota and is currently waiting for a
// network read or write operation to complete. This is // network read or write operation to complete. This is
// the state all peers are in if there are no bandwidth // the state all peers are in if there are no bandwidth
// limits. // limits.
static constexpr bandwidth_state_flags_t bw_network{2}; static constexpr bandwidth_state_flags_t bw_network = 2_bit;
// The peer is waiting for the disk I/O thread to catch // The peer is waiting for the disk I/O thread to catch
// up writing buffers to disk before downloading more. // up writing buffers to disk before downloading more.
static constexpr bandwidth_state_flags_t bw_disk{4}; static constexpr bandwidth_state_flags_t bw_disk = 4_bit;
// bitmasks indicating what state this peer // bitmasks indicating what state this peer
// is in with regards to sending and receiving data. The states are declared in the // is in with regards to sending and receiving data. The states are declared in the

View File

@ -55,11 +55,11 @@ struct TORRENT_EXTRA_EXPORT resolver_interface
// don't have a cache entry, regardless of how old it is. This is usefull // don't have a cache entry, regardless of how old it is. This is usefull
// when completing the lookup quickly is more important than accuracy, // when completing the lookup quickly is more important than accuracy,
// like on shutdown // like on shutdown
static constexpr resolver_flags cache_only{1}; static constexpr resolver_flags cache_only = 0_bit;
// set this flag for lookups that are not critical during shutdown. i.e. // set this flag for lookups that are not critical during shutdown. i.e.
// for looking up tracker names _except_ when stopping a tracker. // for looking up tracker names _except_ when stopping a tracker.
static constexpr resolver_flags abort_on_shutdown{2}; static constexpr resolver_flags abort_on_shutdown = 1_bit;
virtual void async_resolve(std::string const& host, resolver_flags flags virtual void async_resolve(std::string const& host, resolver_flags flags
, callback_t const& h) = 0; , callback_t const& h) = 0;

View File

@ -163,7 +163,7 @@ namespace aux {
// This function helps to construct a ``session_params`` from a // This function helps to construct a ``session_params`` from a
// bencoded data generated by ``session_handle::save_state`` // bencoded data generated by ``session_handle::save_state``
TORRENT_EXPORT session_params read_session_params(bdecode_node const& e TORRENT_EXPORT session_params read_session_params(bdecode_node const& e
, save_state_flags_t flags = save_state_flags_t{0xffffffff}); , save_state_flags_t flags = save_state_flags_t::all());
// The session holds all state that spans multiple torrents. Among other // The session holds all state that spans multiple torrents. Among other
// things it runs the network loop and manages all torrents. Once it's // things it runs the network loop and manages all torrents. Once it's

View File

@ -83,26 +83,26 @@ namespace libtorrent {
bool is_valid() const { return !m_impl.expired(); } bool is_valid() const { return !m_impl.expired(); }
// saves settings (i.e. the settings_pack) // saves settings (i.e. the settings_pack)
static constexpr save_state_flags_t save_settings{0x001}; static constexpr save_state_flags_t save_settings = 0_bit;
// saves dht_settings // saves dht_settings
static constexpr save_state_flags_t save_dht_settings{0x002}; static constexpr save_state_flags_t save_dht_settings = 1_bit;
// saves dht state such as nodes and node-id, possibly accelerating // saves dht state such as nodes and node-id, possibly accelerating
// joining the DHT if provided at next session startup. // joining the DHT if provided at next session startup.
static constexpr save_state_flags_t save_dht_state{0x004}; static constexpr save_state_flags_t save_dht_state = 2_bit;
// save pe_settings // save pe_settings
static constexpr save_state_flags_t save_encryption_settings{0x020}; static constexpr save_state_flags_t save_encryption_settings = 3_bit;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_as_map{0x040}; static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_as_map = 4_bit;
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_proxy{0x008}; static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_proxy = 5_bit;
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_i2p_proxy{0x010}; static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_i2p_proxy = 6_bit;
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_dht_proxy{0x008}; static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_dht_proxy = 7_bit;
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_peer_proxy{0x008}; static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_peer_proxy = 8_bit;
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_web_proxy{0x008}; static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_web_proxy = 9_bit;
static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_tracker_proxy{0x008}; static constexpr save_state_flags_t TORRENT_DEPRECATED_MEMBER save_tracker_proxy = 10_bit;
#endif #endif
// TODO: 2 the ip filter should probably be saved here too // TODO: 2 the ip filter should probably be saved here too
@ -122,8 +122,8 @@ namespace libtorrent {
// ``peer_fingerprint`` and ``user_agent``. Those are left as configured // ``peer_fingerprint`` and ``user_agent``. Those are left as configured
// by the ``session_settings`` passed to the session constructor or // by the ``session_settings`` passed to the session constructor or
// subsequently set via apply_settings(). // subsequently set via apply_settings().
void save_state(entry& e, save_state_flags_t flags = save_state_flags_t{0xffffffff}) const; void save_state(entry& e, save_state_flags_t flags = save_state_flags_t::all()) const;
void load_state(bdecode_node const& e, save_state_flags_t flags = save_state_flags_t{0xffffffff}); void load_state(bdecode_node const& e, save_state_flags_t flags = save_state_flags_t::all());
// .. note:: // .. note::
// these calls are potentially expensive and won't scale well with // these calls are potentially expensive and won't scale well with
@ -541,13 +541,13 @@ namespace libtorrent {
// use load_state and save_state instead // use load_state and save_state instead
TORRENT_DEPRECATED TORRENT_DEPRECATED
void load_state(entry const& ses_state void load_state(entry const& ses_state
, save_state_flags_t flags = save_state_flags_t(0xffffffff)); , save_state_flags_t flags = save_state_flags_t::all());
TORRENT_DEPRECATED TORRENT_DEPRECATED
entry state() const; entry state() const;
// deprecated in 1.1 // deprecated in 1.1
TORRENT_DEPRECATED TORRENT_DEPRECATED
void load_state(lazy_entry const& ses_state void load_state(lazy_entry const& ses_state
, save_state_flags_t flags = save_state_flags_t{0xffffffff}); , save_state_flags_t flags = save_state_flags_t::all());
#endif // TORRENT_NO_DEPRECATE #endif // TORRENT_NO_DEPRECATE
// Sets a filter that will be used to reject and accept incoming as well // Sets a filter that will be used to reject and accept incoming as well
@ -733,18 +733,18 @@ namespace libtorrent {
// delete the files belonging to the torrent from disk. // delete the files belonging to the torrent from disk.
// including the part-file, if there is one // including the part-file, if there is one
static constexpr remove_flags_t delete_files{1}; static constexpr remove_flags_t delete_files = 0_bit;
// delete just the part-file associated with this torrent // delete just the part-file associated with this torrent
static constexpr remove_flags_t delete_partfile{2}; static constexpr remove_flags_t delete_partfile = 1_bit;
// this will add common extensions like ut_pex, ut_metadata, lt_tex // this will add common extensions like ut_pex, ut_metadata, lt_tex
// smart_ban and possibly others. // smart_ban and possibly others.
static constexpr session_flags_t add_default_plugins{1}; static constexpr session_flags_t add_default_plugins = 0_bit;
// this will start features like DHT, local service discovery, UPnP // this will start features like DHT, local service discovery, UPnP
// and NAT-PMP. // and NAT-PMP.
static constexpr session_flags_t start_default_features{2}; static constexpr session_flags_t start_default_features = 1_bit;
// ``remove_torrent()`` will close all peer connections associated with // ``remove_torrent()`` will close all peer connections associated with
// the torrent and tell the tracker that we've stopped participating in // the torrent and tell the tracker that we've stopped participating in

View File

@ -61,7 +61,7 @@ namespace torrent_flags {
// //
// If resume data is passed in with this torrent, the seed mode saved // If resume data is passed in with this torrent, the seed mode saved
// in there will override the seed mode you set here. // in there will override the seed mode you set here.
constexpr torrent_flags_t seed_mode{0x001}; constexpr torrent_flags_t seed_mode = 0_bit;
// If ``upload_mode`` is set, the torrent will be initialized in // If ``upload_mode`` is set, the torrent will be initialized in
// upload-mode, which means it will not make any piece requests. This // upload-mode, which means it will not make any piece requests. This
@ -77,7 +77,7 @@ namespace torrent_flags {
// will eventually be taken out of upload-mode, regardless of how it // will eventually be taken out of upload-mode, regardless of how it
// got there. If it's important to manually control when the torrent // got there. If it's important to manually control when the torrent
// leaves upload mode, don't make it auto managed. // leaves upload mode, don't make it auto managed.
constexpr torrent_flags_t upload_mode{0x004}; constexpr torrent_flags_t upload_mode = 1_bit;
// determines if the torrent should be added in *share mode* or not. // determines if the torrent should be added in *share mode* or not.
// Share mode indicates that we are not interested in downloading the // Share mode indicates that we are not interested in downloading the
@ -97,21 +97,21 @@ namespace torrent_flags {
// //
// The share mode has one setting, the share ratio target, see // The share mode has one setting, the share ratio target, see
// ``settings_pack::share_mode_target`` for more info. // ``settings_pack::share_mode_target`` for more info.
constexpr torrent_flags_t share_mode{0x008}; constexpr torrent_flags_t share_mode = 2_bit;
// determines if the IP filter should apply to this torrent or not. By // determines if the IP filter should apply to this torrent or not. By
// default all torrents are subject to filtering by the IP filter // default all torrents are subject to filtering by the IP filter
// (i.e. this flag is set by default). This is useful if certain // (i.e. this flag is set by default). This is useful if certain
// torrents needs to be exempt for some reason, being an auto-update // torrents needs to be exempt for some reason, being an auto-update
// torrent for instance. // torrent for instance.
constexpr torrent_flags_t apply_ip_filter{0x010}; constexpr torrent_flags_t apply_ip_filter = 3_bit;
// specifies whether or not the torrent is to be started in a paused // specifies whether or not the torrent is to be started in a paused
// state. I.e. it won't connect to the tracker or any of the peers // state. I.e. it won't connect to the tracker or any of the peers
// until it's resumed. This is typically a good way of avoiding race // until it's resumed. This is typically a good way of avoiding race
// conditions when setting configuration options on torrents before // conditions when setting configuration options on torrents before
// starting them. // starting them.
constexpr torrent_flags_t paused{0x020}; constexpr torrent_flags_t paused = 4_bit;
// If the torrent is auto-managed (``auto_managed``), the torrent // If the torrent is auto-managed (``auto_managed``), the torrent
// may be resumed at any point, regardless of how it paused. If it's // may be resumed at any point, regardless of how it paused. If it's
@ -128,30 +128,23 @@ namespace torrent_flags {
// when the resume data was saved will override the auto_managed state // when the resume data was saved will override the auto_managed state
// you pass in here. You can override this by setting // you pass in here. You can override this by setting
// ``override_resume_data``. // ``override_resume_data``.
constexpr torrent_flags_t auto_managed{0x040}; constexpr torrent_flags_t auto_managed = 5_bit;
constexpr torrent_flags_t duplicate_is_error{0x080}; constexpr torrent_flags_t duplicate_is_error = 6_bit;
// on by default and means that this torrent will be part of state // on by default and means that this torrent will be part of state
// updates when calling post_torrent_updates(). // updates when calling post_torrent_updates().
constexpr torrent_flags_t update_subscribe{0x200}; constexpr torrent_flags_t update_subscribe = 7_bit;
// sets the torrent into super seeding mode. If the torrent is not a // sets the torrent into super seeding mode. If the torrent is not a
// seed, this flag has no effect. It has the same effect as calling // seed, this flag has no effect. It has the same effect as calling
// ``torrent_handle::super_seeding(true)`` on the torrent handle // ``torrent_handle::super_seeding(true)`` on the torrent handle
// immediately after adding it. // immediately after adding it.
constexpr torrent_flags_t super_seeding{0x400}; constexpr torrent_flags_t super_seeding = 8_bit;
// sets the sequential download state for the torrent. It has the same // sets the sequential download state for the torrent. It has the same
// effect as calling ``torrent_handle::sequential_download(true)`` on // effect as calling ``torrent_handle::sequential_download(true)`` on
// the torrent handle immediately after adding it. // the torrent handle immediately after adding it.
constexpr torrent_flags_t sequential_download{0x800}; constexpr torrent_flags_t sequential_download = 9_bit;
#ifndef TORRENT_NO_DEPRECATE
// indicates that this torrent should never be unloaded from RAM, even
// if unloading torrents are allowed in general. Setting this makes
// the torrent exempt from loading/unloading management.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER pinned{0x1000};
#endif
// When this flag is set, the // When this flag is set, the
// torrent will *force stop* whenever it transitions from a // torrent will *force stop* whenever it transitions from a
@ -182,27 +175,32 @@ namespace torrent_flags {
// for the state_changed_alert and then call pause(). The download/seeding // for the state_changed_alert and then call pause(). The download/seeding
// will most likely start in between posting the alert and receiving the // will most likely start in between posting the alert and receiving the
// call to pause. // call to pause.
constexpr torrent_flags_t stop_when_ready{0x2000}; constexpr torrent_flags_t stop_when_ready = 10_bit;
// when this flag is set, the tracker list in the add_torrent_params // when this flag is set, the tracker list in the add_torrent_params
// object override any trackers from the torrent file. If the flag is // object override any trackers from the torrent file. If the flag is
// not set, the trackers from the add_torrent_params object will be // not set, the trackers from the add_torrent_params object will be
// added to the list of trackers used by the torrent. // added to the list of trackers used by the torrent.
constexpr torrent_flags_t override_trackers{0x4000}; constexpr torrent_flags_t override_trackers = 11_bit;
// If this flag is set, the web seeds from the add_torrent_params // If this flag is set, the web seeds from the add_torrent_params
// object will override any web seeds in the torrent file. If it's not // object will override any web seeds in the torrent file. If it's not
// set, web seeds in the add_torrent_params object will be added to the // set, web seeds in the add_torrent_params object will be added to the
// list of web seeds used by the torrent. // list of web seeds used by the torrent.
constexpr torrent_flags_t override_web_seeds{0x8000}; constexpr torrent_flags_t override_web_seeds = 12_bit;
// if this flag is set (which it is by default) the torrent will be // if this flag is set (which it is by default) the torrent will be
// considered needing to save its resume data immediately as it's // considered needing to save its resume data immediately as it's
// added. New torrents that don't have any resume data should do that. // added. New torrents that don't have any resume data should do that.
// This flag is cleared by a successful call to save_resume_data() // This flag is cleared by a successful call to save_resume_data()
constexpr torrent_flags_t need_save_resume{0x10000}; constexpr torrent_flags_t need_save_resume = 13_bit;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
// indicates that this torrent should never be unloaded from RAM, even
// if unloading torrents are allowed in general. Setting this makes
// the torrent exempt from loading/unloading management.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER pinned = 14_bit;
// If ``override_resume_data`` is set, flags set for this torrent // If ``override_resume_data`` is set, flags set for this torrent
// in this ``add_torrent_params`` object will take precedence over // in this ``add_torrent_params`` object will take precedence over
// whatever states are saved in the resume data. For instance, the // whatever states are saved in the resume data. For instance, the
@ -214,7 +212,7 @@ namespace torrent_flags {
// configuration from the resume file, with the one exception of save // configuration from the resume file, with the one exception of save
// resume data, which has its own flag (for historic reasons). // resume data, which has its own flag (for historic reasons).
// "file_priorities" and "save_path" are not affected by this flag. // "file_priorities" and "save_path" are not affected by this flag.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER override_resume_data{0x20000}; constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER override_resume_data = 15_bit;
// defaults to on and specifies whether tracker URLs loaded from // defaults to on and specifies whether tracker URLs loaded from
// resume data should be added to the trackers in the torrent or // resume data should be added to the trackers in the torrent or
@ -223,12 +221,12 @@ namespace torrent_flags {
// replaced by any trackers in the resume data. The default behavior is // replaced by any trackers in the resume data. The default behavior is
// to have the resume data override the .torrent file _and_ the // to have the resume data override the .torrent file _and_ the
// trackers added in add_torrent_params. // trackers added in add_torrent_params.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER merge_resume_trackers{0x40000}; constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER merge_resume_trackers = 16_bit;
// if this flag is set, the save path from the resume data file, if // if this flag is set, the save path from the resume data file, if
// present, is honored. This defaults to not being set, in which // present, is honored. This defaults to not being set, in which
// case the save_path specified in add_torrent_params is always used. // case the save_path specified in add_torrent_params is always used.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER use_resume_save_path{0x80000}; constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER use_resume_save_path = 17_bit;
// defaults to on and specifies whether web seed URLs loaded from // defaults to on and specifies whether web seed URLs loaded from
// resume data should be added to the ones in the torrent file or // resume data should be added to the ones in the torrent file or
@ -238,10 +236,10 @@ namespace torrent_flags {
// add_torrent_params are also replaced. The default behavior is to // add_torrent_params are also replaced. The default behavior is to
// have any web seeds in the resume data take precedence over whatever // have any web seeds in the resume data take precedence over whatever
// is passed in here as well as the .torrent file. // is passed in here as well as the .torrent file.
constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER merge_resume_http_seeds{0x100000}; constexpr torrent_flags_t TORRENT_DEPRECATED_MEMBER merge_resume_http_seeds = 18_bit;
#endif #endif
constexpr torrent_flags_t all{0xffffffffffffffff}; constexpr torrent_flags_t all = torrent_flags_t::all();
// internal // internal
constexpr torrent_flags_t default_flags = constexpr torrent_flags_t default_flags =

View File

@ -284,7 +284,7 @@ namespace aux {
// instruct libtorrent to overwrite any data that may already have been // instruct libtorrent to overwrite any data that may already have been
// downloaded with the data of the new piece being added. // downloaded with the data of the new piece being added.
static constexpr add_piece_flags_t overwrite_existing{1}; static constexpr add_piece_flags_t overwrite_existing = 0_bit;
// This function will write ``data`` to the storage as piece ``piece``, // This function will write ``data`` to the storage as piece ``piece``,
// as if it had been downloaded from a peer. ``data`` is expected to // as if it had been downloaded from a peer. ``data`` is expected to
@ -334,28 +334,28 @@ namespace aux {
// calculates ``distributed_copies``, ``distributed_full_copies`` and // calculates ``distributed_copies``, ``distributed_full_copies`` and
// ``distributed_fraction``. // ``distributed_fraction``.
static constexpr status_flags_t query_distributed_copies{1}; static constexpr status_flags_t query_distributed_copies = 0_bit;
// includes partial downloaded blocks in ``total_done`` and // includes partial downloaded blocks in ``total_done`` and
// ``total_wanted_done``. // ``total_wanted_done``.
static constexpr status_flags_t query_accurate_download_counters{2}; static constexpr status_flags_t query_accurate_download_counters = 1_bit;
// includes ``last_seen_complete``. // includes ``last_seen_complete``.
static constexpr status_flags_t query_last_seen_complete{4}; static constexpr status_flags_t query_last_seen_complete = 2_bit;
// populate the ``pieces`` field in torrent_status. // populate the ``pieces`` field in torrent_status.
static constexpr status_flags_t query_pieces{8}; static constexpr status_flags_t query_pieces = 3_bit;
// includes ``verified_pieces`` (only applies to torrents in *seed // includes ``verified_pieces`` (only applies to torrents in *seed
// mode*). // mode*).
static constexpr status_flags_t query_verified_pieces{16}; static constexpr status_flags_t query_verified_pieces = 4_bit;
// includes ``torrent_file``, which is all the static information from // includes ``torrent_file``, which is all the static information from
// the .torrent file. // the .torrent file.
static constexpr status_flags_t query_torrent_file{32}; static constexpr status_flags_t query_torrent_file = 5_bit;
// includes ``name``, the name of the torrent. This is either derived // includes ``name``, the name of the torrent. This is either derived
// from the .torrent file, or from the ``&dn=`` magnet link argument // from the .torrent file, or from the ``&dn=`` magnet link argument
// or possibly some other source. If the name of the torrent is not // or possibly some other source. If the name of the torrent is not
// known, this is an empty string. // known, this is an empty string.
static constexpr status_flags_t query_name{64}; static constexpr status_flags_t query_name = 6_bit;
// includes ``save_path``, the path to the directory the files of the // includes ``save_path``, the path to the directory the files of the
// torrent are saved to. // torrent are saved to.
static constexpr status_flags_t query_save_path{128}; static constexpr status_flags_t query_save_path = 7_bit;
// ``status()`` will return a structure with information about the status // ``status()`` will return a structure with information about the status
// of this torrent. If the torrent_handle is invalid, it will throw // of this torrent. If the torrent_handle is invalid, it will throw
@ -367,7 +367,7 @@ namespace aux {
// //
// By default everything is included. The flags you can use to decide // By default everything is included. The flags you can use to decide
// what to *include* are defined in the status_flags_t enum. // what to *include* are defined in the status_flags_t enum.
torrent_status status(status_flags_t flags = status_flags_t{0x7fffffff}) const; torrent_status status(status_flags_t flags = status_flags_t::all()) const;
// ``get_download_queue()`` takes a non-const reference to a vector which // ``get_download_queue()`` takes a non-const reference to a vector which
// it will fill with information about pieces that are partially // it will fill with information about pieces that are partially
@ -379,7 +379,7 @@ namespace aux {
// downloaded, by passing alert_when_available. When set, the // downloaded, by passing alert_when_available. When set, the
// read_piece_alert alert will be delivered, with the piece data, when // read_piece_alert alert will be delivered, with the piece data, when
// it's downloaded. // it's downloaded.
static constexpr deadline_flags_t alert_when_available{1}; static constexpr deadline_flags_t alert_when_available = 0_bit;
// This function sets or resets the deadline associated with a specific // This function sets or resets the deadline associated with a specific
// piece index (``index``). libtorrent will attempt to download this // piece index (``index``). libtorrent will attempt to download this
@ -570,7 +570,7 @@ namespace aux {
// transferring the blocks that were requested from it, it is // transferring the blocks that were requested from it, it is
// disconnected. This is a graceful shut down of the torrent in the sense // disconnected. This is a graceful shut down of the torrent in the sense
// that no downloaded bytes are wasted. // that no downloaded bytes are wasted.
static constexpr pause_flags_t graceful_pause{1}; static constexpr pause_flags_t graceful_pause = 0_bit;
// ``pause()``, and ``resume()`` will disconnect all peers and reconnect // ``pause()``, and ``resume()`` will disconnect all peers and reconnect
// all peers respectively. When a torrent is paused, it will however // all peers respectively. When a torrent is paused, it will however
@ -626,12 +626,12 @@ namespace aux {
// the disk cache will be flushed before creating the resume data. // the disk cache will be flushed before creating the resume data.
// This avoids a problem with file timestamps in the resume data in // This avoids a problem with file timestamps in the resume data in
// case the cache hasn't been flushed yet. // case the cache hasn't been flushed yet.
static constexpr resume_data_flags_t flush_disk_cache{1}; static constexpr resume_data_flags_t flush_disk_cache = 0_bit;
// the resume data will contain the metadata from the torrent file as // the resume data will contain the metadata from the torrent file as
// well. This is default for any torrent that's added without a // well. This is default for any torrent that's added without a
// torrent file (such as a magnet link or a URL). // torrent file (such as a magnet link or a URL).
static constexpr resume_data_flags_t save_info_dict{2}; static constexpr resume_data_flags_t save_info_dict = 1_bit;
// if nothing significant has changed in the torrent since the last // if nothing significant has changed in the torrent since the last
// time resume data was saved, fail this attempt. Significant changes // time resume data was saved, fail this attempt. Significant changes
@ -639,7 +639,7 @@ namespace aux {
// priorities having changed etc. If the resume data doesn't need // priorities having changed etc. If the resume data doesn't need
// saving, a save_resume_data_failed_alert is posted with the error // saving, a save_resume_data_failed_alert is posted with the error
// resume_data_not_modified. // resume_data_not_modified.
static constexpr resume_data_flags_t only_if_modified{4}; static constexpr resume_data_flags_t only_if_modified = 2_bit;
// ``save_resume_data()`` asks libtorrent to generate fast-resume data for // ``save_resume_data()`` asks libtorrent to generate fast-resume data for
// this torrent. // this torrent.

View File

@ -56,10 +56,10 @@ namespace libtorrent {
public: public:
explicit udp_socket(io_service& ios); explicit udp_socket(io_service& ios);
static constexpr udp_send_flags_t peer_connection{1}; static constexpr udp_send_flags_t peer_connection = 0_bit;
static constexpr udp_send_flags_t tracker_connection{2}; static constexpr udp_send_flags_t tracker_connection = 1_bit;
static constexpr udp_send_flags_t dont_queue{4}; static constexpr udp_send_flags_t dont_queue = 2_bit;
static constexpr udp_send_flags_t dont_fragment{8}; static constexpr udp_send_flags_t dont_fragment = 3_bit;
bool is_open() const { return m_abort == false; } bool is_open() const { return m_abort == false; }
io_service& get_io_service() { return m_socket.get_io_service(); } io_service& get_io_service() { return m_socket.get_io_service(); }

View File

@ -101,7 +101,7 @@ namespace libtorrent {
} }
disk_io_job::disk_io_job() disk_io_job::disk_io_job()
: argument(remove_flags_t{0}) : argument(remove_flags_t{})
, piece(0) , piece(0)
{ {
d.io.offset = 0; d.io.offset = 0;

View File

@ -744,7 +744,7 @@ namespace {
{ {
entry ret; entry ret;
auto retp = &ret; auto retp = &ret;
sync_call(&session_impl::save_state, retp, save_state_flags_t{0xffffffff}); sync_call(&session_impl::save_state, retp, save_state_flags_t::all());
return ret; return ret;
} }
@ -1122,7 +1122,7 @@ namespace {
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
void session_handle::set_severity_level(alert::severity_t s) void session_handle::set_severity_level(alert::severity_t s)
{ {
int m = 0; alert_category_t m = {};
switch (s) switch (s)
{ {
case alert::debug: m = alert::all_categories; break; case alert::debug: m = alert::all_categories; break;
@ -1133,7 +1133,7 @@ namespace {
| alert::dht_notification); break; | alert::dht_notification); break;
case alert::critical: m = alert::error_notification | alert::storage_notification; break; case alert::critical: m = alert::error_notification | alert::storage_notification; break;
case alert::fatal: m = alert::error_notification; break; case alert::fatal: m = alert::error_notification; break;
case alert::none: m = 0; break; case alert::none: m = {}; break;
} }
settings_pack p; settings_pack p;

View File

@ -539,7 +539,8 @@ namespace aux {
{ {
if (pack.has_val(settings_pack::alert_mask)) if (pack.has_val(settings_pack::alert_mask))
{ {
m_alerts.set_alert_mask(alert_category_t(std::uint32_t(pack.get_int(settings_pack::alert_mask)))); m_alerts.set_alert_mask(alert_category_t(
static_cast<std::uint32_t>(pack.get_int(settings_pack::alert_mask))));
} }
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
@ -6488,7 +6489,8 @@ namespace {
void session_impl::update_alert_mask() void session_impl::update_alert_mask()
{ {
m_alerts.set_alert_mask(alert_category_t(std::uint32_t(m_settings.get_int(settings_pack::alert_mask)))); m_alerts.set_alert_mask(alert_category_t(
static_cast<std::uint32_t>(m_settings.get_int(settings_pack::alert_mask))));
} }
void session_impl::pop_alerts(std::vector<alert*>* alerts) void session_impl::pop_alerts(std::vector<alert*>* alerts)

View File

@ -926,12 +926,12 @@ struct test_mode_tag;
using test_mode_t = flags::bitfield_flag<std::uint8_t, test_mode_tag>; using test_mode_t = flags::bitfield_flag<std::uint8_t, test_mode_tag>;
namespace test_mode { namespace test_mode {
constexpr test_mode_t file_prio{1}; constexpr test_mode_t file_prio = 0_bit;
constexpr test_mode_t pieces_have{2}; constexpr test_mode_t pieces_have = 1_bit;
constexpr test_mode_t piece_prio{4}; constexpr test_mode_t piece_prio = 2_bit;
constexpr test_mode_t all_files_zero{8}; constexpr test_mode_t all_files_zero = 3_bit;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
constexpr test_mode_t deprecated{16}; constexpr test_mode_t deprecated = 4_bit;
#endif #endif
} }