From 5a25be2825fc6d4da1c8db8f68b0ee039ba0b714 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 8 Jan 2005 21:12:19 +0000 Subject: [PATCH] *** empty log message *** --- include/libtorrent/session.hpp | 11 ++++++++++- src/session.cpp | 27 +++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index e3e01a403..33ab85e00 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -105,7 +105,8 @@ namespace libtorrent // thread that initialize pieces struct piece_checker_data { - piece_checker_data(): progress(0.f), abort(false) {} + piece_checker_data() + : progress(0.f), abort(false), processing(false) {} boost::shared_ptr torrent_ptr; boost::filesystem::path save_path; @@ -121,6 +122,12 @@ namespace libtorrent std::vector
peers; entry resume_data; + // this is true if this torrent is being processed (checked) + // if it is not being processed, then it can be removed from + // the queue without problems, otherwise the abort flag has + // to be set. + volatile bool processing; + // is filled in by storage::initialize_pieces() // and represents the progress. It should be a // value in the range [0, 1] @@ -137,6 +144,7 @@ namespace libtorrent checker_impl(session_impl& s): m_ses(s), m_abort(false) {} void operator()(); piece_checker_data* find_torrent(const sha1_hash& info_hash); + void remove_torrent(sha1_hash const& info_hash); // when the files has been checked // the torrent is added to the session @@ -315,6 +323,7 @@ namespace libtorrent void disable_extensions(); void set_peer_id(peer_id const& id); + void set_key(int key); bool is_listening() const; diff --git a/src/session.cpp b/src/session.cpp index a7107662b..7f332180e 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -114,6 +114,7 @@ namespace libtorrent { namespace detail m_torrents.pop_front(); continue; } + t->processing = true; } try @@ -176,7 +177,7 @@ namespace libtorrent { namespace detail } } - detail::piece_checker_data* checker_impl::find_torrent(const sha1_hash& info_hash) + detail::piece_checker_data* checker_impl::find_torrent(sha1_hash const& info_hash) { for (std::deque::iterator i = m_torrents.begin(); @@ -188,6 +189,21 @@ namespace libtorrent { namespace detail return 0; } + void checker_impl::remove_torrent(sha1_hash const& info_hash) + { + for (std::deque::iterator i + = m_torrents.begin(); + i != m_torrents.end(); + ++i) + { + if (i->info_hash == info_hash) + { + m_torrents.erase(i); + return; + } + } + } + session_impl::session_impl( std::pair listen_port_range , const fingerprint& cl_fprint @@ -876,6 +892,12 @@ namespace libtorrent m_impl.m_peer_id = id; } + void session::set_key(int key) + { + boost::mutex::scoped_lock l(m_impl.m_mutex); + m_impl.m_key = key; + } + void session::enable_extension(peer_connection::extension_index i) { assert(i >= 0); @@ -1022,7 +1044,8 @@ namespace libtorrent detail::piece_checker_data* d = m_checker_impl.find_torrent(h.m_info_hash); if (d != 0) { - d->abort = true; + if (d->processing) d->abort = true; + else m_checker_impl.remove_torrent(h.m_info_hash); return; } }