From da8bd07ce722d14031dd0d29aa002467814201b7 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sat, 11 Aug 2007 22:55:15 +0000 Subject: [PATCH] libtorrent sync 1449 --- libtorrent/include/libtorrent/config.hpp | 5 +++++ libtorrent/include/libtorrent/entry.hpp | 2 +- libtorrent/include/libtorrent/piece_picker.hpp | 4 +++- libtorrent/include/libtorrent/session.hpp | 5 +++-- libtorrent/include/libtorrent/torrent_handle.hpp | 10 +++++----- libtorrent/include/libtorrent/torrent_info.hpp | 4 +++- libtorrent/src/piece_picker.cpp | 10 +++++++--- libtorrent/src/torrent.cpp | 9 +++++---- 8 files changed, 32 insertions(+), 17 deletions(-) diff --git a/libtorrent/include/libtorrent/config.hpp b/libtorrent/include/libtorrent/config.hpp index c8d86955e..b36d4da22 100755 --- a/libtorrent/include/libtorrent/config.hpp +++ b/libtorrent/include/libtorrent/config.hpp @@ -37,6 +37,8 @@ POSSIBILITY OF SUCH DAMAGE. #if defined(__GNUC__) && __GNUC__ >= 4 +#define TORRENT_DEPRECATED __attribute__ ((deprecated)) + # if defined(TORRENT_BUILDING_SHARED) || defined(TORRENT_LINKING_SHARED) # define TORRENT_EXPORT __attribute__ ((visibility("default"))) # else @@ -61,6 +63,9 @@ POSSIBILITY OF SUCH DAMAGE. # define TORRENT_EXPORT #endif +#ifndef TORRENT_DEPRECATED +#define TORRENT_DEPRECATED +#endif #endif // TORRENT_CONFIG_HPP_INCLUDED diff --git a/libtorrent/include/libtorrent/entry.hpp b/libtorrent/include/libtorrent/entry.hpp index a1eba5324..59e29803d 100755 --- a/libtorrent/include/libtorrent/entry.hpp +++ b/libtorrent/include/libtorrent/entry.hpp @@ -59,7 +59,7 @@ POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include #include diff --git a/libtorrent/include/libtorrent/piece_picker.hpp b/libtorrent/include/libtorrent/piece_picker.hpp index 9595e2501..54df003ef 100755 --- a/libtorrent/include/libtorrent/piece_picker.hpp +++ b/libtorrent/include/libtorrent/piece_picker.hpp @@ -163,7 +163,9 @@ namespace libtorrent void we_have(int index); // sets the priority of a piece. - void set_piece_priority(int index, int prio); + // returns true if the priority was changed from 0 to non-0 + // or vice versa + bool set_piece_priority(int index, int prio); // returns the priority for the piece at 'index' int piece_priority(int index) const; diff --git a/libtorrent/include/libtorrent/session.hpp b/libtorrent/include/libtorrent/session.hpp index 52ec62cdb..38206f32c 100755 --- a/libtorrent/include/libtorrent/session.hpp +++ b/libtorrent/include/libtorrent/session.hpp @@ -144,14 +144,15 @@ namespace libtorrent , int block_size = 16 * 1024 , storage_constructor_type sc = default_storage_constructor); - // TODO: deprecated, this is for backwards compatibility only + // ==== deprecated, this is for backwards compatibility only + // instead, use one of the other add_torrent overloads torrent_handle add_torrent( entry const& e , fs::path const& save_path , entry const& resume_data = entry() , bool compact_mode = true , int block_size = 16 * 1024 - , storage_constructor_type sc = default_storage_constructor) + , storage_constructor_type sc = default_storage_constructor) TORRENT_DEPRECATED { return add_torrent(torrent_info(e), save_path, resume_data , compact_mode, block_size, sc); diff --git a/libtorrent/include/libtorrent/torrent_handle.hpp b/libtorrent/include/libtorrent/torrent_handle.hpp index 6fbaaffad..3f7ae5bcc 100755 --- a/libtorrent/include/libtorrent/torrent_handle.hpp +++ b/libtorrent/include/libtorrent/torrent_handle.hpp @@ -296,13 +296,13 @@ namespace libtorrent // marks the piece with the given index as filtered // it will not be downloaded - void filter_piece(int index, bool filter) const; - void filter_pieces(std::vector const& pieces) const; - bool is_piece_filtered(int index) const; - std::vector filtered_pieces() const; + void filter_piece(int index, bool filter) const TORRENT_DEPRECATED; + void filter_pieces(std::vector const& pieces) const TORRENT_DEPRECATED; + bool is_piece_filtered(int index) const TORRENT_DEPRECATED; + std::vector filtered_pieces() const TORRENT_DEPRECATED; // marks the file with the given index as filtered // it will not be downloaded - void filter_files(std::vector const& files) const; + void filter_files(std::vector const& files) const TORRENT_DEPRECATED; // ================ end deprecation ============ diff --git a/libtorrent/include/libtorrent/torrent_info.hpp b/libtorrent/include/libtorrent/torrent_info.hpp index e52024255..a2d6c4ef9 100755 --- a/libtorrent/include/libtorrent/torrent_info.hpp +++ b/libtorrent/include/libtorrent/torrent_info.hpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #ifdef _MSC_VER #pragma warning(push, 1) @@ -146,7 +147,8 @@ namespace libtorrent const std::string& name() const { assert(m_piece_length > 0); return m_name; } // ------- start deprecation ------- - void print(std::ostream& os) const; +// this functionaily will be removed in a future version + void print(std::ostream& os) const TORRENT_DEPRECATED; // ------- end deprecation ------- bool is_valid() const { return m_piece_length > 0; } diff --git a/libtorrent/src/piece_picker.cpp b/libtorrent/src/piece_picker.cpp index 833ceb793..ddc2c2f5a 100755 --- a/libtorrent/src/piece_picker.cpp +++ b/libtorrent/src/piece_picker.cpp @@ -966,7 +966,7 @@ namespace libtorrent } - void piece_picker::set_piece_priority(int index, int new_piece_priority) + bool piece_picker::set_piece_priority(int index, int new_piece_priority) { TORRENT_PIECE_PICKER_INVARIANT_CHECK; assert(new_piece_priority >= 0); @@ -977,16 +977,18 @@ namespace libtorrent piece_pos& p = m_piece_map[index]; // if the priority isn't changed, don't do anything - if (new_piece_priority == int(p.piece_priority)) return; + if (new_piece_priority == int(p.piece_priority)) return false; int prev_priority = p.priority(m_sequenced_download_threshold); + bool ret = false; if (new_piece_priority == piece_pos::filter_priority && p.piece_priority != piece_pos::filter_priority) { // the piece just got filtered if (p.have()) ++m_num_have_filtered; else ++m_num_filtered; + ret = true; } else if (new_piece_priority != piece_pos::filter_priority && p.piece_priority == piece_pos::filter_priority) @@ -994,6 +996,7 @@ namespace libtorrent // the piece just got unfiltered if (p.have()) --m_num_have_filtered; else --m_num_filtered; + ret = true; } assert(m_num_filtered >= 0); assert(m_num_have_filtered >= 0); @@ -1001,7 +1004,7 @@ namespace libtorrent p.piece_priority = new_piece_priority; int new_priority = p.priority(m_sequenced_download_threshold); - if (new_priority == prev_priority) return; + if (new_priority == prev_priority) return false; if (prev_priority == 0) { @@ -1011,6 +1014,7 @@ namespace libtorrent { move(prev_priority, p.index); } + return ret; } int piece_picker::piece_priority(int index) const diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index baded7160..13309c1e7 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -1119,8 +1119,8 @@ namespace libtorrent assert(index >= 0); assert(index < m_torrent_file.num_pieces()); - m_picker->set_piece_priority(index, priority); - update_peer_interest(); + bool filter_updated = m_picker->set_piece_priority(index, priority); + if (filter_updated) update_peer_interest(); } int torrent::piece_priority(int index) const @@ -1149,14 +1149,15 @@ namespace libtorrent assert(m_picker.get()); int index = 0; + bool filter_updated = false; for (std::vector::const_iterator i = pieces.begin() , end(pieces.end()); i != end; ++i, ++index) { assert(*i >= 0); assert(*i <= 7); - m_picker->set_piece_priority(index, *i); + filter_updated |= m_picker->set_piece_priority(index, *i); } - update_peer_interest(); + if (filter_updated) update_peer_interest(); } void torrent::piece_priorities(std::vector& pieces) const