From 567fd8112f996846db6a9d59aa646174121bbfd0 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 29 Feb 2004 16:39:52 +0000 Subject: [PATCH] *** empty log message *** --- include/libtorrent/torrent_handle.hpp | 10 ++++++- src/session.cpp | 4 ++- src/torrent_handle.cpp | 38 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 6de861c18..88ea0a4cd 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -139,6 +139,7 @@ namespace libtorrent struct torrent_handle { + friend class invariant_access; friend class session; friend class torrent; @@ -215,7 +216,14 @@ namespace libtorrent : m_ses(s) , m_chk(c) , m_info_hash(h) - {} + { + assert(m_ses != 0); + assert(m_chk != 0); + } + +#ifndef NDEBUG + void check_invariant() const; +#endif detail::session_impl* m_ses; detail::checker_impl* m_chk; diff --git a/src/session.cpp b/src/session.cpp index 738db78c9..a9e1a0c67 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -873,7 +873,8 @@ namespace libtorrent void session::remove_torrent(const torrent_handle& h) { if (h.m_ses != &m_impl) return; - assert(h.m_chk == &m_checker_impl); + assert(h.m_chk == &m_checker_impl || h.m_chk == 0); + assert(h.m_ses != 0); { boost::mutex::scoped_lock l(m_impl.m_mutex); @@ -885,6 +886,7 @@ namespace libtorrent } } + if (h.m_chk) { boost::mutex::scoped_lock l(m_checker_impl.m_mutex); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index cc536737d..236b87572 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -59,6 +59,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hasher.hpp" #include "libtorrent/entry.hpp" #include "libtorrent/session.hpp" +#include "libtorrent/invariant_check.hpp" #if defined(_MSC_VER) && _MSC_VER < 1300 namespace std @@ -71,8 +72,19 @@ namespace std namespace libtorrent { +#ifndef NDEBUG + + void torrent_handle::check_invariant() const + { + assert((m_ses == 0 && m_chk == 0) || (m_ses != 0)); + } + +#endif + void torrent_handle::set_max_uploads(int max_uploads) { + INVARIANT_CHECK; + assert(max_uploads >= 2 || max_uploads == -1); if (m_ses == 0) throw invalid_handle(); @@ -104,6 +116,8 @@ namespace libtorrent void torrent_handle::use_interface(const char* net_interface) { + INVARIANT_CHECK; + if (m_ses == 0) throw invalid_handle(); { @@ -133,6 +147,8 @@ namespace libtorrent void torrent_handle::set_max_connections(int max_connections) { + INVARIANT_CHECK; + assert(max_connections > 2 || max_connections == -1); if (m_ses == 0) throw invalid_handle(); @@ -164,6 +180,8 @@ namespace libtorrent torrent_status torrent_handle::status() const { + INVARIANT_CHECK; + if (m_ses == 0) throw invalid_handle(); { @@ -196,6 +214,8 @@ namespace libtorrent const torrent_info& torrent_handle::get_torrent_info() const { + INVARIANT_CHECK; + if (m_ses == 0) throw invalid_handle(); { @@ -216,6 +236,8 @@ namespace libtorrent void torrent_handle::set_tracker_login(std::string const& name, std::string const& password) { + INVARIANT_CHECK; + if (m_ses == 0) throw invalid_handle(); { @@ -244,6 +266,8 @@ namespace libtorrent bool torrent_handle::is_valid() const { + INVARIANT_CHECK; + if (m_ses == 0) return false; { @@ -264,6 +288,8 @@ namespace libtorrent entry torrent_handle::write_resume_data() const { + INVARIANT_CHECK; + std::vector piece_index; if (m_ses == 0) throw invalid_handle(); @@ -376,6 +402,8 @@ namespace libtorrent boost::filesystem::path torrent_handle::save_path() const { + INVARIANT_CHECK; + if (m_ses == 0) throw invalid_handle(); // copy the path into this local variable before @@ -411,6 +439,8 @@ namespace libtorrent void torrent_handle::connect_peer(const address& adr) const { + INVARIANT_CHECK; + if (m_ses == 0) throw invalid_handle(); boost::mutex::scoped_lock l(m_ses->m_mutex); @@ -424,6 +454,8 @@ namespace libtorrent void torrent_handle::force_reannounce() const { + INVARIANT_CHECK; + if (m_ses == 0) throw invalid_handle(); boost::mutex::scoped_lock l(m_ses->m_mutex); @@ -435,6 +467,8 @@ namespace libtorrent void torrent_handle::set_ratio(float ratio) { + INVARIANT_CHECK; + assert(ratio >= 0.f); if (m_ses == 0) throw invalid_handle(); @@ -464,6 +498,8 @@ namespace libtorrent void torrent_handle::get_peer_info(std::vector& v) const { + INVARIANT_CHECK; + v.clear(); if (m_ses == 0) throw invalid_handle(); @@ -539,6 +575,8 @@ namespace libtorrent void torrent_handle::get_download_queue(std::vector& queue) const { + INVARIANT_CHECK; + queue.clear(); if (m_ses == 0) throw invalid_handle();