removed checker thread
This commit is contained in:
@@ -94,73 +94,6 @@ namespace libtorrent
|
||||
{
|
||||
struct session_impl;
|
||||
|
||||
// this data is shared between the main thread and the
|
||||
// thread that initialize pieces
|
||||
struct piece_checker_data
|
||||
{
|
||||
piece_checker_data()
|
||||
: processing(false), progress(0.f), abort(false) {}
|
||||
|
||||
boost::shared_ptr<torrent> torrent_ptr;
|
||||
fs::path save_path;
|
||||
|
||||
sha1_hash info_hash;
|
||||
|
||||
void parse_resume_data(
|
||||
const entry& rd
|
||||
, const torrent_info& info
|
||||
, std::string& error);
|
||||
|
||||
std::vector<int> piece_map;
|
||||
std::vector<piece_picker::downloading_piece> unfinished_pieces;
|
||||
std::vector<piece_picker::block_info> block_info;
|
||||
std::vector<tcp::endpoint> peers;
|
||||
std::vector<tcp::endpoint> banned_peers;
|
||||
entry resume_data;
|
||||
|
||||
// this is true if this torrent is being processed (checked)
|
||||
// if it is not being processed, then it can be removed from
|
||||
// the queue without problems, otherwise the abort flag has
|
||||
// to be set.
|
||||
bool processing;
|
||||
|
||||
// is filled in by storage::initialize_pieces()
|
||||
// and represents the progress. It should be a
|
||||
// value in the range [0, 1]
|
||||
float progress;
|
||||
|
||||
// abort defaults to false and is typically
|
||||
// filled in by torrent_handle when the user
|
||||
// aborts the torrent
|
||||
bool abort;
|
||||
};
|
||||
|
||||
struct checker_impl: boost::noncopyable
|
||||
{
|
||||
checker_impl(session_impl& s): m_ses(s), m_abort(false) {}
|
||||
void operator()();
|
||||
piece_checker_data* find_torrent(const sha1_hash& info_hash);
|
||||
void remove_torrent(sha1_hash const& info_hash, int options);
|
||||
|
||||
#ifndef NDEBUG
|
||||
void check_invariant() const;
|
||||
#endif
|
||||
|
||||
// when the files has been checked
|
||||
// the torrent is added to the session
|
||||
session_impl& m_ses;
|
||||
|
||||
mutable boost::mutex m_mutex;
|
||||
boost::condition m_cond;
|
||||
|
||||
// a list of all torrents that are currently in queue
|
||||
// or checking their files
|
||||
std::deque<boost::shared_ptr<piece_checker_data> > m_torrents;
|
||||
std::deque<boost::shared_ptr<piece_checker_data> > m_processing;
|
||||
|
||||
bool m_abort;
|
||||
};
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
struct tracker_logger;
|
||||
#endif
|
||||
@@ -284,6 +217,9 @@ namespace libtorrent
|
||||
|
||||
std::vector<torrent_handle> get_torrents();
|
||||
|
||||
void check_torrent(boost::shared_ptr<torrent> const& t);
|
||||
void done_checking(boost::shared_ptr<torrent> const& t);
|
||||
|
||||
void set_severity_level(alert::severity_t s);
|
||||
std::auto_ptr<alert> pop_alert();
|
||||
|
||||
@@ -435,6 +371,7 @@ namespace libtorrent
|
||||
|
||||
tracker_manager m_tracker_manager;
|
||||
torrent_map m_torrents;
|
||||
std::list<boost::shared_ptr<torrent> > m_queued_for_checking;
|
||||
|
||||
// this maps sockets to their peer_connection
|
||||
// object. It is the complete list of all connected
|
||||
@@ -625,16 +562,8 @@ namespace libtorrent
|
||||
extension_list_t m_extensions;
|
||||
#endif
|
||||
|
||||
// data shared between the main thread
|
||||
// and the checker thread
|
||||
checker_impl m_checker_impl;
|
||||
|
||||
// the main working thread
|
||||
boost::scoped_ptr<boost::thread> m_thread;
|
||||
|
||||
// the thread that calls initialize_pieces()
|
||||
// on all torrents before they start downloading
|
||||
boost::scoped_ptr<boost::thread> m_checker_thread;
|
||||
};
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
|
@@ -77,6 +77,8 @@ namespace libtorrent
|
||||
, move_storage
|
||||
, release_files
|
||||
, delete_files
|
||||
, check_fastresume
|
||||
, check_files
|
||||
};
|
||||
|
||||
action_t action;
|
||||
@@ -154,10 +156,6 @@ namespace libtorrent
|
||||
, boost::function<void(int, disk_io_job const&)> const& f
|
||||
= boost::function<void(int, disk_io_job const&)>());
|
||||
|
||||
#ifndef NDEBUG
|
||||
disk_io_job find_job(boost::intrusive_ptr<piece_manager> s
|
||||
, int action, int piece) const;
|
||||
#endif
|
||||
// keep track of the number of bytes in the job queue
|
||||
// at any given time. i.e. the sum of all buffer_size.
|
||||
// this is used to slow down the download global download
|
||||
@@ -268,9 +266,6 @@ namespace libtorrent
|
||||
// number of bytes per block. The BitTorrent
|
||||
// protocol defines the block size to 16 KiB.
|
||||
int m_block_size;
|
||||
#ifndef NDEBUG
|
||||
disk_io_job m_current;
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_DISK_STATS
|
||||
std::ofstream m_log;
|
||||
|
@@ -138,10 +138,7 @@ namespace libtorrent
|
||||
|
||||
// the vector tells which pieces we already have
|
||||
// and which we don't have.
|
||||
void files_checked(
|
||||
std::vector<bool> const& pieces
|
||||
, std::vector<downloading_piece> const& unfinished
|
||||
, std::vector<int>& verify_pieces);
|
||||
void init(std::vector<bool> const& pieces);
|
||||
|
||||
// increases the peer count for the given piece
|
||||
// (is used when a HAVE message is received)
|
||||
|
@@ -119,12 +119,12 @@ namespace libtorrent
|
||||
// if allocate_files is true.
|
||||
// allocate_files is true if allocation mode
|
||||
// is set to full and sparse files are supported
|
||||
// false return value indicates an error
|
||||
virtual bool initialize(bool allocate_files) = 0;
|
||||
|
||||
// negative return value indicates an error
|
||||
virtual size_type read(char* buf, int slot, int offset, int size) = 0;
|
||||
|
||||
// may throw file_error if storage for slot hasn't been allocated
|
||||
// negative return value indicates an error
|
||||
virtual size_type write(const char* buf, int slot, int offset, int size) = 0;
|
||||
|
||||
@@ -194,48 +194,23 @@ namespace libtorrent
|
||||
, fs::path const& path
|
||||
, file_pool& fp
|
||||
, disk_io_thread& io
|
||||
, storage_constructor_type sc);
|
||||
, storage_constructor_type sc
|
||||
, storage_mode_t sm);
|
||||
|
||||
~piece_manager();
|
||||
|
||||
torrent_info const* info() const { return m_info.get(); }
|
||||
|
||||
bool check_fastresume(aux::piece_checker_data& d
|
||||
, std::vector<bool>& pieces, int& num_pieces, storage_mode_t storage_mode
|
||||
, std::string& error_msg);
|
||||
std::pair<bool, float> check_files(std::vector<bool>& pieces
|
||||
, int& num_pieces, boost::recursive_mutex& mutex, bool& error);
|
||||
|
||||
// frees a buffer that was returned from a read operation
|
||||
void free_buffer(char* buf);
|
||||
|
||||
void write_resume_data(entry& rd) const
|
||||
{ m_storage->write_resume_data(rd); }
|
||||
void write_resume_data(entry& rd, std::vector<bool> const& have) const;
|
||||
|
||||
bool verify_resume_data(entry const& rd, std::string& error)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
m_resume_data_verified = true;
|
||||
#endif
|
||||
return m_storage->verify_resume_data(rd, error);
|
||||
}
|
||||
|
||||
bool is_allocating() const
|
||||
{ return m_state == state_expand_pieces; }
|
||||
|
||||
void mark_failed(int index);
|
||||
|
||||
std::string const& error() const { return m_storage->error(); }
|
||||
void clear_error() { m_storage->clear_error(); }
|
||||
|
||||
unsigned long piece_crc(
|
||||
int slot_index
|
||||
, int block_size
|
||||
, piece_picker::block_info const* bi);
|
||||
|
||||
int slot_for(int piece) const;
|
||||
int piece_for(int slot) const;
|
||||
void async_check_fastresume(entry const* resume_data
|
||||
, boost::function<void(int, disk_io_job const&)> const& handler);
|
||||
|
||||
void async_check_files(boost::function<void(int, disk_io_job const&)> const& handler);
|
||||
|
||||
void async_read(
|
||||
peer_request const& r
|
||||
, boost::function<void(int, disk_io_job const&)> const& handler
|
||||
@@ -249,8 +224,6 @@ namespace libtorrent
|
||||
|
||||
void async_hash(int piece, boost::function<void(int, disk_io_job const&)> const& f);
|
||||
|
||||
fs::path save_path() const;
|
||||
|
||||
void async_release_files(
|
||||
boost::function<void(int, disk_io_job const&)> const& handler
|
||||
= boost::function<void(int, disk_io_job const&)>());
|
||||
@@ -262,12 +235,44 @@ namespace libtorrent
|
||||
void async_move_storage(fs::path const& p
|
||||
, boost::function<void(int, disk_io_job const&)> const& handler);
|
||||
|
||||
// fills the vector that maps all allocated
|
||||
// slots to the piece that is stored (or
|
||||
// partially stored) there. -2 is the index
|
||||
// of unassigned pieces and -1 is unallocated
|
||||
void export_piece_map(std::vector<int>& pieces
|
||||
, std::vector<bool> const& have) const;
|
||||
enum return_t
|
||||
{
|
||||
// return values from check_fastresume and check_files
|
||||
no_error = 0,
|
||||
need_full_check = -1,
|
||||
fatal_disk_error = -2,
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
fs::path save_path() const;
|
||||
|
||||
bool verify_resume_data(entry const& rd, std::string& error)
|
||||
{ return m_storage->verify_resume_data(rd, error); }
|
||||
|
||||
bool is_allocating() const
|
||||
{ return m_state == state_expand_pieces; }
|
||||
|
||||
void mark_failed(int index);
|
||||
|
||||
std::string const& error() const { return m_storage->error(); }
|
||||
void clear_error() { m_storage->clear_error(); }
|
||||
|
||||
int slot_for(int piece) const;
|
||||
int piece_for(int slot) const;
|
||||
|
||||
// helper functions for check_dastresume
|
||||
int check_no_fastresume(std::string& error);
|
||||
int check_init_storage(std::string& error);
|
||||
|
||||
// if error is set and return value is 'no_error' or 'need_full_check'
|
||||
// the error message indicates that the fast resume data was rejected
|
||||
// if 'fatal_disk_error' is returned, the error message indicates what
|
||||
// when wrong in the disk access
|
||||
int check_fastresume(entry const& rd, std::string& error);
|
||||
|
||||
// this function returns true if the checking is complete
|
||||
int check_files(int& current_slot, int& have_piece, std::string& error);
|
||||
|
||||
bool compact_allocation() const
|
||||
{ return m_storage_mode == storage_mode_compact; }
|
||||
@@ -275,19 +280,9 @@ namespace libtorrent
|
||||
#ifndef NDEBUG
|
||||
std::string name() const { return m_info->name(); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
bool allocate_slots(int num_slots, bool abort_on_disk = false);
|
||||
|
||||
int identify_data(
|
||||
const std::vector<char>& piece_data
|
||||
, int current_slot
|
||||
, std::vector<bool>& have_pieces
|
||||
, int& num_pieces
|
||||
, const std::multimap<sha1_hash, int>& hash_to_piece
|
||||
, boost::recursive_mutex& mutex);
|
||||
|
||||
size_type read_impl(
|
||||
char* buf
|
||||
, int piece_index
|
||||
@@ -300,8 +295,10 @@ namespace libtorrent
|
||||
, int offset
|
||||
, int size);
|
||||
|
||||
bool check_one_piece(std::vector<bool>& pieces, int& num_pieces
|
||||
, boost::recursive_mutex& mutex);
|
||||
bool check_one_piece(int& have_piece);
|
||||
int identify_data(
|
||||
const std::vector<char>& piece_data
|
||||
, int current_slot);
|
||||
|
||||
void switch_to_full_mode();
|
||||
sha1_hash hash_for_piece_impl(int piece);
|
||||
@@ -357,8 +354,6 @@ namespace libtorrent
|
||||
state_none,
|
||||
// the file checking is complete
|
||||
state_finished,
|
||||
// creating the directories
|
||||
state_create_files,
|
||||
// checking the files
|
||||
state_full_check,
|
||||
// move pieces to their final position
|
||||
@@ -403,9 +398,6 @@ namespace libtorrent
|
||||
// the piece_manager destructs. This is because
|
||||
// the torrent_info object is owned by the torrent.
|
||||
boost::shared_ptr<void> m_torrent;
|
||||
#ifndef NDEBUG
|
||||
bool m_resume_data_verified;
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -98,20 +98,19 @@ namespace libtorrent
|
||||
|
||||
torrent(
|
||||
aux::session_impl& ses
|
||||
, aux::checker_impl& checker
|
||||
, boost::intrusive_ptr<torrent_info> tf
|
||||
, fs::path const& save_path
|
||||
, tcp::endpoint const& net_interface
|
||||
, storage_mode_t m_storage_mode
|
||||
, int block_size
|
||||
, storage_constructor_type sc
|
||||
, bool paused);
|
||||
, bool paused
|
||||
, entry const& resume_data);
|
||||
|
||||
// used with metadata-less torrents
|
||||
// (the metadata is downloaded from the peers)
|
||||
torrent(
|
||||
aux::session_impl& ses
|
||||
, aux::checker_impl& checker
|
||||
, char const* tracker_url
|
||||
, sha1_hash const& info_hash
|
||||
, char const* name
|
||||
@@ -120,7 +119,8 @@ namespace libtorrent
|
||||
, storage_mode_t m_storage_mode
|
||||
, int block_size
|
||||
, storage_constructor_type sc
|
||||
, bool paused);
|
||||
, bool paused
|
||||
, entry const& resume_data);
|
||||
|
||||
~torrent();
|
||||
|
||||
@@ -142,6 +142,12 @@ namespace libtorrent
|
||||
// it will initialize the storage and the piece-picker
|
||||
void init();
|
||||
|
||||
void on_resume_data_checked(int ret, disk_io_job const& j);
|
||||
void on_piece_checked(int ret, disk_io_job const& j);
|
||||
void files_checked();
|
||||
void start_checking();
|
||||
|
||||
storage_mode_t storage_mode() const { return m_storage_mode; }
|
||||
// this will flag the torrent as aborted. The main
|
||||
// loop in session_impl will check for this state
|
||||
// on all torrents once every second, and take
|
||||
@@ -149,19 +155,12 @@ namespace libtorrent
|
||||
void abort();
|
||||
bool is_aborted() const { return m_abort; }
|
||||
|
||||
// returns true if this torrent is being allocated
|
||||
// by the checker thread.
|
||||
bool is_allocating() const;
|
||||
|
||||
session_settings const& settings() const;
|
||||
|
||||
aux::session_impl& session() { return m_ses; }
|
||||
|
||||
void set_sequential_download(bool sd);
|
||||
|
||||
bool verify_resume_data(entry const& rd, std::string& error)
|
||||
{ TORRENT_ASSERT(m_storage); return m_storage->verify_resume_data(rd, error); }
|
||||
|
||||
void second_tick(stat& accumulator, float tick_interval);
|
||||
|
||||
// debug purpose only
|
||||
@@ -169,11 +168,6 @@ namespace libtorrent
|
||||
|
||||
std::string name() const;
|
||||
|
||||
bool check_fastresume(aux::piece_checker_data&);
|
||||
std::pair<bool, float> check_files(bool& error);
|
||||
void files_checked(std::vector<piece_picker::downloading_piece> const&
|
||||
unfinished_pieces);
|
||||
|
||||
stat statistics() const { return m_stat; }
|
||||
size_type bytes_left() const;
|
||||
boost::tuples::tuple<size_type, size_type> bytes_done() const;
|
||||
@@ -705,7 +699,6 @@ namespace libtorrent
|
||||
// a back reference to the session
|
||||
// this torrent belongs to.
|
||||
aux::session_impl& m_ses;
|
||||
aux::checker_impl& m_checker;
|
||||
|
||||
boost::scoped_ptr<piece_picker> m_picker;
|
||||
|
||||
@@ -768,6 +761,12 @@ namespace libtorrent
|
||||
// determines the storage state for this torrent.
|
||||
storage_mode_t m_storage_mode;
|
||||
|
||||
// the state of this torrent (queued, checking, downloading)
|
||||
torrent_status::state_t m_state;
|
||||
float m_progress;
|
||||
|
||||
entry m_resume_data;
|
||||
|
||||
// defaults to 16 kiB, but can be set by the user
|
||||
// when creating the torrent
|
||||
const int m_default_block_size;
|
||||
|
@@ -278,7 +278,7 @@ namespace libtorrent
|
||||
friend struct aux::session_impl;
|
||||
friend class torrent;
|
||||
|
||||
torrent_handle(): m_ses(0), m_chk(0), m_info_hash(0) {}
|
||||
torrent_handle(): m_ses(0), m_info_hash(0) {}
|
||||
|
||||
void get_peer_info(std::vector<peer_info>& v) const;
|
||||
bool send_chat_message(tcp::endpoint ip, std::string message) const;
|
||||
@@ -418,15 +418,12 @@ namespace libtorrent
|
||||
|
||||
private:
|
||||
|
||||
torrent_handle(aux::session_impl* s,
|
||||
aux::checker_impl* c,
|
||||
const sha1_hash& h)
|
||||
torrent_handle(aux::session_impl* s
|
||||
, const sha1_hash& h)
|
||||
: m_ses(s)
|
||||
, m_chk(c)
|
||||
, m_info_hash(h)
|
||||
{
|
||||
TORRENT_ASSERT(m_ses != 0);
|
||||
TORRENT_ASSERT(m_chk != 0);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
@@ -434,7 +431,6 @@ namespace libtorrent
|
||||
#endif
|
||||
|
||||
aux::session_impl* m_ses;
|
||||
aux::checker_impl* m_chk;
|
||||
sha1_hash m_info_hash;
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user