merged file priority fix from RC_0_16 and keep the disk thread's file priorities up to date
This commit is contained in:
parent
86c704a6ff
commit
a0a41b6c5e
|
@ -41,6 +41,7 @@
|
||||||
* fix uTP edge case where udp socket buffer fills up
|
* fix uTP edge case where udp socket buffer fills up
|
||||||
* fix nagle implementation in uTP
|
* fix nagle implementation in uTP
|
||||||
|
|
||||||
|
* improve support for de-selected files in full allocation mode
|
||||||
* fix dht_bootstrap_alert being posted
|
* fix dht_bootstrap_alert being posted
|
||||||
* SetFileValidData fix on windows (prevents zero-fill)
|
* SetFileValidData fix on windows (prevents zero-fill)
|
||||||
* fix minor lock_files issue on unix
|
* fix minor lock_files issue on unix
|
||||||
|
|
|
@ -116,6 +116,7 @@ namespace libtorrent
|
||||||
, update_settings
|
, update_settings
|
||||||
, read_and_hash
|
, read_and_hash
|
||||||
, cache_piece
|
, cache_piece
|
||||||
|
, file_priority
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
, finalize_file
|
, finalize_file
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -75,6 +75,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
// struct temp_storage : storage_interface
|
// struct temp_storage : storage_interface
|
||||||
// {
|
// {
|
||||||
// temp_storage(file_storage const& fs) : m_files(fs) {}
|
// temp_storage(file_storage const& fs) : m_files(fs) {}
|
||||||
|
// void set_file_priority(std::vector<boost::uint8_t> const& prio) {}
|
||||||
// virtual bool initialize(bool allocate_files) { return false; }
|
// virtual bool initialize(bool allocate_files) { return false; }
|
||||||
// virtual bool has_any_file() { return false; }
|
// virtual bool has_any_file() { return false; }
|
||||||
// virtual int read(char* buf, int slot, int offset, int size)
|
// virtual int read(char* buf, int slot, int offset, int size)
|
||||||
|
@ -193,6 +194,7 @@ namespace libtorrent
|
||||||
// hidden
|
// hidden
|
||||||
storage_interface(): m_disk_pool(0), m_settings(0) {}
|
storage_interface(): m_disk_pool(0), m_settings(0) {}
|
||||||
|
|
||||||
|
|
||||||
// This function is called when the storage is to be initialized. The default storage
|
// This function is called when the storage is to be initialized. The default storage
|
||||||
// will create directories and empty files at this point. If ``allocate_files`` is true,
|
// will create directories and empty files at this point. If ``allocate_files`` is true,
|
||||||
// it will also ``ftruncate`` all files to their target size.
|
// it will also ``ftruncate`` all files to their target size.
|
||||||
|
@ -205,6 +207,10 @@ namespace libtorrent
|
||||||
// If so, the storage will be checked for existing pieces before starting the download.
|
// If so, the storage will be checked for existing pieces before starting the download.
|
||||||
virtual bool has_any_file() = 0;
|
virtual bool has_any_file() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// change the priorities of files.
|
||||||
|
virtual void set_file_priority(std::vector<boost::uint8_t> const& prio) = 0;
|
||||||
|
|
||||||
// These functions should read or write the data in or to the given ``slot`` at the given ``offset``.
|
// These functions should read or write the data in or to the given ``slot`` at the given ``offset``.
|
||||||
// It should read or write ``num_bufs`` buffers sequentially, where the size of each buffer
|
// It should read or write ``num_bufs`` buffers sequentially, where the size of each buffer
|
||||||
// is specified in the buffer array ``bufs``. The file::iovec_t type has the following members::
|
// is specified in the buffer array ``bufs``. The file::iovec_t type has the following members::
|
||||||
|
@ -407,6 +413,7 @@ namespace libtorrent
|
||||||
// hidden
|
// hidden
|
||||||
~default_storage();
|
~default_storage();
|
||||||
|
|
||||||
|
void set_file_priority(std::vector<boost::uint8_t> const& prio);
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
void finalize_file(int file);
|
void finalize_file(int file);
|
||||||
#endif
|
#endif
|
||||||
|
@ -495,6 +502,7 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
disabled_storage(int piece_size) : m_piece_size(piece_size) {}
|
disabled_storage(int piece_size) : m_piece_size(piece_size) {}
|
||||||
|
void set_file_priority(std::vector<boost::uint8_t> const& prio) {}
|
||||||
bool has_any_file() { return false; }
|
bool has_any_file() { return false; }
|
||||||
bool rename_file(int, std::string const&) { return false; }
|
bool rename_file(int, std::string const&) { return false; }
|
||||||
bool release_files() { return false; }
|
bool release_files() { return false; }
|
||||||
|
@ -609,6 +617,10 @@ namespace libtorrent
|
||||||
void async_move_storage(std::string const& p, int flags
|
void async_move_storage(std::string const& p, int flags
|
||||||
, boost::function<void(int, disk_io_job const&)> const& handler);
|
, boost::function<void(int, disk_io_job const&)> const& handler);
|
||||||
|
|
||||||
|
void async_set_file_priority(
|
||||||
|
std::vector<boost::uint8_t> const& prios
|
||||||
|
, boost::function<void(int, disk_io_job const&)> const& handler);
|
||||||
|
|
||||||
void async_save_resume_data(
|
void async_save_resume_data(
|
||||||
boost::function<void(int, disk_io_job const&)> const& handler);
|
boost::function<void(int, disk_io_job const&)> const& handler);
|
||||||
|
|
||||||
|
@ -707,6 +719,8 @@ namespace libtorrent
|
||||||
int delete_files_impl() { return m_storage->delete_files(); }
|
int delete_files_impl() { return m_storage->delete_files(); }
|
||||||
int rename_file_impl(int index, std::string const& new_filename)
|
int rename_file_impl(int index, std::string const& new_filename)
|
||||||
{ return m_storage->rename_file(index, new_filename); }
|
{ return m_storage->rename_file(index, new_filename); }
|
||||||
|
void set_file_priority_impl(std::vector<boost::uint8_t> const& p)
|
||||||
|
{ m_storage->set_file_priority(p); }
|
||||||
|
|
||||||
int move_storage_impl(std::string const& save_path, int flags);
|
int move_storage_impl(std::string const& save_path, int flags);
|
||||||
|
|
||||||
|
|
|
@ -2486,8 +2486,17 @@ namespace libtorrent
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
test_error(j);
|
test_error(j);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case disk_io_job::file_priority:
|
||||||
|
{
|
||||||
|
std::vector<boost::uint8_t>* p
|
||||||
|
= reinterpret_cast<std::vector<boost::uint8_t>*>(j.buffer);
|
||||||
|
j.storage->set_file_priority_impl(*p);
|
||||||
|
delete p;
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,6 +397,11 @@ namespace libtorrent
|
||||||
|
|
||||||
default_storage::~default_storage() { m_pool.release(this); }
|
default_storage::~default_storage() { m_pool.release(this); }
|
||||||
|
|
||||||
|
void default_storage::set_file_priority(std::vector<boost::uint8_t> const& prio)
|
||||||
|
{
|
||||||
|
m_file_priority = prio;
|
||||||
|
}
|
||||||
|
|
||||||
bool default_storage::initialize(bool allocate_files)
|
bool default_storage::initialize(bool allocate_files)
|
||||||
{
|
{
|
||||||
m_allocate_files = allocate_files;
|
m_allocate_files = allocate_files;
|
||||||
|
@ -457,7 +462,6 @@ namespace libtorrent
|
||||||
ec.clear();
|
ec.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<boost::uint8_t>().swap(m_file_priority);
|
|
||||||
// close files that were opened in write mode
|
// close files that were opened in write mode
|
||||||
m_pool.release(this);
|
m_pool.release(this);
|
||||||
|
|
||||||
|
@ -1525,6 +1529,19 @@ ret:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void piece_manager::async_set_file_priority(
|
||||||
|
std::vector<boost::uint8_t> const& prios
|
||||||
|
, boost::function<void(int, disk_io_job const&)> const& handler)
|
||||||
|
{
|
||||||
|
std::vector<boost::uint8_t>* p = new std::vector<boost::uint8_t>(prios);
|
||||||
|
|
||||||
|
disk_io_job j;
|
||||||
|
j.storage = this;
|
||||||
|
j.buffer = (char*)p;
|
||||||
|
j.action = disk_io_job::file_priority;
|
||||||
|
m_io_thread.add_job(j, handler);
|
||||||
|
}
|
||||||
|
|
||||||
void piece_manager::async_save_resume_data(
|
void piece_manager::async_save_resume_data(
|
||||||
boost::function<void(int, disk_io_job const&)> const& handler)
|
boost::function<void(int, disk_io_job const&)> const& handler)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3964,6 +3964,8 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void nop() {}
|
||||||
|
|
||||||
void torrent::prioritize_files(std::vector<int> const& files)
|
void torrent::prioritize_files(std::vector<int> const& files)
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
@ -3989,6 +3991,13 @@ namespace libtorrent
|
||||||
if (valid_metadata() && m_torrent_file->num_files() > int(m_file_priority.size()))
|
if (valid_metadata() && m_torrent_file->num_files() > int(m_file_priority.size()))
|
||||||
m_file_priority.resize(m_torrent_file->num_files(), 1);
|
m_file_priority.resize(m_torrent_file->num_files(), 1);
|
||||||
|
|
||||||
|
// stoage may be NULL during shutdown
|
||||||
|
if (m_torrent_file->num_pieces() > 0 && m_storage)
|
||||||
|
{
|
||||||
|
filesystem().async_set_file_priority(m_file_priority
|
||||||
|
, boost::bind(&nop));
|
||||||
|
}
|
||||||
|
|
||||||
update_piece_priorities();
|
update_piece_priorities();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4009,6 +4018,12 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
if (m_file_priority[index] == prio) return;
|
if (m_file_priority[index] == prio) return;
|
||||||
m_file_priority[index] = prio;
|
m_file_priority[index] = prio;
|
||||||
|
// stoage may be NULL during shutdown
|
||||||
|
if (m_storage)
|
||||||
|
{
|
||||||
|
filesystem().async_set_file_priority(m_file_priority
|
||||||
|
, boost::bind(&nop));
|
||||||
|
}
|
||||||
update_piece_priorities();
|
update_piece_priorities();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ struct test_storage : storage_interface
|
||||||
|
|
||||||
virtual bool initialize(bool allocate_files) { return true; }
|
virtual bool initialize(bool allocate_files) { return true; }
|
||||||
virtual bool has_any_file() { return true; }
|
virtual bool has_any_file() { return true; }
|
||||||
|
virtual void set_file_priority(std::vector<boost::uint8_t> const& p) {}
|
||||||
|
|
||||||
int write(
|
int write(
|
||||||
const char* buf
|
const char* buf
|
||||||
|
|
|
@ -77,6 +77,7 @@ struct test_storage : storage_interface
|
||||||
, m_written(0)
|
, m_written(0)
|
||||||
, m_limit(16 * 1024 * 2)
|
, m_limit(16 * 1024 * 2)
|
||||||
{}
|
{}
|
||||||
|
virtual void set_file_priority(std::vector<boost::uint8_t> const& p) {}
|
||||||
|
|
||||||
virtual bool initialize(bool allocate_files)
|
virtual bool initialize(bool allocate_files)
|
||||||
{ return m_lower_layer->initialize(allocate_files); }
|
{ return m_lower_layer->initialize(allocate_files); }
|
||||||
|
|
Loading…
Reference in New Issue