diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 1258f5e51..3162030e8 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -852,6 +852,13 @@ namespace libtorrent void clear_in_state_update() { m_in_state_updates = false; } + void inc_num_connecting() + { ++m_num_connecting; } + void dec_num_connecting() + { + TORRENT_ASSERT(m_num_connecting > 0); + --m_num_connecting; + } #ifdef TORRENT_USE_OPENSSL void set_ssl_cert(std::string const& certificate , std::string const& private_key @@ -955,15 +962,16 @@ namespace libtorrent public: #endif std::set m_connections; +#ifdef TORRENT_DEBUG + private: +#endif + // of all peers in m_connections, this is the number // of peers that are outgoing and still waiting to // complete the connection. This is used to possibly // kick out these connections when we get incoming // connections (if we've reached the connection limit) int m_num_connecting; -#ifdef TORRENT_DEBUG - private: -#endif // The list of web seeds in this torrent. Seeds // with fatal errors are removed from the set diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 3d94cae4e..ad20dfe82 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -204,10 +204,7 @@ namespace libtorrent // if t is NULL, we better not be connecting, since // we can't decrement the connecting counter TORRENT_ASSERT(t || !m_connecting); - if (m_connecting && t) - { - ++t->m_num_connecting; - } + if (m_connecting && t) t->inc_num_connecting(); m_est_reciprocation_rate = m_ses.m_settings.default_est_reciprocation_rate; #if TORRENT_USE_I2P @@ -928,8 +925,7 @@ namespace libtorrent TORRENT_ASSERT(!m_connecting); if (m_connecting && t) { - TORRENT_ASSERT(t->m_num_connecting > 0); - --t->m_num_connecting; + t->dec_num_connecting(); m_connecting = false; } @@ -3419,8 +3415,7 @@ namespace libtorrent boost::shared_ptr t = m_torrent.lock(); if (m_connecting) { - TORRENT_ASSERT(t->m_num_connecting > 0); - --t->m_num_connecting; + t->dec_num_connecting(); m_connecting = false; } @@ -3553,8 +3548,7 @@ namespace libtorrent boost::shared_ptr t = m_torrent.lock(); if (m_connecting) { - TORRENT_ASSERT(t->m_num_connecting > 0); - --t->m_num_connecting; + t->dec_num_connecting(); m_connecting = false; } if (m_connection_ticket >= 0) @@ -4089,8 +4083,7 @@ namespace libtorrent TORRENT_ASSERT(t || !m_connecting); if (m_connecting && t) { - TORRENT_ASSERT(t->m_num_connecting > 0); - --t->m_num_connecting; + t->dec_num_connecting(); m_connecting = false; } disconnect(errors::torrent_aborted); @@ -5475,8 +5468,7 @@ namespace libtorrent TORRENT_ASSERT(t || !m_connecting); if (m_connecting && t) { - TORRENT_ASSERT(t->m_num_connecting > 0); - --t->m_num_connecting; + t->dec_num_connecting(); m_connecting = false; } m_ses.m_half_open.done(m_connection_ticket);