From 16886741d038b1f1554c48edbfb6b550fca349f1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 2 Oct 2007 18:34:34 +0000 Subject: [PATCH] release_files now keeps the torrent object alive --- include/libtorrent/torrent.hpp | 1 + src/torrent.cpp | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index bcc54899f..90ebfea31 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -551,6 +551,7 @@ namespace libtorrent private: void on_files_released(int ret, disk_io_job const& j); + void on_torrent_paused(int ret, disk_io_job const& j); void on_storage_moved(int ret, disk_io_job const& j); void on_piece_verified(int ret, disk_io_job const& j diff --git a/src/torrent.cpp b/src/torrent.cpp index 08176c6e0..14fa6f5e9 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1024,11 +1024,26 @@ namespace libtorrent #endif disconnect_all(); - if (m_owning_storage.get()) m_storage->async_release_files(); + if (m_owning_storage.get()) + m_storage->async_release_files( + bind(&torrent::on_files_released, shared_from_this(), _1, _2)); + m_owning_storage = 0; } void torrent::on_files_released(int ret, disk_io_job const& j) + { +/* + session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); + + if (alerts().should_post(alert::warning)) + { + alerts().post_alert(torrent_paused_alert(get_handle(), "torrent paused")); + } +*/ + } + + void torrent::on_torrent_paused(int ret, disk_io_job const& j) { session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); @@ -2117,7 +2132,9 @@ namespace libtorrent , bind(&peer_connection::disconnect, _1)); assert(m_storage); - m_storage->async_release_files(); + // we need to keep the object alive during this operation + m_storage->async_release_files( + bind(&torrent::on_files_released, shared_from_this(), _1, _2)); } // called when torrent is complete (all pieces downloaded) @@ -2549,10 +2566,8 @@ namespace libtorrent if (m_owning_storage.get()) { assert(m_storage); - // TOOD: add a callback which posts - // an alert for the client to sync. with m_storage->async_release_files( - bind(&torrent::on_files_released, shared_from_this(), _1, _2)); + bind(&torrent::on_torrent_paused, shared_from_this(), _1, _2)); } }