lt sync 1959

This commit is contained in:
Marcos Pinto 2008-01-24 23:17:49 +00:00
commit 34b1726178
4 changed files with 21 additions and 18 deletions

View file

@ -189,10 +189,13 @@ struct bandwidth_manager
TORRENT_ASSERT(current_quota == m_current_quota); TORRENT_ASSERT(current_quota == m_current_quota);
typename queue_t::const_iterator j = m_queue.begin(); typename queue_t::const_iterator j = m_queue.begin();
++j; if (j != m_queue.end())
for (typename queue_t::const_iterator i = m_queue.begin() {
, end(m_queue.end()); i != end && j != end; ++i, ++j) ++j;
TORRENT_ASSERT(i->priority >= j->priority); for (typename queue_t::const_iterator i = m_queue.begin()
, end(m_queue.end()); i != end && j != end; ++i, ++j)
TORRENT_ASSERT(i->priority >= j->priority);
}
} }
#endif #endif

View file

@ -376,6 +376,7 @@ namespace libtorrent
peer_connection::~peer_connection() peer_connection::~peer_connection()
{ {
// INVARIANT_CHECK; // INVARIANT_CHECK;
TORRENT_ASSERT(!m_in_constructor);
TORRENT_ASSERT(m_disconnecting); TORRENT_ASSERT(m_disconnecting);
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
@ -593,6 +594,7 @@ namespace libtorrent
// check to make sure we don't have another connection with the same // check to make sure we don't have another connection with the same
// info_hash and peer_id. If we do. close this connection. // info_hash and peer_id. If we do. close this connection.
t->attach_peer(this); t->attach_peer(this);
if (m_disconnecting) return;
m_torrent = wpt; m_torrent = wpt;
TORRENT_ASSERT(!m_torrent.expired()); TORRENT_ASSERT(!m_torrent.expired());
@ -1994,16 +1996,17 @@ namespace libtorrent
{ {
session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
TORRENT_ASSERT(!m_in_constructor);
boost::intrusive_ptr<peer_connection> me(this); boost::intrusive_ptr<peer_connection> me(this);
INVARIANT_CHECK; INVARIANT_CHECK;
if (m_disconnecting) return; if (m_disconnecting) return;
m_disconnecting = true; if (m_connecting && m_connection_ticket >= 0)
if (m_connecting) {
m_ses.m_half_open.done(m_connection_ticket); m_ses.m_half_open.done(m_connection_ticket);
m_connection_ticket = -1;
m_ses.m_io_service.post(boost::bind(&close_socket_ignore_error, m_socket)); }
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
@ -2029,7 +2032,9 @@ namespace libtorrent
m_torrent.reset(); m_torrent.reset();
} }
m_disconnecting = true;
m_ses.close_connection(me); m_ses.close_connection(me);
m_ses.m_io_service.post(boost::bind(&close_socket_ignore_error, m_socket));
} }
void peer_connection::set_upload_limit(int limit) void peer_connection::set_upload_limit(int limit)
@ -3165,7 +3170,6 @@ namespace libtorrent
bool peer_connection::is_seed() const bool peer_connection::is_seed() const
{ {
INVARIANT_CHECK;
// if m_num_pieces == 0, we probably don't have the // if m_num_pieces == 0, we probably don't have the
// metadata yet. // metadata yet.
return m_num_pieces == (int)m_have_piece.size() && m_num_pieces > 0; return m_num_pieces == (int)m_have_piece.size() && m_num_pieces > 0;

View file

@ -2441,6 +2441,7 @@ namespace detail
boost::shared_ptr<torrent> t = (*i)->associated_torrent().lock(); boost::shared_ptr<torrent> t = (*i)->associated_torrent().lock();
peer_connection* p = i->get(); peer_connection* p = i->get();
TORRENT_ASSERT(!p->is_disconnecting());
if (!p->is_choked()) ++unchokes; if (!p->is_choked()) ++unchokes;
if (p->peer_info_struct() if (p->peer_info_struct()
&& p->peer_info_struct()->optimistically_unchoked) && p->peer_info_struct()->optimistically_unchoked)

View file

@ -2164,13 +2164,8 @@ namespace libtorrent
throw protocol_error("reached connection limit"); throw protocol_error("reached connection limit");
} }
TORRENT_ASSERT(m_connections.find(p) == m_connections.end());
peer_iterator ci = m_connections.insert(p).first;
try try
{ {
// if new_connection throws, we have to remove the
// it from the list.
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i) , end(m_extensions.end()); i != end; ++i)
@ -2179,15 +2174,14 @@ namespace libtorrent
if (pp) p->add_extension(pp); if (pp) p->add_extension(pp);
} }
#endif #endif
TORRENT_ASSERT(m_connections.find(p) == ci); m_policy.new_connection(*p);
TORRENT_ASSERT(*ci == p);
m_policy.new_connection(**ci);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
m_connections.erase(ci);
throw; throw;
} }
TORRENT_ASSERT(m_connections.find(p) == m_connections.end());
peer_iterator ci = m_connections.insert(p).first;
TORRENT_ASSERT(p->remote() == p->get_socket()->remote_endpoint()); TORRENT_ASSERT(p->remote() == p->get_socket()->remote_endpoint());
#ifndef NDEBUG #ifndef NDEBUG
@ -2631,6 +2625,7 @@ namespace libtorrent
for (int c = 0; c < 2; ++c) for (int c = 0; c < 2; ++c)
{ {
queue_t::const_iterator j = m_bandwidth_queue[c].begin(); queue_t::const_iterator j = m_bandwidth_queue[c].begin();
if (j == m_bandwidth_queue[c].end()) continue;
++j; ++j;
for (queue_t::const_iterator i = m_bandwidth_queue[c].begin() for (queue_t::const_iterator i = m_bandwidth_queue[c].begin()
, end(m_bandwidth_queue[c].end()); i != end && j != end; ++i, ++j) , end(m_bandwidth_queue[c].end()); i != end && j != end; ++i, ++j)