From 6db55b87ab3cf250d46226d271e1ed0753ec0665 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 16 Oct 2005 21:14:08 +0000 Subject: [PATCH] fixed problem when aborting checking torrents --- include/libtorrent/bencode.hpp | 3 ++- src/session.cpp | 15 +++++++++++++++ src/torrent.cpp | 26 +++++++++++++------------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index 77baea44f..972a6e4c1 100755 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -195,7 +195,8 @@ namespace libtorrent write_char(out, 'e'); break; default: - throw invalid_encoding(); + // do nothing + break; } } diff --git a/src/session.cpp b/src/session.cpp index 720087fbe..20d8247fc 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -118,6 +118,14 @@ namespace libtorrent { namespace detail t = m_torrents.front(); if (t->abort) { + if (processing->torrent_ptr->num_peers()) + { + m_ses.m_torrents.insert(std::make_pair( + t->info_hash, t->torrent_ptr)); + t->torrent_ptr->abort(); + } + + m_torrents.pop_front(); continue; } @@ -238,6 +246,13 @@ namespace libtorrent { namespace detail assert(!m_processing.empty()); assert(m_processing.front() == processing); + if (processing->torrent_ptr->num_peers()) + { + m_ses.m_torrents.insert(std::make_pair( + processing->info_hash, processing->torrent_ptr)); + processing->torrent_ptr->abort(); + } + processing.reset(); m_processing.pop_front(); if (!m_processing.empty()) diff --git a/src/torrent.cpp b/src/torrent.cpp index 8ebd9a1b9..59f83bfff 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -860,21 +860,21 @@ namespace libtorrent peer_iterator i = m_connections.find(p->get_socket()->sender()); assert(i != m_connections.end()); - // if the peer_connection was downloading any pieces - // abort them - for (std::deque::const_iterator i = p->download_queue().begin(); - i != p->download_queue().end(); ++i) + if (ready_for_connections()) { - m_picker->abort_download(*i); - } - for (std::deque::const_iterator i = p->request_queue().begin(); - i != p->request_queue().end(); ++i) - { - m_picker->abort_download(*i); - } + // if the peer_connection was downloading any pieces + // abort them + for (std::deque::const_iterator i = p->download_queue().begin(); + i != p->download_queue().end(); ++i) + { + m_picker->abort_download(*i); + } + for (std::deque::const_iterator i = p->request_queue().begin(); + i != p->request_queue().end(); ++i) + { + m_picker->abort_download(*i); + } - if (valid_metadata()) - { std::vector piece_list; const std::vector& pieces = p->get_bitfield();