made the invariant checks cheaper and more useful. The full invariant checks are still available as an option

This commit is contained in:
Arvid Norberg
2008-07-12 17:51:59 +00:00
parent ff6cbbc6b6
commit 1ed583011c
4 changed files with 123 additions and 109 deletions

View File

@@ -3586,9 +3586,6 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock();
if (m_disconnecting)
{
for (aux::session_impl::torrent_map::const_iterator i = m_ses.m_torrents.begin()
, end(m_ses.m_torrents.end()); i != end; ++i)
TORRENT_ASSERT(!i->second->has_peer((peer_connection*)this));
TORRENT_ASSERT(!t);
}
else if (!m_in_constructor)
@@ -3629,11 +3626,13 @@ namespace libtorrent
if (!t)
{
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
// since this connection doesn't have a torrent reference
// no torrent should have a reference to this connection either
for (aux::session_impl::torrent_map::const_iterator i = m_ses.m_torrents.begin()
, end(m_ses.m_torrents.end()); i != end; ++i)
TORRENT_ASSERT(!i->second->has_peer((peer_connection*)this));
#endif
return;
}
@@ -3643,7 +3642,9 @@ namespace libtorrent
for (torrent::const_peer_iterator i = t->begin(); i != t->end(); ++i)
{
// make sure this peer is not a dangling pointer
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
TORRENT_ASSERT(m_ses.has_peer(*i));
#endif
peer_connection const& p = *(*i);
for (std::deque<piece_block>::const_iterator i = p.request_queue().begin()
, end(p.request_queue().end()); i != end; ++i)
@@ -3659,16 +3660,18 @@ namespace libtorrent
TORRENT_ASSERT(t->picker().num_peers(i->first) == i->second);
}
}
#ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS
if (m_peer_info)
{
policy::const_iterator i;
for (i = t->get_policy().begin_peer();
i != t->get_policy().end_peer(); ++i)
for (i = t->get_policy().begin_peer()
, end(t->get_policy().end_peer()); i != end; ++i)
{
if (&i->second == m_peer_info) break;
}
TORRENT_ASSERT(i != t->get_policy().end_peer());
}
#endif
if (t->has_picker() && !t->is_aborted())
{
// make sure that pieces that have completed the download