From ea77427e078fa50c793a2fc49fa7a73149d67691 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 23 May 2014 02:23:11 +0000 Subject: [PATCH] added clear_piece_deadlines() to remove all piece deadlines --- ChangeLog | 2 ++ include/libtorrent/torrent.hpp | 1 + include/libtorrent/torrent_handle.hpp | 4 ++++ src/torrent.cpp | 16 ++++++++++++++++ src/torrent_handle.cpp | 5 +++++ 5 files changed, 28 insertions(+) diff --git a/ChangeLog b/ChangeLog index f60da8873..8da64e9ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 1.0 release + * added clear_piece_deadlines() to remove all piece deadlines * improve queuing logic of inactive torrents (dont_count_slow_torrents) * expose optimistic unchoke logic to plugins * fix issue with large UDP packets on windows @@ -52,6 +53,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * added work-around for MingW issue in file I/O * fixed sparse file detection on windows * fixed bug in gunzip * fix to use proxy settings when adding .torrent file from URL diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index b1eb54d9a..258a10439 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -345,6 +345,7 @@ namespace libtorrent void set_piece_deadline(int piece, int t, int flags); void reset_piece_deadline(int piece); + void clear_time_critical(); void update_piece_priorities(); void status(torrent_status* st, boost::uint32_t flags); diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 3f950ecd6..d95c0878b 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -362,8 +362,12 @@ namespace libtorrent // ``reset_piece_deadline`` removes the deadline from the piece. If it // hasn't already been downloaded, it will no longer be considered a // priority. + // + // ``clear_piece_deadlines()`` removes deadlines on all pieces in + // the torrent. As if reset_piece_deadline() was called on all pieces. void set_piece_deadline(int index, int deadline, int flags = 0) const; void reset_piece_deadline(int index) const; + void clear_piece_deadlines() const; // This sets the bandwidth priority of this torrent. The priority of a // torrent determines how much bandwidth its peers are assigned when diff --git a/src/torrent.cpp b/src/torrent.cpp index bd0f33e55..467504680 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3827,6 +3827,22 @@ namespace libtorrent } } + void torrent::clear_time_critical() + { + for (std::deque::iterator i = m_time_critical_pieces.begin(); + i != m_time_critical_pieces.end();) + { + if (i->flags & torrent_handle::alert_when_available) + { + // post an empty read_piece_alert to indicate it failed + m_ses.m_alerts.post_alert(read_piece_alert( + get_handle(), i->piece, error_code(boost::system::errc::operation_canceled, get_system_category()))); + } + if (has_picker()) m_picker->set_piece_priority(i->piece, 1); + i = m_time_critical_pieces.erase(i); + } + } + // remove time critical pieces where priority is 0 void torrent::remove_time_critical_pieces(std::vector const& priority) { diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 734b64303..707aa807b 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -889,6 +889,11 @@ namespace libtorrent TORRENT_ASYNC_CALL1(reset_piece_deadline, index); } + void torrent_handle::clear_piece_deadlines() const + { + TORRENT_ASYNC_CALL(clear_time_critical); + } + boost::shared_ptr torrent_handle::native_handle() const { return m_torrent.lock();