is_seed() is not a good indicator of whether or not we have a piece picker. use has_picker() instead

This commit is contained in:
Arvid Norberg 2012-04-25 19:16:22 +00:00
parent 4ae349f61f
commit 2fc7f2191f
3 changed files with 11 additions and 16 deletions

View File

@ -522,9 +522,8 @@ namespace libtorrent
// when we get a have message, this is called for that piece
void peer_has(int index)
{
if (m_picker.get())
if (has_picker())
{
TORRENT_ASSERT(!is_seed());
m_picker->inc_refcount(index);
}
#ifdef TORRENT_DEBUG
@ -538,9 +537,8 @@ namespace libtorrent
// when we get a bitfield message, this is called for that piece
void peer_has(bitfield const& bits)
{
if (m_picker.get())
if (has_picker())
{
TORRENT_ASSERT(!is_seed());
m_picker->inc_refcount(bits);
}
#ifdef TORRENT_DEBUG
@ -553,9 +551,8 @@ namespace libtorrent
void peer_has_all()
{
if (m_picker.get())
if (has_picker())
{
TORRENT_ASSERT(!is_seed());
m_picker->inc_refcount_all();
}
#ifdef TORRENT_DEBUG
@ -568,9 +565,8 @@ namespace libtorrent
void peer_lost(int index)
{
if (m_picker.get())
if (has_picker())
{
TORRENT_ASSERT(!is_seed());
m_picker->dec_refcount(index);
}
#ifdef TORRENT_DEBUG

View File

@ -3316,7 +3316,7 @@ namespace libtorrent
// if we're a seed, we don't have a piece picker
// so we don't have to worry about invariants getting
// out of sync with it
if (t->is_seed()) continue;
if (!t->has_picker()) continue;
// this can happen if a block times out, is re-requested and
// then arrives "unexpectedly"

View File

@ -1160,7 +1160,7 @@ namespace libtorrent
int blocks_in_piece = (piece_size + block_size() - 1) / block_size();
// avoid crash trying to access the picker when there is none
if (is_seed()) return;
if (!has_picker()) return;
if (picker().have_piece(piece)
&& (flags & torrent::overwrite_existing) == 0)
@ -1204,8 +1204,6 @@ namespace libtorrent
INVARIANT_CHECK;
if (is_seed()) return;
if (m_abort)
{
piece_block block_finished(p.piece, p.start / block_size());
@ -1220,6 +1218,8 @@ namespace libtorrent
return;
}
if (!has_picker()) return;
// if we already have this block, just ignore it.
// this can happen if the same block is passed in through
// add_piece() multiple times
@ -3733,7 +3733,7 @@ namespace libtorrent
INVARIANT_CHECK;
TORRENT_ASSERT(valid_metadata());
if (is_seed())
if (!has_picker())
{
avail.clear();
return;
@ -5137,7 +5137,7 @@ namespace libtorrent
// if this torrent is a seed, we won't have a piece picker
// and there will be no half-finished pieces.
if (!is_seed())
if (has_picker())
{
const std::vector<piece_picker::downloading_piece>& q
= m_picker->get_download_queue();
@ -5394,7 +5394,7 @@ namespace libtorrent
std::vector<block_info>& blk = m_ses.m_block_info_storage;
blk.clear();
if (!valid_metadata() || is_seed()) return;
if (!valid_metadata() || !has_picker()) return;
piece_picker const& p = picker();
std::vector<piece_picker::downloading_piece> const& q
= p.get_download_queue();
@ -6443,7 +6443,6 @@ namespace libtorrent
{
TORRENT_ASSERT(block_size() > 0);
}
// if (is_seed()) TORRENT_ASSERT(m_picker.get() == 0);
for (std::vector<size_type>::const_iterator i = m_file_progress.begin()