diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 3a145c687..fbf2c8a03 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -85,7 +85,7 @@ namespace libtorrent : user_agent(user_agent_) , tracker_completion_timeout(60) , tracker_receive_timeout(20) - , stop_tracker_timeout(10) + , stop_tracker_timeout(5) , tracker_maximum_response_length(1024*1024) , piece_timeout(120) , request_queue_time(3.f) diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index b1b4d87ac..07c377a0f 100755 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -234,6 +234,7 @@ namespace libtorrent void remove_request(tracker_connection const*); bool empty() const; + int num_requests() const; private: diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 6f42438b0..3ae3839b4 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -638,11 +638,26 @@ namespace detail void session_impl::abort() { mutex_t::scoped_lock l(m_mutex); - TORRENT_ASSERT(!m_abort); + if (m_abort) return; + m_io_service.stop(); +#if defined(TORRENT_LOGGING) + (*m_logger) << time_now_string() << " *** ABORT CALLED ***\n"; +#endif // abort the main thread m_abort = true; - m_io_service.stop(); - l.unlock(); + if (m_lsd) m_lsd->close(); + if (m_upnp) m_upnp->close(); + if (m_natpmp) m_natpmp->close(); +#ifndef TORRENT_DISABLE_DHT + if (m_dht) m_dht->stop(); +#endif + m_timer.cancel(); + // abort all torrents + for (torrent_map::iterator i = m_torrents.begin() + , end(m_torrents.end()); i != end; ++i) + { + i->second->abort(); + } mutex::scoped_lock l2(m_checker_impl.m_mutex); // abort the checker thread @@ -1031,17 +1046,17 @@ namespace detail // too expensive // INVARIANT_CHECK; + if (m_abort) return; + if (e) { #if defined(TORRENT_LOGGING) (*m_logger) << "*** SECOND TIMER FAILED " << e.message() << "\n"; #endif - m_abort = true; - m_io_service.stop(); + abort(); return; } - if (m_abort) return; float tick_interval = total_microseconds(time_now() - m_last_tick) / 1000000.f; m_last_tick = time_now(); @@ -1488,6 +1503,10 @@ namespace detail m_settings.stop_tracker_timeout) && !m_tracker_manager.empty()) { +#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) + (*m_logger) << time_now_string() << " " << m_tracker_manager.num_requests() + << " tracker requests pending\n"; +#endif tracker_timer.expires_from_now(milliseconds(100)); tracker_timer.async_wait(m_strand.wrap( bind(&io_service::stop, &m_io_service))); @@ -2072,9 +2091,7 @@ namespace detail session_impl::~session_impl() { -#ifndef TORRENT_DISABLE_DHT - stop_dht(); -#endif + abort(); #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) (*m_logger) << time_now_string() << "\n\n *** shutting down session *** \n\n"; diff --git a/src/torrent.cpp b/src/torrent.cpp index 840525c8a..a094fa749 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1029,6 +1029,7 @@ namespace libtorrent bind(&torrent::on_files_released, shared_from_this(), _1, _2)); m_owning_storage = 0; + m_announce_timer.cancel(); } void torrent::on_files_released(int ret, disk_io_job const& j) diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 37dd941eb..0118e5802 100755 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -584,4 +584,9 @@ namespace libtorrent return m_connections.empty(); } + int tracker_manager::num_requests() const + { + mutex_t::scoped_lock l(m_mutex); + return m_connections.size(); + } }