support forced shutdown/destruction of torrent objects

This commit is contained in:
arvidn 2017-12-28 00:09:12 +01:00 committed by Arvid Norberg
parent 5f0c9a0c1d
commit aae12250ae
6 changed files with 30 additions and 2 deletions

View File

@ -103,6 +103,8 @@ namespace libtorrent {
explicit peer_list(torrent_peer_allocator_interface& alloc);
~peer_list();
void clear();
// not copyable
peer_list(peer_list const&) = delete;
peer_list& operator=(peer_list const&) = delete;

View File

@ -448,6 +448,7 @@ namespace libtorrent {
// the necessary actions then.
void abort();
bool is_aborted() const { return m_abort; }
void panic();
void new_external_ip();

View File

@ -57,7 +57,7 @@ namespace libtorrent {
#if TORRENT_USE_ASSERTS
torrent_peer(torrent_peer const&) = default;
torrent_peer& operator=(torrent_peer const&) = default;
~torrent_peer() { in_use = false; }
~torrent_peer() { TORRENT_ASSERT(in_use); in_use = false; }
#endif
std::int64_t total_download() const;

View File

@ -125,6 +125,13 @@ namespace libtorrent {
thread_started();
}
void peer_list::clear()
{
for (auto const p : m_peers)
m_peer_allocator.free_peer_entry(p);
m_peers.clear();
}
peer_list::~peer_list()
{
for (auto const p : m_peers)

View File

@ -6030,7 +6030,13 @@ namespace {
// TORRENT_ASSERT(is_not_thread());
// TODO: asserts that no outstanding async operations are still in flight
TORRENT_ASSERT(m_torrents.empty());
// this can happen if we end the io_service run loop with an exception
for (auto& t : m_torrents)
{
t.second->panic();
t.second->abort();
}
m_torrents.clear();
#if defined TORRENT_ASIO_DEBUGGING
FILE* f = fopen("wakeups.log", "w+");

View File

@ -4419,6 +4419,18 @@ namespace libtorrent {
m_state_subscription = false;
}
// this is called when we're destructing non-gracefully. i.e. we're _just_
// destructing everything.
void torrent::panic()
{
m_storage.reset();
// if there are any other peers allocated still, we need to clear them
// now. They can't be cleared later because the allocator will already
// have been destructed
if (m_peer_list) m_peer_list->clear();
m_connections.clear();
}
void torrent::set_super_seeding(bool on)
{
if (on == m_super_seeding) return;