From 23936310d2745e6f25967d1a073500a9e3b9a184 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 26 Feb 2004 18:55:10 +0000 Subject: [PATCH] *** empty log message *** --- Jamfile | 1 + include/libtorrent/policy.hpp | 2 +- src/policy.cpp | 31 ++++++++++++++++++++----------- src/session.cpp | 16 ++++++++-------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Jamfile b/Jamfile index 577fcdd6b..29dcaf4a2 100755 --- a/Jamfile +++ b/Jamfile @@ -18,6 +18,7 @@ project torrent ./include $(BOOST_ROOT) release:NDEBUG + BOOST_ALL_NO_LIB # devstudio switches diff --git a/include/libtorrent/policy.hpp b/include/libtorrent/policy.hpp index 5dab457ec..4cbf827ce 100755 --- a/include/libtorrent/policy.hpp +++ b/include/libtorrent/policy.hpp @@ -170,7 +170,7 @@ namespace libtorrent peer* find_unchoke_candidate(); - void connect_peer(peer *); + bool connect_peer(peer *); bool connect_one_peer(); diff --git a/src/policy.cpp b/src/policy.cpp index 23fdf2a4a..e391e11bd 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -777,7 +777,7 @@ namespace libtorrent if (i->banned) return; - if(m_torrent->num_peers() < m_max_connections) + if (m_torrent->num_peers() < m_max_connections) { connect_peer(&*i); } @@ -909,19 +909,28 @@ namespace libtorrent assert(!p->connection); assert(p->type==peer::connectable); - connect_peer(p); - return true; + return connect_peer(p); } - void policy::connect_peer(peer *p) + bool policy::connect_peer(peer *p) { - p->connection = &m_torrent->connect_to_peer(p->id); - p->connection->add_stat(p->prev_amount_download, p->prev_amount_upload); - p->prev_amount_download = 0; - p->prev_amount_upload = 0; - p->connected = - m_last_optimistic_disconnect = - boost::posix_time::second_clock::local_time(); + try + { + p->connection = &m_torrent->connect_to_peer(p->id); + p->connection->add_stat(p->prev_amount_download, p->prev_amount_upload); + p->prev_amount_download = 0; + p->prev_amount_upload = 0; + p->connected = + m_last_optimistic_disconnect = + boost::posix_time::second_clock::local_time(); + return true; + } + catch (network_error&) + { + // TODO: remove the peer +// m_peers.erase(std::find(m_peers.begin(), m_peers.end(), p)); + } + return false; } bool policy::disconnect_one_peer() diff --git a/src/session.cpp b/src/session.cpp index 9ed2fbcb2..738db78c9 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -290,7 +290,7 @@ namespace libtorrent { namespace detail { m_connections.erase(m_disconnect_peer.back()); m_disconnect_peer.pop_back(); - assert(m_selector.count_read_monitors() == (int)m_connections.size() + 1); + assert(m_selector.count_read_monitors() == (int)m_connections.size() + (bool)m_listen_socket); } } @@ -403,7 +403,7 @@ namespace libtorrent { namespace detail boost::mutex::scoped_lock l(m_mutex); // +1 for the listen socket - assert(m_selector.count_read_monitors() == (int)m_connections.size() + 1); + assert(m_selector.count_read_monitors() == (int)m_connections.size() + (bool)m_listen_socket); if (m_abort) { @@ -466,7 +466,7 @@ namespace libtorrent { namespace detail m_selector.remove(*i); m_connections.erase(p); - assert(m_selector.count_read_monitors() == (int)m_connections.size() + 1); + assert(m_selector.count_read_monitors() == (int)m_connections.size() + (bool)m_listen_socket); t->abort(); } catch (std::exception& e) @@ -481,7 +481,7 @@ namespace libtorrent { namespace detail m_selector.remove(*i); m_connections.erase(p); - assert(m_selector.count_read_monitors() == (int)m_connections.size() + 1); + assert(m_selector.count_read_monitors() == (int)m_connections.size() + (bool)m_listen_socket); } } } @@ -556,7 +556,7 @@ namespace libtorrent { namespace detail m_selector.remove(*i); m_connections.erase(p); - assert(m_selector.count_read_monitors() == (int)m_connections.size() + 1); + assert(m_selector.count_read_monitors() == (int)m_connections.size() + (bool)m_listen_socket); t->abort(); } catch (std::exception& e) @@ -570,7 +570,7 @@ namespace libtorrent { namespace detail // from the connection-list m_selector.remove(*i); m_connections.erase(p); - assert(m_selector.count_read_monitors() == (int)m_connections.size() + 1); + assert(m_selector.count_read_monitors() == (int)m_connections.size() + (bool)m_listen_socket); } } } @@ -603,7 +603,7 @@ namespace libtorrent { namespace detail if (p != m_connections.end()) { m_connections.erase(p); - assert(m_selector.count_read_monitors() == (int)m_connections.size() + 1); + assert(m_selector.count_read_monitors() == (int)m_connections.size() + (bool)m_listen_socket); } } @@ -644,7 +644,7 @@ namespace libtorrent { namespace detail } m_selector.remove(j->first); m_connections.erase(j); - assert(m_selector.count_read_monitors() == (int)m_connections.size() + 1); + assert(m_selector.count_read_monitors() == (int)m_connections.size() + (bool)m_listen_socket); continue; }