diff --git a/include/libtorrent/bandwidth_manager.hpp b/include/libtorrent/bandwidth_manager.hpp index da251cf4b..4a3772c44 100644 --- a/include/libtorrent/bandwidth_manager.hpp +++ b/include/libtorrent/bandwidth_manager.hpp @@ -203,10 +203,23 @@ struct bandwidth_manager m_history_timer.cancel(); } +#ifndef NDEBUG + bool is_queued(PeerConnection const* peer) + { + for (typename queue_t::iterator i = m_queue.begin() + , end(m_queue.end()); i != end; ++i) + { + if (i->peer.get() == peer) return true; + } + return false; + } +#endif + + // non prioritized means that, if there's a line for bandwidth, // others will cut in front of the non-prioritized peers. // this is used by web seeds - void request_bandwidth(intrusive_ptr peer + void request_bandwidth(intrusive_ptr const& peer , int blk , bool non_prioritized) throw() { @@ -217,13 +230,7 @@ struct bandwidth_manager // make sure this peer isn't already in line // waiting for bandwidth -#ifndef NDEBUG - for (typename queue_t::iterator i = m_queue.begin() - , end(m_queue.end()); i != end; ++i) - { - TORRENT_ASSERT(i->peer < peer || peer < i->peer); - } -#endif + TORRENT_ASSERT(!is_queued(peer.get())); boost::shared_ptr t = peer->associated_torrent().lock(); diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index cf3569318..dc057ba98 100755 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -665,6 +665,10 @@ namespace libtorrent // request is in progress. bool m_writing; bool m_reading; +#ifndef NDEBUG + bool m_requested_write_quota; + bool m_requested_read_quota; +#endif // if set to non-zero, this peer will always prefer // to request entire n pieces, rather than blocks. diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 9bd089234..e6800004f 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -132,6 +132,10 @@ namespace libtorrent + boost::lexical_cast(m_remote.port()), m_ses.listen_port()); (*m_logger) << "*** OUTGOING CONNECTION\n"; #endif +#ifndef NDEBUG + m_requested_read_quota = false; + m_requested_write_quota = false; +#endif boost::shared_ptr t = m_torrent.lock(); TORRENT_ASSERT(t); @@ -215,6 +219,10 @@ namespace libtorrent (*m_logger) << "*** INCOMING CONNECTION\n"; #endif +#ifndef NDEBUG + m_requested_read_quota = false; + m_requested_write_quota = false; +#endif std::fill(m_peer_id.begin(), m_peer_id.end(), 0); } @@ -2380,12 +2388,20 @@ namespace libtorrent { TORRENT_ASSERT(m_writing); m_writing = false; +#ifndef NDEBUG + TORRENT_ASSERT(m_requested_write_quota); + m_requested_write_quota = false; +#endif setup_send(); } else if (channel == download_channel) { TORRENT_ASSERT(m_reading); m_reading = false; +#ifndef NDEBUG + TORRENT_ASSERT(m_requested_read_quota); + m_requested_read_quota = false; +#endif setup_receive(); } } @@ -2434,6 +2450,10 @@ namespace libtorrent TORRENT_ASSERT(!m_writing); // peers that we are not interested in are non-prioritized m_writing = true; +#ifndef NDEBUG + TORRENT_ASSERT(!m_requested_write_quota); + m_requested_write_quota = true; +#endif t->request_bandwidth(upload_channel, self() , !(is_interesting() && !has_peer_choked())); } @@ -2488,6 +2508,10 @@ namespace libtorrent (*m_logger) << "req bandwidth [ " << download_channel << " ]\n"; #endif m_reading = true; +#ifndef NDEBUG + TORRENT_ASSERT(!m_requested_read_quota); + m_requested_read_quota = true; +#endif t->request_bandwidth(download_channel, self(), m_non_prioritized); } return;