From 83754b3427f639da42bfbdccdccab485070688d3 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 6 Oct 2012 14:31:14 +0000 Subject: [PATCH] merged post_torrent_updates assert from libtorrent_aio --- include/libtorrent/aux_/session_impl.hpp | 3 +++ src/session_impl.cpp | 12 ++++++++++++ src/torrent.cpp | 6 +++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 4b81bac09..978d0adbb 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -237,6 +237,9 @@ namespace libtorrent , boost::bind(&boost::intrusive_ptr::get, _1) == p) != m_connections.end(); } + // this is set while the session is building the + // torrent status update message + bool m_posting_torrent_updates; #endif void main_thread(); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 4bdc908ef..7080bb3f6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -672,6 +672,10 @@ namespace aux { , m_network_thread(0) #endif { +#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS + m_posting_torrent_updates = false; +#endif + memset(m_redundant_bytes, 0, sizeof(m_redundant_bytes)); m_udp_socket.set_rate_limit(m_settings.dht_upload_rate_limit); @@ -4792,6 +4796,10 @@ namespace aux { std::auto_ptr alert(new state_update_alert()); alert->status.reserve(m_state_updates.size()); +#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS + m_posting_torrent_updates = true; +#endif + for (std::vector >::iterator i = m_state_updates.begin() , end(m_state_updates.end()); i != end; ++i) { @@ -4803,6 +4811,10 @@ namespace aux { } m_state_updates.clear(); +#if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS + m_posting_torrent_updates = false; +#endif + m_alerts.post_alert_ptr(alert.release()); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 7ddfb9fd3..070b8d005 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2923,7 +2923,7 @@ namespace libtorrent TORRENT_ASSERT(st.total_wanted >= st.total_wanted_done); // subtract padding files - if (m_padding > 0) + if (m_padding > 0 && accurate) { file_storage const& files = m_torrent_file->files(); int fileno = 0; @@ -8398,6 +8398,10 @@ namespace libtorrent // this should probably be moved to torrent::start() TORRENT_ASSERT(shared_from_this()); + // we can't call state_updated() while the session + // is building the status update alert + TORRENT_ASSERT(!m_ses.m_posting_torrent_updates); + // we're either not subscribing to this torrent, or // it has already been updated this round, no need to // add it to the list twice