From b72ae5d5ccb1ae84d9813ca9d01371c952dbfe84 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Thu, 30 Oct 2008 17:23:36 +0000 Subject: lt sync 2881 --- libtorrent/include/libtorrent/connection_queue.hpp | 2 ++ libtorrent/src/connection_queue.cpp | 19 +++++++++++++++++++ libtorrent/src/session_impl.cpp | 14 +++++++++++++- libtorrent/src/storage.cpp | 2 +- libtorrent/src/torrent.cpp | 3 ++- libtorrent/src/upnp.cpp | 2 +- 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/libtorrent/include/libtorrent/connection_queue.hpp b/libtorrent/include/libtorrent/connection_queue.hpp index 527b862df..749d72133 100644 --- a/libtorrent/include/libtorrent/connection_queue.hpp +++ b/libtorrent/include/libtorrent/connection_queue.hpp @@ -63,6 +63,7 @@ public: void limit(int limit); int limit() const; void close(); + int size() const { return m_queue.size(); } #ifndef NDEBUG void check_invariant() const; @@ -93,6 +94,7 @@ private: int m_next_ticket; int m_num_connecting; int m_half_open_limit; + bool m_abort; deadline_timer m_timer; diff --git a/libtorrent/src/connection_queue.cpp b/libtorrent/src/connection_queue.cpp index 548fe07e6..d5228a66a 100644 --- a/libtorrent/src/connection_queue.cpp +++ b/libtorrent/src/connection_queue.cpp @@ -42,6 +42,7 @@ namespace libtorrent connection_queue::connection_queue(io_service& ios): m_next_ticket(0) , m_num_connecting(0) , m_half_open_limit(0) + , m_abort(false) , m_timer(ios) #ifndef NDEBUG , m_in_timeout_function(false) @@ -114,7 +115,24 @@ namespace libtorrent void connection_queue::close() { error_code ec; + mutex_t::scoped_lock l(m_mutex); m_timer.cancel(ec); + m_abort = true; + + // make a copy of the list to go through, so + // that connections removing themseleves won't + // interfere with the iteration + std::list closing_entries = m_queue; + + // we don't want to call the timeout callback while we're locked + // since that is a recepie for dead-locks + l.unlock(); + + for (std::list::iterator i = closing_entries.begin() + , end(closing_entries.end()); i != end; ++i) + { + try { i->on_timeout(); } catch (std::exception&) {} + } } void connection_queue::limit(int limit) @@ -148,6 +166,7 @@ namespace libtorrent #ifdef TORRENT_CONNECTION_LOGGING m_log << log_time() << " " << free_slots() << std::endl; #endif + if (m_abort) return; if (m_num_connecting >= m_half_open_limit && m_half_open_limit > 0) return; diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index d67abdce6..adc163f50 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -495,6 +495,12 @@ namespace aux { #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) (*m_logger) << time_now_string() << " aborting all connections (" << m_connections.size() << ")\n"; #endif + m_half_open.close(); + +#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) + (*m_logger) << time_now_string() << " connection queue: " << m_half_open.size() << std::endl; +#endif + // abort all connections while (!m_connections.empty()) { @@ -505,10 +511,14 @@ namespace aux { TORRENT_ASSERT(conn == int(m_connections.size()) + 1); } +#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) + (*m_logger) << time_now_string() << " connection queue: " << m_half_open.size() << std::endl; +#endif + TORRENT_ASSERT(m_half_open.size() == 0); + #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) (*m_logger) << time_now_string() << " shutting down connection queue\n"; #endif - m_half_open.close(); m_download_channel.close(); m_upload_channel.close(); @@ -2178,6 +2188,7 @@ namespace aux { (*m_logger) << time_now_string() << "\n\n *** shutting down session *** \n\n"; #endif abort(); + TORRENT_ASSERT(m_connections.empty()); #ifndef TORRENT_DISABLE_GEO_IP if (m_asnum_db) GeoIP_delete(m_asnum_db); @@ -2200,6 +2211,7 @@ namespace aux { #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) (*m_logger) << time_now_string() << " shutdown complete!\n"; #endif + TORRENT_ASSERT(m_connections.empty()); } void session_impl::set_max_uploads(int limit) diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index e1572d9a2..eda0b4368 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -525,7 +525,7 @@ namespace libtorrent #endif #if TORRENT_USE_WPATH - fs::wpath file_path = safe_convert(m_save_path / file_iter->path); + fs::wpath file_path = safe_convert((m_save_path / file_iter->path).string()); #else fs::path file_path = m_save_path / file_iter->path; #endif diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index 1786b009b..5caa3943a 100755 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -3078,7 +3078,8 @@ namespace libtorrent && m_state != torrent_status::checking_files && (m_state != torrent_status::queued_for_checking || !valid_metadata()) - && m_policy.num_connect_candidates() > 0; + && m_policy.num_connect_candidates() > 0 + && !m_abort; } void torrent::disconnect_all() diff --git a/libtorrent/src/upnp.cpp b/libtorrent/src/upnp.cpp index e45022953..390d49450 100644 --- a/libtorrent/src/upnp.cpp +++ b/libtorrent/src/upnp.cpp @@ -160,7 +160,7 @@ int upnp::add_mapping(upnp::protocol_type p, int external_port, int local_port) m_log << time_now_string() << " *** add mapping [ proto: " << (p == tcp?"tcp":"udp") << " ext_port: " << external_port - << " local_port:" << local_port << " ]"; + << " local_port :" << local_port << " ]"; if (m_disabled) m_log << " DISABLED"; m_log << std::endl; #endif -- cgit