diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index b27c1c410..d86d819cd 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1001,13 +1001,11 @@ namespace libtorrent , m_download_queue.end() , block_finished); - std::deque::iterator i; - if (b != m_download_queue.end()) { if (m_assume_fifo) { - for (i = m_download_queue.begin(); + for (std::deque::iterator i = m_download_queue.begin(); i != b; ++i) { #ifdef TORRENT_VERBOSE_LOGGING @@ -1115,6 +1113,23 @@ namespace libtorrent { t->piece_failed(p.piece); } +#ifndef NDEBUG + if (!t->is_seed()) + { + const int blocks_per_piece = static_cast( + t->torrent_file().piece_length() / t->block_size()); + + std::vector const& dl_queue + = t->picker().get_download_queue(); + + for (std::vector::const_iterator i = + dl_queue.begin(); i != dl_queue.end(); ++i) + { + assert(int(i->finished_blocks.count()) < blocks_per_piece); + } + } +#endif + t->get_policy().piece_finished(p.piece, verified); if (!was_seed && t->is_seed()) diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index d9d434951..9dde4d271 100755 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -971,7 +971,7 @@ namespace libtorrent assert(i != m_downloads.end()); assert((int)i->finished_blocks.count() <= m_blocks_per_piece); int max_blocks = blocks_in_piece(index); - if ((int)i->finished_blocks.count() != max_blocks) return false; + if ((int)i->finished_blocks.count() < max_blocks) return false; assert((int)i->requested_blocks.count() == max_blocks); return true; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 4dedf0302..9bdcfe56d 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1029,17 +1029,18 @@ namespace libtorrent { namespace detail void session_impl::connection_completed( boost::intrusive_ptr const& p) #ifndef NDEBUG - try + try #endif { mutex_t::scoped_lock l(m_mutex); - - if (m_abort) return; connection_map::iterator i = m_half_open.find(p->get_socket()); m_connections.insert(std::make_pair(p->get_socket(), p)); assert(i != m_half_open.end()); if (i != m_half_open.end()) m_half_open.erase(i); + + if (m_abort) return; + process_connection_queue(); } #ifndef NDEBUG @@ -1123,13 +1124,13 @@ namespace libtorrent { namespace detail assert(m_abort); m_abort = true; - while (!m_connections.empty()) - m_connections.begin()->second->disconnect(); + m_connection_queue.clear(); while (!m_half_open.empty()) m_half_open.begin()->second->disconnect(); - m_connection_queue.clear(); + while (!m_connections.empty()) + m_connections.begin()->second->disconnect(); #ifndef NDEBUG for (torrent_map::iterator i = m_torrents.begin();