fix for when aborting torrents that are being checked. Fix in client_test when removing torrents that are checking.

This commit is contained in:
Arvid Norberg 2008-11-17 01:19:46 +00:00
parent de93105d51
commit f503bbfe86
6 changed files with 44 additions and 1 deletions

View File

@ -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<save_resume_data_failed_alert*>(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[] =

View File

@ -88,6 +88,7 @@ namespace libtorrent
, rename_file
, abort_thread
, clear_read_cache
, abort_torrent
};
action_t action;

View File

@ -236,6 +236,8 @@ namespace libtorrent
boost::function<void(int, disk_io_job const&)> const& handler
= boost::function<void(int, disk_io_job const&)>());
void abort_disk_io();
void async_clear_read_cache(
boost::function<void(int, disk_io_job const&)> const& handler
= boost::function<void(int, disk_io_job const&)>());

View File

@ -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<disk_io_job>::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);

View File

@ -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<void(int, disk_io_job const&)> const& handler)
{

View File

@ -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());