From 1c816fa608c618a48f490e216ff0d5dab9544c62 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 6 Jan 2008 00:58:51 +0000 Subject: [PATCH] removes peers from bandwidth request queue when disconnecting --- src/torrent.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/torrent.cpp b/src/torrent.cpp index 2100fe5e3..a8ca89cbf 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1619,6 +1619,18 @@ namespace libtorrent p->set_peer_info(0); TORRENT_ASSERT(i != m_connections.end()); m_connections.erase(i); + + // remove from bandwidth request-queue + for (int c = 0; c < 2; ++c) + { + for (queue_t::iterator i = m_bandwidth_queue[c].begin() + , end(m_bandwidth_queue[c].end()); i != end; ++i) + { + if (i->peer != p) continue; + m_bandwidth_queue[c].erase(i); + break; + } + } } catch (std::exception& e) { @@ -2644,6 +2656,9 @@ namespace libtorrent { session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); + TORRENT_ASSERT(m_bandwidth_queue[0].size() <= m_connections.size()); + TORRENT_ASSERT(m_bandwidth_queue[1].size() <= m_connections.size()); + int num_uploads = 0; std::map num_requests; for (const_peer_iterator i = begin(); i != end(); ++i)