From d6a53200a2eb442452dbd4d213d6b8543d8f98c2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 6 Jun 2012 16:05:25 +0000 Subject: [PATCH] add a force-flag to cancel_request --- include/libtorrent/peer_connection.hpp | 4 +++- src/peer_connection.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 4b1c80046..0d61804f5 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -506,7 +506,9 @@ namespace libtorrent // sends a cancel message if appropriate // refills the request queue, and possibly ignoring pieces requested // by peers in the ignore list (to avoid recursion) - void cancel_request(piece_block const& b); + // if force is true, the blocks is also freed from the piece + // picker, allowing another peer to request it immediately + void cancel_request(piece_block const& b, bool force = false); void send_block_requests(); int bandwidth_throttle(int channel) const diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index f9c8b1c2c..4a16ae7b2 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -2898,7 +2898,7 @@ namespace libtorrent } } - void peer_connection::cancel_request(piece_block const& block) + void peer_connection::cancel_request(piece_block const& block, bool force) { INVARIANT_CHECK; @@ -2946,6 +2946,8 @@ namespace libtorrent TORRENT_ASSERT(block_size > 0); TORRENT_ASSERT(block_size <= t->block_size()); + if (force) t->picker().abort_download(block, peer_info_struct()); + if (m_outstanding_bytes < block_size) return; peer_request r;