added async_add_torrent for increased performance when adding many torrents (no documentation yet though)
This commit is contained in:
@@ -587,5 +587,19 @@ namespace libtorrent {
|
||||
return msg;
|
||||
}
|
||||
|
||||
std::string add_torrent_alert::message() const
|
||||
{
|
||||
char msg[600];
|
||||
if (error)
|
||||
{
|
||||
snprintf(msg, sizeof(msg), "failed to add torrent: %s", error.message().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(msg, sizeof(msg), "added torrent: %s", !params.url.empty() ? params.url.c_str() : params.ti->name().c_str());
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
} // namespace libtorrent
|
||||
|
||||
|
@@ -275,6 +275,11 @@ namespace libtorrent
|
||||
return combine_path(m_paths[fe.path_index], fe.filename());
|
||||
}
|
||||
|
||||
size_type file_storage::file_size(internal_file_entry const& fe) const
|
||||
{
|
||||
return fe.size;
|
||||
}
|
||||
|
||||
peer_request file_storage::map_file(int file_index, size_type file_offset
|
||||
, int size) const
|
||||
{
|
||||
|
@@ -610,6 +610,15 @@ namespace libtorrent
|
||||
return r;
|
||||
}
|
||||
|
||||
void session::async_add_torrent(add_torrent_params const& params)
|
||||
{
|
||||
add_torrent_params* p = new add_torrent_params(params);
|
||||
if (params.resume_data) p->resume_data = new std::vector<char>(*params.resume_data);
|
||||
if (params.tracker_url) p->tracker_url = strdup(params.tracker_url);
|
||||
if (params.name) p->name = strdup(params.name);
|
||||
TORRENT_ASYNC_CALL1(async_add_torrent, p);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
// if the torrent already exists, this will throw duplicate_torrent
|
||||
|
@@ -4251,6 +4251,17 @@ namespace aux {
|
||||
return torrent_handle(find_torrent(info_hash));
|
||||
}
|
||||
|
||||
void session_impl::async_add_torrent(add_torrent_params* params)
|
||||
{
|
||||
error_code ec;
|
||||
torrent_handle handle = add_torrent(*params, ec);
|
||||
m_alerts.post_alert(add_torrent_alert(handle, *params, ec));
|
||||
delete params->resume_data;
|
||||
free((char*)params->tracker_url);
|
||||
free((char*)params->name);
|
||||
delete params;
|
||||
}
|
||||
|
||||
torrent_handle session_impl::add_torrent(add_torrent_params const& params
|
||||
, error_code& ec)
|
||||
{
|
||||
|
@@ -3936,13 +3936,15 @@ ctx->set_verify_callback(verify_function, ec);
|
||||
// initialize the piece priorities to 0, then only allow
|
||||
// setting higher priorities
|
||||
std::vector<int> pieces(m_torrent_file->num_pieces(), 0);
|
||||
for (int i = 0; i < int(m_file_priority.size()); ++i)
|
||||
int index = 0;
|
||||
for (file_storage::iterator i = m_torrent_file->files().begin()
|
||||
, end(m_torrent_file->files().end()); i != end; ++i, ++index)
|
||||
{
|
||||
size_type start = position;
|
||||
size_type size = m_torrent_file->files().at(i).size;
|
||||
size_type size = m_torrent_file->files().file_size(*i);
|
||||
if (size == 0) continue;
|
||||
position += size;
|
||||
if (m_file_priority[i] == 0) continue;
|
||||
if (m_file_priority[index] == 0) continue;
|
||||
|
||||
// mark all pieces of the file with this file's priority
|
||||
// but only if the priority is higher than the pieces
|
||||
@@ -3954,7 +3956,7 @@ ctx->set_verify_callback(verify_function, ec);
|
||||
// come here several times with the same start_piece, end_piece
|
||||
std::for_each(pieces.begin() + start_piece
|
||||
, pieces.begin() + last_piece + 1
|
||||
, boost::bind(&set_if_greater, _1, m_file_priority[i]));
|
||||
, boost::bind(&set_if_greater, _1, m_file_priority[index]));
|
||||
}
|
||||
prioritize_pieces(pieces);
|
||||
}
|
||||
|
Reference in New Issue
Block a user