fix for invalid iterators when changing piece priorities causes peers to disconnect

This commit is contained in:
Arvid Norberg 2008-09-17 23:14:59 +00:00
parent d8cc89fd13
commit cd1301b1c9
1 changed files with 12 additions and 3 deletions

View File

@ -1397,10 +1397,13 @@ namespace libtorrent
// since this piece just passed, we might have // since this piece just passed, we might have
// become uninterested in some peers where this // become uninterested in some peers where this
// was the last piece we were interested in // was the last piece we were interested in
for (peer_iterator i = m_connections.begin() for (peer_iterator i = m_connections.begin();
, end(m_connections.end()); i != end; ++i) i != m_connections.end();)
{ {
peer_connection* p = *i; peer_connection* p = *i;
// update_interest may disconnect the peer and
// invalidate the iterator
++i;
// if we're not interested already, no need to check // if we're not interested already, no need to check
if (!p->is_interesting()) continue; if (!p->is_interesting()) continue;
// if the peer doesn't have the piece we just got, it // if the peer doesn't have the piece we just got, it
@ -1854,8 +1857,14 @@ namespace libtorrent
// updates the interested flag in peers // updates the interested flag in peers
void torrent::update_peer_interest(bool was_finished) void torrent::update_peer_interest(bool was_finished)
{ {
for (peer_iterator i = begin(); i != end(); ++i) for (peer_iterator i = begin(); i != end();)
{
peer_connection* p = *i;
// update_interest may disconnect the peer and
// invalidate the iterator
++i;
(*i)->update_interest(); (*i)->update_interest();
}
// the torrent just became finished // the torrent just became finished
if (is_finished() && !was_finished) if (is_finished() && !was_finished)