fix file_completed_alert (#880)

This commit is contained in:
Arvid Norberg 2016-07-03 14:48:18 -04:00 committed by GitHub
parent 7ed980659f
commit cf65f85dc3
6 changed files with 50 additions and 9 deletions

View File

@ -1,5 +1,7 @@
1.1.1 release
* fix bug where file_completed_alert would not be posted unless file_progress
had been queries by the client
* move files one-by-one when moving storage for a torrent
* fix bug in enum_net() for BSD and Mac
* fix bug in python binding of announce_entry

View File

@ -56,6 +56,7 @@ namespace aux
void export_progress(std::vector<boost::int64_t> &fp);
bool empty() const { return m_file_progress.empty(); }
void clear();
void update(file_storage const& fs, int index

View File

@ -801,10 +801,14 @@ namespace libtorrent
return std::binary_search(m_predictive_pieces.begin(), m_predictive_pieces.end(), index);
}
private:
// called when we learn that we have a piece
// only once per piece
void we_have(int index);
public:
int num_have() const
{
// pretend we have every piece when in seed mode

View File

@ -414,6 +414,41 @@ TORRENT_TEST(delete_partfile)
TEST_CHECK(!ec);
}
TORRENT_TEST(torrent_completed_alert)
{
int num_file_completed = false;
setup_swarm(2, swarm_test::download
// add session
, [](lt::settings_pack& pack)
{
pack.set_int(lt::settings_pack::alert_mask, alert::progress_notification);
}
// add torrent
, [](lt::add_torrent_params&) {}
// on alert
, [&](lt::alert const* a, lt::session&)
{
auto tc = alert_cast<lt::file_completed_alert>(a);
if (tc == nullptr) return;
++num_file_completed;
}
// terminate
, [](int ticks, lt::session& ses) -> bool
{
if (ticks > 80)
{
TEST_ERROR("timeout");
return true;
}
if (!is_seed(ses)) return false;
printf("completed in %d ticks\n", ticks);
return true;
});
TEST_EQUAL(num_file_completed, 1);
}
// TODO: add test that makes sure a torrent in graceful pause mode won't make
// outgoing connections
// TODO: add test that makes sure a torrent in graceful pause mode won't accept

View File

@ -80,7 +80,7 @@ namespace libtorrent { namespace aux
while (size)
{
int add = (std::min)(boost::int64_t(size), fs.file_size(file_index) - file_offset);
int const add = (std::min)(boost::int64_t(size), fs.file_size(file_index) - file_offset);
TORRENT_ASSERT(add >= 0);
m_file_progress[file_index] += add;

View File

@ -1354,6 +1354,13 @@ namespace libtorrent
+ block_size() - 1) / block_size();
m_picker->init(blocks_per_piece, blocks_in_last_piece, m_torrent_file->num_pieces());
// initialize the file progress too
if (m_file_progress.empty())
{
TORRENT_ASSERT(has_picker());
m_file_progress.init(picker(), m_torrent_file->files());
}
update_gauge();
for (peer_iterator i = m_connections.begin()
@ -2612,7 +2619,6 @@ namespace libtorrent
// removing the piece picker will clear the user priorities
// instead, just clear which pieces we have
// m_picker.reset();
if (m_picker)
{
int blocks_per_piece = (m_torrent_file->piece_length() + block_size() - 1) / block_size();
@ -11693,13 +11699,6 @@ namespace libtorrent
return;
}
// if this is the first time the client asks for file progress.
// allocate it and make sure it's up to date
// we cover the case where we're a seed above
TORRENT_ASSERT(has_picker());
m_file_progress.init(picker(), m_torrent_file->files());
m_file_progress.export_progress(fp);
if (flags & torrent_handle::piece_granularity)