diff --git a/examples/client_test.cpp b/examples/client_test.cpp index ab0156684..6d78d457f 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -656,6 +656,13 @@ void handle_alert(libtorrent::session& ses, libtorrent::alert* a ses.remove_torrent(h); } } + else if (save_resume_data_failed_alert* p = dynamic_cast(a)) + { + torrent_handle h = p->handle; + if (std::find_if(handles.begin(), handles.end() + , bind(&handles_t::value_type::second, _1) == h) == handles.end()) + ses.remove_torrent(h); + } } static char const* state_str[] = diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 23e8dd349..948db1176 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -88,6 +88,7 @@ namespace libtorrent , rename_file , abort_thread , clear_read_cache + , abort_torrent }; action_t action; diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index f144b5fc8..4f7cd5238 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -236,6 +236,8 @@ namespace libtorrent boost::function const& handler = boost::function()); + void abort_disk_io(); + void async_clear_read_cache( boost::function const& handler = boost::function()); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 0369a9d41..357b506b0 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -178,7 +178,10 @@ namespace libtorrent } ++i; } - m_signal.notify_all(); + disk_io_job j; + j.action = disk_io_job::abort_torrent; + j.storage = s; + add_job(j); } bool range_overlap(int start1, int length1, int start2, int length2) @@ -803,6 +806,28 @@ namespace libtorrent switch (j.action) { + case disk_io_job::abort_torrent: + { + mutex_t::scoped_lock jl(m_queue_mutex); + for (std::list::iterator i = m_jobs.begin(); + i != m_jobs.end();) + { + if (i->storage != j.storage) + { + ++i; + continue; + } + if (i->action == disk_io_job::check_files) + { + if (i->callback) m_ios.post(bind(i->callback + , piece_manager::disk_check_aborted, *i)); + m_jobs.erase(i++); + continue; + } + ++i; + } + break; + } case disk_io_job::abort_thread: { mutex_t::scoped_lock jl(m_queue_mutex); diff --git a/src/storage.cpp b/src/storage.cpp index 9a41570a8..71e8c39f9 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1289,6 +1289,11 @@ namespace libtorrent m_io_thread.add_job(j, handler); } + void piece_manager::abort_disk_io() + { + m_io_thread.stop(this); + } + void piece_manager::async_delete_files( boost::function const& handler) { diff --git a/src/torrent.cpp b/src/torrent.cpp index 7c5d73c54..791cd6811 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1631,8 +1631,11 @@ namespace libtorrent // files belonging to the torrents disconnect_all(); if (m_owning_storage.get()) + { m_storage->async_release_files( bind(&torrent::on_files_released, shared_from_this(), _1, _2)); + m_storage->abort_disk_io(); + } if (m_state == torrent_status::checking_files) m_ses.done_checking(shared_from_this());