fixed a bug in http_seed_connection::downloading_piece_progress which would sometimes trigger an assert

This commit is contained in:
Arvid Norberg 2010-10-17 19:19:17 +00:00
parent 643a49f022
commit 973a1c45f2
2 changed files with 10 additions and 5 deletions

View File

@ -117,7 +117,11 @@ namespace libtorrent
TORRENT_ASSERT(receive_buffer_size < t->block_size()); TORRENT_ASSERT(receive_buffer_size < t->block_size());
ret.bytes_downloaded = t->block_size() - receive_buffer_size; ret.bytes_downloaded = t->block_size() - receive_buffer_size;
} }
ret.block_index = (pr.start + ret.bytes_downloaded) / t->block_size(); // this is used to make sure that the block_index stays within
// bounds. If the entire piece is downloaded, the block_index
// would otherwise point to one past the end
int correction = ret.bytes_downloaded ? -1 : 0;
ret.block_index = (pr.start + ret.bytes_downloaded + correction) / t->block_size();
ret.full_block_bytes = t->block_size(); ret.full_block_bytes = t->block_size();
const int last_piece = t->torrent_file().num_pieces() - 1; const int last_piece = t->torrent_file().num_pieces() - 1;
if (ret.piece_index == last_piece && ret.block_index if (ret.piece_index == last_piece && ret.block_index

View File

@ -117,10 +117,11 @@ namespace libtorrent
ret.piece_index = m_requests.front().piece; ret.piece_index = m_requests.front().piece;
ret.bytes_downloaded = m_block_pos % t->block_size(); ret.bytes_downloaded = m_block_pos % t->block_size();
if (m_block_pos) // this is used to make sure that the block_index stays within
ret.block_index = (m_requests.front().start + m_block_pos - 1) / t->block_size(); // bounds. If the entire piece is downloaded, the block_index
else // would otherwise point to one past the end
ret.block_index = (m_requests.front().start + m_block_pos) / t->block_size(); int correction = m_block_pos ? -1 : 0;
ret.block_index = (m_requests.front().start + m_block_pos + correction) / t->block_size();
TORRENT_ASSERT(ret.block_index < piece_block::invalid.block_index); TORRENT_ASSERT(ret.block_index < piece_block::invalid.block_index);
TORRENT_ASSERT(ret.piece_index < piece_block::invalid.piece_index); TORRENT_ASSERT(ret.piece_index < piece_block::invalid.piece_index);