From d1addf876adbe4d4c19473e3819a1d4513856cf2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 24 Apr 2010 19:24:27 +0000 Subject: [PATCH] added some asserts --- src/torrent.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/torrent.cpp b/src/torrent.cpp index 43e9fecc1..afecbcce3 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2151,6 +2151,7 @@ namespace libtorrent // update m_file_progress TORRENT_ASSERT(m_picker); TORRENT_ASSERT(!have_piece(index)); + TORRENT_ASSERT(!m_picker->have_piece(index)); const int piece_size = m_torrent_file->piece_length(); size_type off = size_type(index) * piece_size; @@ -2195,6 +2196,17 @@ namespace libtorrent TORRENT_ASSERT(index >= 0); TORRENT_ASSERT(index < m_torrent_file->num_pieces()); +#ifdef TORRENT_DEBUG + // make sure all blocks were successfully written before we + // declare the piece has "we have". + piece_picker::downloading_piece dp; + m_picker->piece_info(index, dp); + int blocks_in_piece = m_picker->blocks_in_piece(index); + TORRENT_ASSERT(dp.finished == blocks_in_piece); + TORRENT_ASSERT(dp.writing == 0); + TORRENT_ASSERT(dp.requested == 0); + TORRENT_ASSERT(dp.index == index); +#endif if (m_ses.m_alerts.should_post()) { @@ -5998,6 +6010,7 @@ namespace libtorrent TORRENT_ASSERT(piece_index >= 0); TORRENT_ASSERT(piece_index < m_torrent_file->num_pieces()); TORRENT_ASSERT(piece_index < (int)m_picker->num_pieces()); + TORRENT_ASSERT(!m_picker || !m_picker->have_piece(piece_index)); #ifdef TORRENT_DEBUG if (m_picker) {