fix potential infinite loop in request_time_critical_pieces

This commit is contained in:
Arvid Norberg 2011-08-05 17:35:09 +00:00
parent f38f8c57c4
commit 6a4708ef15
3 changed files with 12 additions and 1 deletions

View File

@ -88,6 +88,7 @@
incoming connection incoming connection
* added more detailed instrumentation of the disk I/O thread * added more detailed instrumentation of the disk I/O thread
* fix for set_piece_deadline
* add reset_piece_deadline function * add reset_piece_deadline function
* fix merkle tree torrent assert * fix merkle tree torrent assert

View File

@ -2745,6 +2745,10 @@ namespace libtorrent
if ((int)m_download_queue.size() + (int)m_request_queue.size() if ((int)m_download_queue.size() + (int)m_request_queue.size()
> m_desired_queue_size * 2) return false; > m_desired_queue_size * 2) return false;
if (on_parole()) return false; if (on_parole()) return false;
if (m_disconnecting) return false;
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
if (t->upload_mode()) return false;
return true; return true;
} }

View File

@ -7037,6 +7037,8 @@ namespace libtorrent
for (std::list<time_critical_piece>::iterator i = m_time_critical_pieces.begin() for (std::list<time_critical_piece>::iterator i = m_time_critical_pieces.begin()
, end(m_time_critical_pieces.end()); i != end; ++i) , end(m_time_critical_pieces.end()); i != end; ++i)
{ {
if (peers.empty()) break;
if (i != m_time_critical_pieces.begin() && i->deadline > now if (i != m_time_critical_pieces.begin() && i->deadline > now
+ milliseconds(m_average_piece_time + m_piece_time_deviation * 4)) + milliseconds(m_average_piece_time + m_piece_time_deviation * 4))
{ {
@ -7079,7 +7081,11 @@ namespace libtorrent
} }
else if (!interesting_blocks.empty()) else if (!interesting_blocks.empty())
{ {
c.add_request(interesting_blocks.front(), peer_connection::req_time_critical); if (!c.add_request(interesting_blocks.front(), peer_connection::req_time_critical))
{
peers.erase(p);
continue;
}
added_request = true; added_request = true;
} }