update callback interface for async_check_files and async_flush_piece

This commit is contained in:
arvidn 2016-11-22 19:03:27 -05:00 committed by Arvid Norberg
parent d8662533d5
commit f08501b869
8 changed files with 41 additions and 34 deletions

View File

@ -75,10 +75,9 @@ namespace libtorrent
virtual void async_check_files(storage_interface* storage
, add_torrent_params const* resume_data
, std::vector<std::string>& links
, std::function<void(disk_io_job const*)> handler) = 0;
, std::function<void(int, storage_error const&)> handler) = 0;
virtual void async_flush_piece(storage_interface* storage, int piece
, std::function<void(disk_io_job const*)> handler
= std::function<void(disk_io_job const*)>()) = 0;
, std::function<void()> handler = std::function<void()>()) = 0;
virtual void async_stop_torrent(storage_interface* storage
, std::function<void(disk_io_job const*)> handler)= 0;
virtual void async_rename_file(storage_interface* storage, int index, std::string const& name

View File

@ -159,6 +159,7 @@ namespace libtorrent
using hash_handler = std::function<void(int, int, sha1_hash const&, storage_error const&)>;
using move_handler = std::function<void(int, std::string const&, storage_error const&)>;
using release_handler = std::function<void()>;
using check_handler = std::function<void(int, storage_error const&)>;
using generic_handler = std::function<void(disk_io_job const*)>;
boost::variant<read_handler
@ -166,6 +167,7 @@ namespace libtorrent
, hash_handler
, move_handler
, release_handler
, check_handler
, generic_handler> callback;
// the error code from the file operation

View File

@ -309,14 +309,13 @@ namespace libtorrent
void async_check_files(storage_interface* storage
, add_torrent_params const* resume_data
, std::vector<std::string>& links
, std::function<void(disk_io_job const*)> handler) override;
, std::function<void(int, storage_error const&)> handler) override;
void async_rename_file(storage_interface* storage, int index, std::string const& name
, std::function<void(disk_io_job const*)> handler) override;
void async_stop_torrent(storage_interface* storage
, std::function<void(disk_io_job const*)> handler) override;
void async_flush_piece(storage_interface* storage, int piece
, std::function<void(disk_io_job const*)> handler
= std::function<void(disk_io_job const*)>()) override;
, std::function<void()> handler = std::function<void()>()) override;
void async_set_file_priority(storage_interface* storage
, std::vector<std::uint8_t> const& prio
, std::function<void(disk_io_job const*)> handler) override;

View File

@ -351,8 +351,8 @@ namespace libtorrent
bt_peer_connection* find_peer(tcp::endpoint const& ep) const;
peer_connection* find_peer(sha1_hash const& pid);
void on_resume_data_checked(disk_io_job const* j);
void on_force_recheck(disk_io_job const* j);
void on_resume_data_checked(int status, storage_error const& error);
void on_force_recheck(int status, storage_error const& error);
void on_piece_hashed(int status, int piece, sha1_hash const& piece_hash
, storage_error const& error);
void files_checked();

View File

@ -70,6 +70,12 @@ namespace libtorrent
h();
}
void operator()(disk_io_job::check_handler& h) const
{
if (!h) return;
h(m_job.ret, m_job.error);
}
void operator()(disk_io_job::generic_handler& h) const
{
if (!h) return;

View File

@ -1831,7 +1831,7 @@ namespace libtorrent
void disk_io_thread::async_check_files(storage_interface* storage
, add_torrent_params const* resume_data
, std::vector<std::string>& links
, std::function<void(disk_io_job const*)> handler)
, std::function<void(int, storage_error const&)> handler)
{
std::vector<std::string>* links_vector
= new std::vector<std::string>();
@ -1893,7 +1893,7 @@ namespace libtorrent
}
void disk_io_thread::async_flush_piece(storage_interface* storage, int piece
, std::function<void(disk_io_job const*)> handler)
, std::function<void()> handler)
{
disk_io_job* j = allocate_job(disk_io_job::flush_piece);
j->storage = storage->shared_from_this();

View File

@ -1883,7 +1883,7 @@ namespace libtorrent
m_ses.disk_thread().async_check_files(
m_storage.get(), m_add_torrent_params ? m_add_torrent_params.get() : nullptr
, links, std::bind(&torrent::on_resume_data_checked
, shared_from_this(), _1));
, shared_from_this(), _1, _2));
// async_check_files will gut links
#ifndef TORRENT_DISABLE_LOGGING
debug_log("init, async_check_files");
@ -1929,7 +1929,8 @@ namespace libtorrent
return nullptr;
}
void torrent::on_resume_data_checked(disk_io_job const* j) try
void torrent::on_resume_data_checked(int const status
, storage_error const& error) try
{
// hold a reference until this function returns
@ -1948,11 +1949,11 @@ namespace libtorrent
TORRENT_ASSERT(is_single_thread());
if (j->ret == disk_interface::fatal_disk_error)
if (status == disk_interface::fatal_disk_error)
{
TORRENT_ASSERT(m_outstanding_check_files == false);
m_add_torrent_params.reset();
handle_disk_error("check_resume_data", j->error);
handle_disk_error("check_resume_data", error);
auto_managed(false);
pause();
set_state(torrent_status::checking_files);
@ -1993,24 +1994,24 @@ namespace libtorrent
// only report this error if the user actually provided resume data
// (i.e. m_add_torrent_params->have_pieces)
if ((j->error || j->ret != 0)
if ((error || status != 0)
&& m_add_torrent_params
&& !m_add_torrent_params->have_pieces.empty()
&& m_ses.alerts().should_post<fastresume_rejected_alert>())
{
m_ses.alerts().emplace_alert<fastresume_rejected_alert>(get_handle()
, j->error.ec
, resolve_filename(j->error.file)
, j->error.operation_str());
, error.ec
, resolve_filename(error.file)
, error.operation_str());
}
#ifndef TORRENT_DISABLE_LOGGING
if (should_log())
{
if (j->ret != 0)
if (status != 0)
{
debug_log("fastresume data rejected: ret: %d (%d) %s"
, j->ret, j->error.ec.value(), j->error.ec.message().c_str());
, status, error.ec.value(), error.ec.message().c_str());
}
else
{
@ -2019,7 +2020,7 @@ namespace libtorrent
}
#endif
bool should_start_full_check = j->ret != 0;
bool should_start_full_check = status != 0;
// if we got a partial pieces bitfield, it means we were in the middle of
// checking this torrent. pick it up where we left off
@ -2037,12 +2038,12 @@ namespace libtorrent
// that when the resume data check fails. For instance, if the resume data
// is incorrect, but we don't have any files, we skip the check and initialize
// the storage to not have anything.
if (j->ret == 0)
if (status == 0)
{
// there are either no files for this torrent
// or the resume_data was accepted
if (!j->error && m_add_torrent_params)
if (!error && m_add_torrent_params)
{
// --- PIECES ---
@ -2189,10 +2190,10 @@ namespace libtorrent
std::vector<std::string> links;
m_ses.disk_thread().async_check_files(m_storage.get(), nullptr
, links, std::bind(&torrent::on_force_recheck
, shared_from_this(), _1));
, shared_from_this(), _1, _2));
}
void torrent::on_force_recheck(disk_io_job const* j) try
void torrent::on_force_recheck(int const status, storage_error const& error) try
{
TORRENT_ASSERT(is_single_thread());
@ -2201,12 +2202,12 @@ namespace libtorrent
if (m_abort) return;
if (j->ret == disk_interface::fatal_disk_error)
if (error)
{
handle_disk_error("force_recheck", j->error);
handle_disk_error("force_recheck", error);
return;
}
if (j->ret == 0)
if (status == 0)
{
// if there are no files, just start
files_checked();

View File

@ -68,17 +68,17 @@ void on_read_piece(int ret, disk_io_job const& j, char const* data, int size)
if (ret > 0) TEST_CHECK(std::equal(j.buffer.disk_block, j.buffer.disk_block + ret, data));
}
void on_check_resume_data(disk_io_job const* j, bool* done)
void on_check_resume_data(int const status, storage_error const& error, bool* done)
{
std::cerr << time_now_string() << " on_check_resume_data ret: " << j->ret;
switch (j->ret)
std::cerr << time_now_string() << " on_check_resume_data ret: " << status;
switch (status)
{
case disk_interface::no_error:
std::cerr << time_now_string() << " success" << std::endl;
break;
case disk_interface::fatal_disk_error:
std::cerr << time_now_string() << " disk error: " << j->error.ec.message()
<< " file: " << j->error.file << std::endl;
std::cerr << time_now_string() << " disk error: " << error.ec.message()
<< " file: " << error.file << std::endl;
break;
case disk_interface::need_full_check:
std::cerr << time_now_string() << " need full check" << std::endl;
@ -480,7 +480,7 @@ void test_check_files(std::string const& test_path
add_torrent_params frd;
std::vector<std::string> links;
io.async_check_files(pm.get(), &frd, links
, std::bind(&on_check_resume_data, _1, &done));
, std::bind(&on_check_resume_data, _1, _2, &done));
io.submit_jobs();
ios.reset();
run_until(ios, done);