simplify session call and replace session_handle and torrent_handle macros (#741)

remove use of macros in session_handle and torrent_handle forwarders
This commit is contained in:
Arvid Norberg 2016-05-21 19:05:42 -04:00
parent b4e11a06c0
commit dceee3b065
12 changed files with 363 additions and 467 deletions

View File

@ -37,70 +37,15 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/aux_/session_impl.hpp"
#include <boost/function.hpp> #include <boost/function.hpp>
#include <functional>
namespace libtorrent { namespace aux { namespace libtorrent { namespace aux {
void blocking_call(); void blocking_call();
void dump_call_profile(); void dump_call_profile();
void fun_wrap(bool& done, std::condition_variable& e, std::mutex& m, boost::function<void(void)> f);
template <class R>
void fun_ret(R& ret, bool& done, std::condition_variable& e, std::mutex& m, boost::function<R(void)> f)
{
ret = f();
std::unique_lock<std::mutex> l(m);
done = true;
e.notify_all();
}
void torrent_wait(bool& done, aux::session_impl& ses); void torrent_wait(bool& done, aux::session_impl& ses);
void sync_call(aux::session_impl& ses, boost::function<void(void)> f);
template <typename Handle>
void sync_call_handle(Handle& h, boost::function<void(void)> f)
{
bool done = false;
session_impl& ses = static_cast<session_impl&>(h->session());
ses.get_io_service().dispatch(boost::bind(&aux::fun_wrap
, boost::ref(done)
, boost::ref(ses.cond)
, boost::ref(ses.mut), f));
h.reset();
aux::torrent_wait(done, ses);
}
template <typename Ret>
Ret sync_call_ret(aux::session_impl& ses, boost::function<Ret(void)> f)
{
bool done = false;
Ret r;
ses.get_io_service().dispatch(boost::bind(&fun_ret<Ret>
, boost::ref(r)
, boost::ref(done)
, boost::ref(ses.cond)
, boost::ref(ses.mut)
, f));
torrent_wait(done, ses);
return r;
}
template <typename Handle, typename Ret>
void sync_call_ret_handle(Handle& h, Ret& r, boost::function<Ret(void)> f)
{
bool done = false;
session_impl& ses = static_cast<session_impl&>(h->session());
ses.get_io_service().dispatch(boost::bind(&aux::fun_ret<Ret>
, boost::ref(r)
, boost::ref(done)
, boost::ref(ses.cond)
, boost::ref(ses.mut)
, f));
h.reset();
aux::torrent_wait(done, ses);
}
} } // namespace aux namespace libtorrent } } // namespace aux namespace libtorrent
#endif // TORRENT_SESSION_CALL_HPP_INCLUDED #endif // TORRENT_SESSION_CALL_HPP_INCLUDED

View File

@ -339,7 +339,8 @@ namespace libtorrent
void dht_get_peers(sha1_hash const& info_hash); void dht_get_peers(sha1_hash const& info_hash);
void dht_announce(sha1_hash const& info_hash, int port = 0, int flags = 0); void dht_announce(sha1_hash const& info_hash, int port = 0, int flags = 0);
void dht_direct_request(udp::endpoint ep, entry& e, void* userdata = 0); void dht_direct_request(udp::endpoint ep, entry& e
, void* userdata = 0);
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
entry dht_state() const; entry dht_state() const;
@ -443,15 +444,15 @@ namespace libtorrent
void pop_alerts(); void pop_alerts();
alert const* pop_alert(); alert const* pop_alert();
size_t set_alert_queue_size_limit(size_t queue_size_limit_); size_t set_alert_queue_size_limit(size_t queue_size_limit_);
int upload_rate_limit() const; int upload_rate_limit_depr() const;
int download_rate_limit() const; int download_rate_limit_depr() const;
int local_upload_rate_limit() const; int local_upload_rate_limit() const;
int local_download_rate_limit() const; int local_download_rate_limit() const;
void set_local_download_rate_limit(int bytes_per_second); void set_local_download_rate_limit(int bytes_per_second);
void set_local_upload_rate_limit(int bytes_per_second); void set_local_upload_rate_limit(int bytes_per_second);
void set_download_rate_limit(int bytes_per_second); void set_download_rate_limit_depr(int bytes_per_second);
void set_upload_rate_limit(int bytes_per_second); void set_upload_rate_limit_depr(int bytes_per_second);
void set_max_connections(int limit); void set_max_connections(int limit);
void set_max_uploads(int limit); void set_max_uploads(int limit);

View File

@ -1021,6 +1021,16 @@ namespace libtorrent
{ return m_impl; } { return m_impl; }
private: private:
template <typename Fun, typename... Args>
void async_call(Fun f, Args&&... a) const;
template <typename Fun, typename... Args>
void sync_call(Fun f, Args&&... a) const;
template <typename Ret, typename Fun, typename... Args>
Ret sync_call_ret(Fun f, Args&&... a) const;
aux::session_impl* m_impl; aux::session_impl* m_impl;
}; };

View File

@ -296,7 +296,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::shared_ptr<torrent_plugin>); void add_extension(boost::shared_ptr<torrent_plugin>);
void remove_extension(boost::shared_ptr<torrent_plugin>); void remove_extension(boost::shared_ptr<torrent_plugin>);
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext void add_extension_fun(boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
, void* userdata); , void* userdata);
void notify_extension_add_peer(tcp::endpoint const& ip, int src, int flags); void notify_extension_add_peer(tcp::endpoint const& ip, int src, int flags);
#endif #endif
@ -508,7 +508,7 @@ namespace libtorrent
void filtered_pieces(std::vector<bool>& bitmask) const; void filtered_pieces(std::vector<bool>& bitmask) const;
void filter_files(std::vector<bool> const& files); void filter_files(std::vector<bool> const& files);
#if !TORRENT_NO_FPU #if !TORRENT_NO_FPU
void file_progress(std::vector<float>& fp); void file_progress_float(std::vector<float>& fp);
#endif #endif
// ============ end deprecation ============= // ============ end deprecation =============
@ -579,16 +579,17 @@ namespace libtorrent
// add or remove a url that will be attempted for // add or remove a url that will be attempted for
// finding the file(s) in this torrent. // finding the file(s) in this torrent.
void add_web_seed(std::string const& url, web_seed_t::type_t type); void add_web_seed(std::string const& url
void add_web_seed(std::string const& url, web_seed_t::type_t type , web_seed_t::type_t type
, std::string const& auth, web_seed_t::headers_t const& extra_headers); , std::string const& auth = std::string()
, web_seed_t::headers_t const& extra_headers = web_seed_entry::headers_t());
void remove_web_seed(std::string const& url, web_seed_t::type_t type); void remove_web_seed(std::string const& url, web_seed_t::type_t type);
void disconnect_web_seed(peer_connection* p); void disconnect_web_seed(peer_connection* p);
void retry_web_seed(peer_connection* p, int retry = 0); void retry_web_seed(peer_connection* p, int retry = 0);
void remove_web_seed(peer_connection* p, error_code const& ec void remove_web_seed_conn(peer_connection* p, error_code const& ec
, operation_t op, int error = 0); , operation_t op, int error = 0);
std::set<std::string> web_seeds(web_seed_entry::type_t type) const; std::set<std::string> web_seeds(web_seed_entry::type_t type) const;
@ -747,7 +748,7 @@ namespace libtorrent
return m_super_seeding && is_seed(); return m_super_seeding && is_seed();
} }
void super_seeding(bool on); void set_super_seeding(bool on);
int get_piece_to_super_seed(bitfield const&); int get_piece_to_super_seed(bitfield const&);
// returns true if we have downloaded the given piece // returns true if we have downloaded the given piece
@ -864,7 +865,7 @@ namespace libtorrent
// remove a web seed, or schedule it for removal in case there // remove a web seed, or schedule it for removal in case there
// are outstanding operations on it // are outstanding operations on it
void remove_web_seed(std::list<web_seed_t>::iterator web); void remove_web_seed_iter(std::list<web_seed_t>::iterator web);
// this is called when the torrent has finished. i.e. // this is called when the torrent has finished. i.e.
// all the pieces we have not filtered have been downloaded. // all the pieces we have not filtered have been downloaded.

View File

@ -241,6 +241,8 @@ namespace libtorrent
// with just set_flags() and clear_flags() using the flags from // with just set_flags() and clear_flags() using the flags from
// add_torrent_params. Perhaps those flags should have a more generic // add_torrent_params. Perhaps those flags should have a more generic
// name. // name.
// TODO: 4 remove some of these friends
friend class invariant_access; friend class invariant_access;
friend struct aux::session_impl; friend struct aux::session_impl;
friend class session; friend class session;
@ -1281,6 +1283,15 @@ namespace libtorrent
private: private:
template<typename Fun, typename... Args>
void async_call(Fun f, Args&&... a) const;
template<typename Fun, typename... Args>
void sync_call(Fun f, Args&&... a) const;
template<typename Ret, typename Fun, typename... Args>
Ret sync_call_ret(Ret def, Fun f, Args&&... a) const;
torrent_handle(boost::weak_ptr<torrent> const& t) torrent_handle(boost::weak_ptr<torrent> const& t)
{ if (!t.expired()) m_torrent = t; } { if (!t.expired()) m_torrent = t; }

View File

@ -107,7 +107,7 @@ namespace libtorrent
peer_connection::disconnect(ec, op, error); peer_connection::disconnect(ec, op, error);
if (t) t->disconnect_web_seed(this); if (t) t->disconnect_web_seed(this);
} }
boost::optional<piece_block_progress> boost::optional<piece_block_progress>
http_seed_connection::downloading_piece_progress() const http_seed_connection::downloading_piece_progress() const
{ {
@ -269,9 +269,9 @@ namespace libtorrent
} }
TORRENT_ASSERT(recv_buffer.left() == 0 || *recv_buffer.begin == 'H'); TORRENT_ASSERT(recv_buffer.left() == 0 || *recv_buffer.begin == 'H');
TORRENT_ASSERT(recv_buffer.left() <= m_recv_buffer.packet_size()); TORRENT_ASSERT(recv_buffer.left() <= m_recv_buffer.packet_size());
// this means the entire status line hasn't been received yet // this means the entire status line hasn't been received yet
if (m_parser.status_code() == -1) if (m_parser.status_code() == -1)
{ {
@ -320,13 +320,13 @@ namespace libtorrent
if (location.empty()) if (location.empty())
{ {
// we should not try this server again. // we should not try this server again.
t->remove_web_seed(this, errors::missing_location, op_bittorrent, 2); t->remove_web_seed_conn(this, errors::missing_location, op_bittorrent, 2);
return; return;
} }
// add the redirected url and remove the current one // add the redirected url and remove the current one
t->add_web_seed(location, web_seed_entry::http_seed); t->add_web_seed(location, web_seed_entry::http_seed);
t->remove_web_seed(this, errors::redirecting, op_bittorrent, 2); t->remove_web_seed_conn(this, errors::redirecting, op_bittorrent, 2);
return; return;
} }
@ -345,14 +345,14 @@ namespace libtorrent
{ {
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
// we should not try this server again. // we should not try this server again.
t->remove_web_seed(this, errors::no_content_length, op_bittorrent, 2); t->remove_web_seed_conn(this, errors::no_content_length, op_bittorrent, 2);
return; return;
} }
if (m_response_left != front_request.length) if (m_response_left != front_request.length)
{ {
received_bytes(0, int(bytes_transferred)); received_bytes(0, int(bytes_transferred));
// we should not try this server again. // we should not try this server again.
t->remove_web_seed(this, errors::invalid_range, op_bittorrent, 2); t->remove_web_seed_conn(this, errors::invalid_range, op_bittorrent, 2);
return; return;
} }
m_body_start = m_parser.body_start(); m_body_start = m_parser.body_start();

View File

@ -71,14 +71,6 @@ void dump_call_profile()
#endif #endif
} }
void fun_wrap(bool& done, std::condition_variable& e, std::mutex& m, boost::function<void(void)> f)
{
f();
std::unique_lock<std::mutex> l(m);
done = true;
e.notify_all();
}
void torrent_wait(bool& done, aux::session_impl& ses) void torrent_wait(bool& done, aux::session_impl& ses)
{ {
blocking_call(); blocking_call();
@ -86,15 +78,4 @@ void torrent_wait(bool& done, aux::session_impl& ses)
while (!done) { ses.cond.wait(l); }; while (!done) { ses.cond.wait(l); };
} }
void sync_call(aux::session_impl& ses, boost::function<void(void)> f)
{
bool done = false;
ses.get_io_service().dispatch(boost::bind(&fun_wrap
, boost::ref(done)
, boost::ref(ses.cond)
, boost::ref(ses.mut)
, f));
torrent_wait(done, ses);
}
} } // namespace aux namespace libtorrent } } // namespace aux namespace libtorrent

View File

@ -36,74 +36,67 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/torrent.hpp" #include "libtorrent/torrent.hpp"
#include "libtorrent/lazy_entry.hpp" #include "libtorrent/lazy_entry.hpp"
#include <functional>
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
#include "libtorrent/read_resume_data.hpp" #include "libtorrent/read_resume_data.hpp"
#endif #endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-macros"
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-macros"
#endif
#define TORRENT_ASYNC_CALL(x) \
m_impl->get_io_service().dispatch(boost::bind(&session_impl:: x, m_impl))
#define TORRENT_ASYNC_CALL1(x, a1) \
m_impl->get_io_service().dispatch(boost::bind(&session_impl:: x, m_impl, a1))
#define TORRENT_ASYNC_CALL2(x, a1, a2) \
m_impl->get_io_service().dispatch(boost::bind(&session_impl:: x, m_impl, a1, a2))
#define TORRENT_ASYNC_CALL3(x, a1, a2, a3) \
m_impl->get_io_service().dispatch(boost::bind(&session_impl:: x, m_impl, a1, a2, a3))
#define TORRENT_SYNC_CALL(x) \
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl)))
#define TORRENT_SYNC_CALL1(x, a1) \
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl, a1)))
#define TORRENT_SYNC_CALL2(x, a1, a2) \
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl, a1, a2)))
#define TORRENT_SYNC_CALL3(x, a1, a2, a3) \
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl, a1, a2, a3)))
#define TORRENT_SYNC_CALL4(x, a1, a2, a3, a4) \
aux::sync_call(*m_impl, boost::function<void(void)>(boost::bind(&session_impl:: x, m_impl, a1, a2, a3, a4)))
#define TORRENT_SYNC_CALL_RET(type, x) \
aux::sync_call_ret<type>(*m_impl, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl)))
#define TORRENT_SYNC_CALL_RET1(type, x, a1) \
aux::sync_call_ret<type>(*m_impl, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl, a1)))
#define TORRENT_SYNC_CALL_RET2(type, x, a1, a2) \
aux::sync_call_ret<type>(*m_impl, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl, a1, a2)))
#define TORRENT_SYNC_CALL_RET3(type, x, a1, a2, a3) \
aux::sync_call_ret<type>(*m_impl, boost::function<type(void)>(boost::bind(&session_impl:: x, m_impl, a1, a2, a3)))
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
using libtorrent::aux::session_impl; using libtorrent::aux::session_impl;
namespace libtorrent namespace libtorrent
{ {
template <typename Fun, typename... Args>
void session_handle::async_call(Fun f, Args&&... a) const
{
m_impl->get_io_service().dispatch([=]() mutable
{ (m_impl->*f)(a...); });
}
template<typename Fun, typename... Args>
void session_handle::sync_call(Fun f, Args&&... a) const
{
// this is the flag to indicate the call has completed
// capture them by pointer to allow everything to be captured by value
// and simplify the capture expression
bool done = false;
m_impl->get_io_service().dispatch([=,&done]() mutable
{
(m_impl->*f)(a...);
std::unique_lock<std::mutex> l(m_impl->mut);
done = true;
m_impl->cond.notify_all();
});
aux::torrent_wait(done, *m_impl);
}
template<typename Ret, typename Fun, typename... Args>
Ret session_handle::sync_call_ret(Fun f, Args&&... a) const
{
// this is the flag to indicate the call has completed
// capture them by pointer to allow everything to be captured by value
// and simplify the capture expression
bool done = false;
Ret r;
m_impl->get_io_service().dispatch([=,&r,&done]() mutable
{
r = (m_impl->*f)(a...);
std::unique_lock<std::mutex> l(m_impl->mut);
done = true;
m_impl->cond.notify_all();
});
aux::torrent_wait(done, *m_impl);
return r;
}
void session_handle::save_state(entry& e, boost::uint32_t flags) const void session_handle::save_state(entry& e, boost::uint32_t flags) const
{ {
TORRENT_SYNC_CALL2(save_state, &e, flags); entry* ep = &e;
sync_call(&session_impl::save_state, ep, flags);
} }
void session_handle::load_state(bdecode_node const& e void session_handle::load_state(bdecode_node const& e
@ -111,35 +104,36 @@ namespace libtorrent
{ {
// this needs to be synchronized since the lifespan // this needs to be synchronized since the lifespan
// of e is tied to the caller // of e is tied to the caller
TORRENT_SYNC_CALL2(load_state, &e, flags); sync_call(&session_impl::load_state, &e, flags);
} }
void session_handle::get_torrent_status(std::vector<torrent_status>* ret void session_handle::get_torrent_status(std::vector<torrent_status>* ret
, boost::function<bool(torrent_status const&)> const& pred , boost::function<bool(torrent_status const&)> const& pred
, boost::uint32_t flags) const , boost::uint32_t flags) const
{ {
TORRENT_SYNC_CALL3(get_torrent_status, ret, boost::ref(pred), flags); auto predr = std::ref(pred);
sync_call(&session_impl::get_torrent_status, ret, predr, flags);
} }
void session_handle::refresh_torrent_status(std::vector<torrent_status>* ret void session_handle::refresh_torrent_status(std::vector<torrent_status>* ret
, boost::uint32_t flags) const , boost::uint32_t flags) const
{ {
TORRENT_SYNC_CALL2(refresh_torrent_status, ret, flags); sync_call(&session_impl::refresh_torrent_status, ret, flags);
} }
void session_handle::post_torrent_updates(boost::uint32_t flags) void session_handle::post_torrent_updates(boost::uint32_t flags)
{ {
TORRENT_ASYNC_CALL1(post_torrent_updates, flags); async_call(&session_impl::post_torrent_updates, flags);
} }
void session_handle::post_session_stats() void session_handle::post_session_stats()
{ {
TORRENT_ASYNC_CALL(post_session_stats); async_call(&session_impl::post_session_stats);
} }
void session_handle::post_dht_stats() void session_handle::post_dht_stats()
{ {
TORRENT_ASYNC_CALL(post_dht_stats); async_call(&session_impl::post_dht_stats);
} }
io_service& session_handle::get_io_service() io_service& session_handle::get_io_service()
@ -149,12 +143,12 @@ namespace libtorrent
torrent_handle session_handle::find_torrent(sha1_hash const& info_hash) const torrent_handle session_handle::find_torrent(sha1_hash const& info_hash) const
{ {
return TORRENT_SYNC_CALL_RET1(torrent_handle, find_torrent_handle, info_hash); return sync_call_ret<torrent_handle>(&session_impl::find_torrent_handle, info_hash);
} }
std::vector<torrent_handle> session_handle::get_torrents() const std::vector<torrent_handle> session_handle::get_torrents() const
{ {
return TORRENT_SYNC_CALL_RET(std::vector<torrent_handle>, get_torrents); return sync_call_ret<std::vector<torrent_handle>>(&session_impl::get_torrents);
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -289,7 +283,8 @@ namespace libtorrent
add_torrent_params const& p = params; add_torrent_params const& p = params;
#endif #endif
error_code ec; error_code ec;
torrent_handle r = TORRENT_SYNC_CALL_RET2(torrent_handle, add_torrent, p, boost::ref(ec)); auto ecr = std::ref(ec);
torrent_handle r = sync_call_ret<torrent_handle>(&session_impl::add_torrent, p, ecr);
if (ec) throw system_error(ec); if (ec) throw system_error(ec);
return r; return r;
} }
@ -306,7 +301,8 @@ namespace libtorrent
#else #else
add_torrent_params const& p = params; add_torrent_params const& p = params;
#endif #endif
return TORRENT_SYNC_CALL_RET2(torrent_handle, add_torrent, p, boost::ref(ec)); auto ecr = std::ref(ec);
return sync_call_ret<torrent_handle>(&session_impl::add_torrent, p, ecr);
} }
void session_handle::async_add_torrent(add_torrent_params const& params) void session_handle::async_add_torrent(add_torrent_params const& params)
@ -319,7 +315,7 @@ namespace libtorrent
handle_backwards_compatible_resume_data(*p); handle_backwards_compatible_resume_data(*p);
#endif #endif
TORRENT_ASYNC_CALL1(async_add_torrent, p); async_call(&session_impl::async_add_torrent, p);
} }
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
@ -382,28 +378,28 @@ namespace libtorrent
void session_handle::pause() void session_handle::pause()
{ {
TORRENT_ASYNC_CALL(pause); async_call(&session_impl::pause);
} }
void session_handle::resume() void session_handle::resume()
{ {
TORRENT_ASYNC_CALL(resume); async_call(&session_impl::resume);
} }
bool session_handle::is_paused() const bool session_handle::is_paused() const
{ {
return TORRENT_SYNC_CALL_RET(bool, is_paused); return sync_call_ret<bool>(&session_impl::is_paused);
} }
void session_handle::set_load_function(user_load_function_t fun) void session_handle::set_load_function(user_load_function_t fun)
{ {
TORRENT_ASYNC_CALL1(set_load_function, fun); async_call(&session_impl::set_load_function, fun);
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
session_status session_handle::status() const session_status session_handle::status() const
{ {
return TORRENT_SYNC_CALL_RET(session_status, status); return sync_call_ret<session_status>(&session_impl::status);
} }
void session_handle::get_cache_info(sha1_hash const& ih void session_handle::get_cache_info(sha1_hash const& ih
@ -456,7 +452,7 @@ namespace libtorrent
void session_handle::set_dht_settings(dht_settings const& settings) void session_handle::set_dht_settings(dht_settings const& settings)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL1(set_dht_settings, settings); async_call(&session_impl::set_dht_settings, settings);
#else #else
TORRENT_UNUSED(settings); TORRENT_UNUSED(settings);
#endif #endif
@ -465,7 +461,7 @@ namespace libtorrent
dht_settings session_handle::get_dht_settings() const dht_settings session_handle::get_dht_settings() const
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
return TORRENT_SYNC_CALL_RET(dht_settings, get_dht_settings); return sync_call_ret<dht_settings>(&session_impl::get_dht_settings);
#else #else
return dht_settings(); return dht_settings();
#endif #endif
@ -474,7 +470,7 @@ namespace libtorrent
bool session_handle::is_dht_running() const bool session_handle::is_dht_running() const
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
return TORRENT_SYNC_CALL_RET(bool, is_dht_running); return sync_call_ret<bool>(&session_impl::is_dht_running);
#else #else
return false; return false;
#endif #endif
@ -483,7 +479,7 @@ namespace libtorrent
void session_handle::set_dht_storage(dht::dht_storage_constructor_type sc) void session_handle::set_dht_storage(dht::dht_storage_constructor_type sc)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL1(set_dht_storage, sc); async_call(&session_impl::set_dht_storage, sc);
#else #else
TORRENT_UNUSED(sc); TORRENT_UNUSED(sc);
#endif #endif
@ -492,7 +488,7 @@ namespace libtorrent
void session_handle::add_dht_node(std::pair<std::string, int> const& node) void session_handle::add_dht_node(std::pair<std::string, int> const& node)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL1(add_dht_node_name, node); async_call(&session_impl::add_dht_node_name, node);
#else #else
TORRENT_UNUSED(node); TORRENT_UNUSED(node);
#endif #endif
@ -501,7 +497,7 @@ namespace libtorrent
void session_handle::add_dht_router(std::pair<std::string, int> const& node) void session_handle::add_dht_router(std::pair<std::string, int> const& node)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL1(add_dht_router, node); async_call(&session_impl::add_dht_router, node);
#else #else
TORRENT_UNUSED(node); TORRENT_UNUSED(node);
#endif #endif
@ -510,7 +506,7 @@ namespace libtorrent
void session_handle::dht_get_item(sha1_hash const& target) void session_handle::dht_get_item(sha1_hash const& target)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL1(dht_get_immutable_item, target); async_call(&session_impl::dht_get_immutable_item, target);
#else #else
TORRENT_UNUSED(target); TORRENT_UNUSED(target);
#endif #endif
@ -520,7 +516,7 @@ namespace libtorrent
, std::string salt) , std::string salt)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL2(dht_get_mutable_item, key, salt); async_call(&session_impl::dht_get_mutable_item, key, salt);
#else #else
TORRENT_UNUSED(key); TORRENT_UNUSED(key);
TORRENT_UNUSED(salt); TORRENT_UNUSED(salt);
@ -534,7 +530,7 @@ namespace libtorrent
sha1_hash ret = hasher(&buf[0], int(buf.size())).final(); sha1_hash ret = hasher(&buf[0], int(buf.size())).final();
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL2(dht_put_immutable_item, data, ret); async_call(&session_impl::dht_put_immutable_item, data, ret);
#endif #endif
return ret; return ret;
} }
@ -545,7 +541,7 @@ namespace libtorrent
, std::string salt) , std::string salt)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL3(dht_put_mutable_item, key, cb, salt); async_call(&session_impl::dht_put_mutable_item, key, cb, salt);
#else #else
TORRENT_UNUSED(key); TORRENT_UNUSED(key);
TORRENT_UNUSED(cb); TORRENT_UNUSED(cb);
@ -556,7 +552,7 @@ namespace libtorrent
void session_handle::dht_get_peers(sha1_hash const& info_hash) void session_handle::dht_get_peers(sha1_hash const& info_hash)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL1(dht_get_peers, info_hash); async_call(&session_impl::dht_get_peers, info_hash);
#else #else
TORRENT_UNUSED(info_hash); TORRENT_UNUSED(info_hash);
#endif #endif
@ -565,7 +561,7 @@ namespace libtorrent
void session_handle::dht_announce(sha1_hash const& info_hash, int port, int flags) void session_handle::dht_announce(sha1_hash const& info_hash, int port, int flags)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL3(dht_announce, info_hash, port, flags); async_call(&session_impl::dht_announce, info_hash, port, flags);
#else #else
TORRENT_UNUSED(info_hash); TORRENT_UNUSED(info_hash);
TORRENT_UNUSED(port); TORRENT_UNUSED(port);
@ -576,7 +572,8 @@ namespace libtorrent
void session_handle::dht_direct_request(udp::endpoint ep, entry const& e, void* userdata) void session_handle::dht_direct_request(udp::endpoint ep, entry const& e, void* userdata)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL3(dht_direct_request, ep, e, userdata); entry copy = e;
async_call(&session_impl::dht_direct_request, ep, copy, userdata);
#else #else
TORRENT_UNUSED(ep); TORRENT_UNUSED(ep);
TORRENT_UNUSED(e); TORRENT_UNUSED(e);
@ -588,7 +585,7 @@ namespace libtorrent
entry session_handle::dht_state() const entry session_handle::dht_state() const
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
return TORRENT_SYNC_CALL_RET(entry, dht_state); return sync_call_ret<entry>(&session_impl::dht_state);
#else #else
return entry(); return entry();
#endif #endif
@ -597,7 +594,7 @@ namespace libtorrent
void session_handle::start_dht(entry const& startup_state) void session_handle::start_dht(entry const& startup_state)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL1(start_dht_deprecated, startup_state); async_call(&session_impl::start_dht_deprecated, startup_state);
#else #else
TORRENT_UNUSED(startup_state); TORRENT_UNUSED(startup_state);
#endif #endif
@ -607,7 +604,7 @@ namespace libtorrent
void session_handle::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> ext) void session_handle::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> ext)
{ {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
TORRENT_ASYNC_CALL1(add_extension, ext); async_call(&session_impl::add_extension, ext);
#else #else
TORRENT_UNUSED(ext); TORRENT_UNUSED(ext);
#endif #endif
@ -616,7 +613,7 @@ namespace libtorrent
void session_handle::add_extension(boost::shared_ptr<plugin> ext) void session_handle::add_extension(boost::shared_ptr<plugin> ext)
{ {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
TORRENT_ASYNC_CALL1(add_ses_extension, ext); async_call(&session_impl::add_ses_extension, ext);
#else #else
TORRENT_UNUSED(ext); TORRENT_UNUSED(ext);
#endif #endif
@ -651,13 +648,14 @@ namespace libtorrent
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
if (ret != 0) throw system_error(ec); if (ret != 0) throw system_error(ec);
#endif #endif
TORRENT_SYNC_CALL2(load_state, &e, flags); sync_call(&session_impl::load_state, &e, flags);
} }
entry session_handle::state() const entry session_handle::state() const
{ {
entry ret; entry ret;
TORRENT_SYNC_CALL2(save_state, &ret, 0xffffffff); auto retp = &ret;
sync_call(&session_impl::save_state, retp, 0xffffffff);
return ret; return ret;
} }
@ -677,24 +675,24 @@ namespace libtorrent
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
if (ret != 0) throw system_error(ec); if (ret != 0) throw system_error(ec);
#endif #endif
TORRENT_SYNC_CALL2(load_state, &e, flags); sync_call(&session_impl::load_state, &e, flags);
} }
#endif // TORRENT_NO_DEPRECATE #endif // TORRENT_NO_DEPRECATE
void session_handle::set_ip_filter(ip_filter const& f) void session_handle::set_ip_filter(ip_filter const& f)
{ {
boost::shared_ptr<ip_filter> copy = boost::make_shared<ip_filter>(f); boost::shared_ptr<ip_filter> copy = boost::make_shared<ip_filter>(f);
TORRENT_ASYNC_CALL1(set_ip_filter, copy); async_call(&session_impl::set_ip_filter, copy);
} }
ip_filter session_handle::get_ip_filter() const ip_filter session_handle::get_ip_filter() const
{ {
return TORRENT_SYNC_CALL_RET(ip_filter, get_ip_filter); return sync_call_ret<ip_filter>(&session_impl::get_ip_filter);
} }
void session_handle::set_port_filter(port_filter const& f) void session_handle::set_port_filter(port_filter const& f)
{ {
TORRENT_ASYNC_CALL1(set_port_filter, f); async_call(&session_impl::set_port_filter, f);
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -708,57 +706,57 @@ namespace libtorrent
peer_id session_handle::id() const peer_id session_handle::id() const
{ {
return TORRENT_SYNC_CALL_RET(peer_id, get_peer_id); return sync_call_ret<peer_id>(&session_impl::get_peer_id);
} }
void session_handle::set_key(int key) void session_handle::set_key(int key)
{ {
TORRENT_ASYNC_CALL1(set_key, key); async_call(&session_impl::set_key, key);
} }
unsigned short session_handle::listen_port() const unsigned short session_handle::listen_port() const
{ {
return TORRENT_SYNC_CALL_RET(unsigned short, listen_port); return sync_call_ret<unsigned short>(&session_impl::listen_port);
} }
unsigned short session_handle::ssl_listen_port() const unsigned short session_handle::ssl_listen_port() const
{ {
return TORRENT_SYNC_CALL_RET(unsigned short, ssl_listen_port); return sync_call_ret<unsigned short>(&session_impl::ssl_listen_port);
} }
bool session_handle::is_listening() const bool session_handle::is_listening() const
{ {
return TORRENT_SYNC_CALL_RET(bool, is_listening); return sync_call_ret<bool>(&session_impl::is_listening);
} }
void session_handle::set_peer_class_filter(ip_filter const& f) void session_handle::set_peer_class_filter(ip_filter const& f)
{ {
TORRENT_ASYNC_CALL1(set_peer_class_filter, f); async_call(&session_impl::set_peer_class_filter, f);
} }
void session_handle::set_peer_class_type_filter(peer_class_type_filter const& f) void session_handle::set_peer_class_type_filter(peer_class_type_filter const& f)
{ {
TORRENT_ASYNC_CALL1(set_peer_class_type_filter, f); async_call(&session_impl::set_peer_class_type_filter, f);
} }
int session_handle::create_peer_class(char const* name) int session_handle::create_peer_class(char const* name)
{ {
return TORRENT_SYNC_CALL_RET1(int, create_peer_class, name); return sync_call_ret<int>(&session_impl::create_peer_class, name);
} }
void session_handle::delete_peer_class(int cid) void session_handle::delete_peer_class(int cid)
{ {
TORRENT_ASYNC_CALL1(delete_peer_class, cid); async_call(&session_impl::delete_peer_class, cid);
} }
peer_class_info session_handle::get_peer_class(int cid) peer_class_info session_handle::get_peer_class(int cid)
{ {
return TORRENT_SYNC_CALL_RET1(peer_class_info, get_peer_class, cid); return sync_call_ret<peer_class_info>(&session_impl::get_peer_class, cid);
} }
void session_handle::set_peer_class(int cid, peer_class_info const& pci) void session_handle::set_peer_class(int cid, peer_class_info const& pci)
{ {
TORRENT_ASYNC_CALL2(set_peer_class, cid, pci); async_call(&session_impl::set_peer_class, cid, pci);
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -797,18 +795,18 @@ namespace libtorrent
#else #else
throw_invalid_handle(); throw_invalid_handle();
#endif #endif
TORRENT_ASYNC_CALL2(remove_torrent, h, options); async_call(&session_impl::remove_torrent, h, options);
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
void session_handle::set_settings(session_settings const& s) void session_handle::set_settings(session_settings const& s)
{ {
TORRENT_ASYNC_CALL1(set_settings, s); async_call(&session_impl::set_settings, s);
} }
session_settings session_handle::settings() const session_settings session_handle::settings() const
{ {
return TORRENT_SYNC_CALL_RET(session_settings, deprecated_settings); return sync_call_ret<session_settings>(&session_impl::deprecated_settings);
} }
void session_handle::set_pe_settings(pe_settings const& r) void session_handle::set_pe_settings(pe_settings const& r)
@ -848,12 +846,12 @@ namespace libtorrent
<= settings_pack::pe_both); <= settings_pack::pe_both);
boost::shared_ptr<settings_pack> copy = boost::make_shared<settings_pack>(s); boost::shared_ptr<settings_pack> copy = boost::make_shared<settings_pack>(s);
TORRENT_ASYNC_CALL1(apply_settings_pack, copy); async_call(&session_impl::apply_settings_pack, copy);
} }
settings_pack session_handle::get_settings() const settings_pack session_handle::get_settings() const
{ {
return TORRENT_SYNC_CALL_RET(settings_pack, get_settings); return sync_call_ret<settings_pack>(&session_impl::get_settings);
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -897,12 +895,12 @@ namespace libtorrent
int session_handle::num_uploads() const int session_handle::num_uploads() const
{ {
return TORRENT_SYNC_CALL_RET(int, num_uploads); return sync_call_ret<int>(&session_impl::num_uploads);
} }
int session_handle::num_connections() const int session_handle::num_connections() const
{ {
return TORRENT_SYNC_CALL_RET(int, num_connections); return sync_call_ret<int>(&session_impl::num_connections);
} }
void session_handle::set_peer_proxy(proxy_settings const& s) void session_handle::set_peer_proxy(proxy_settings const& s)
@ -947,66 +945,66 @@ namespace libtorrent
int session_handle::upload_rate_limit() const int session_handle::upload_rate_limit() const
{ {
return TORRENT_SYNC_CALL_RET(int, upload_rate_limit); return sync_call_ret<int>(&session_impl::upload_rate_limit_depr);
} }
int session_handle::download_rate_limit() const int session_handle::download_rate_limit() const
{ {
return TORRENT_SYNC_CALL_RET(int, download_rate_limit); return sync_call_ret<int>(&session_impl::download_rate_limit_depr);
} }
int session_handle::local_upload_rate_limit() const int session_handle::local_upload_rate_limit() const
{ {
return TORRENT_SYNC_CALL_RET(int, local_upload_rate_limit); return sync_call_ret<int>(&session_impl::local_upload_rate_limit);
} }
int session_handle::local_download_rate_limit() const int session_handle::local_download_rate_limit() const
{ {
return TORRENT_SYNC_CALL_RET(int, local_download_rate_limit); return sync_call_ret<int>(&session_impl::local_download_rate_limit);
} }
int session_handle::max_half_open_connections() const { return 8; } int session_handle::max_half_open_connections() const { return 8; }
void session_handle::set_local_upload_rate_limit(int bytes_per_second) void session_handle::set_local_upload_rate_limit(int bytes_per_second)
{ {
TORRENT_ASYNC_CALL1(set_local_upload_rate_limit, bytes_per_second); async_call(&session_impl::set_local_upload_rate_limit, bytes_per_second);
} }
void session_handle::set_local_download_rate_limit(int bytes_per_second) void session_handle::set_local_download_rate_limit(int bytes_per_second)
{ {
TORRENT_ASYNC_CALL1(set_local_download_rate_limit, bytes_per_second); async_call(&session_impl::set_local_download_rate_limit, bytes_per_second);
} }
void session_handle::set_upload_rate_limit(int bytes_per_second) void session_handle::set_upload_rate_limit(int bytes_per_second)
{ {
TORRENT_ASYNC_CALL1(set_upload_rate_limit, bytes_per_second); async_call(&session_impl::set_upload_rate_limit_depr, bytes_per_second);
} }
void session_handle::set_download_rate_limit(int bytes_per_second) void session_handle::set_download_rate_limit(int bytes_per_second)
{ {
TORRENT_ASYNC_CALL1(set_download_rate_limit, bytes_per_second); async_call(&session_impl::set_download_rate_limit_depr, bytes_per_second);
} }
void session_handle::set_max_connections(int limit) void session_handle::set_max_connections(int limit)
{ {
TORRENT_ASYNC_CALL1(set_max_connections, limit); async_call(&session_impl::set_max_connections, limit);
} }
void session_handle::set_max_uploads(int limit) void session_handle::set_max_uploads(int limit)
{ {
TORRENT_ASYNC_CALL1(set_max_uploads, limit); async_call(&session_impl::set_max_uploads, limit);
} }
void session_handle::set_max_half_open_connections(int) {} void session_handle::set_max_half_open_connections(int) {}
int session_handle::max_uploads() const int session_handle::max_uploads() const
{ {
return TORRENT_SYNC_CALL_RET(int, max_uploads); return sync_call_ret<int>(&session_impl::max_uploads);
} }
int session_handle::max_connections() const int session_handle::max_connections() const
{ {
return TORRENT_SYNC_CALL_RET(int, max_connections); return sync_call_ret<int>(&session_impl::max_connections);
} }
#endif // TORRENT_NO_DEPRECATE #endif // TORRENT_NO_DEPRECATE
@ -1051,7 +1049,7 @@ namespace libtorrent
size_t session_handle::set_alert_queue_size_limit(size_t queue_size_limit_) size_t session_handle::set_alert_queue_size_limit(size_t queue_size_limit_)
{ {
return TORRENT_SYNC_CALL_RET1(size_t, set_alert_queue_size_limit, queue_size_limit_); return sync_call_ret<size_t>(&session_impl::set_alert_queue_size_limit, queue_size_limit_);
} }
void session_handle::set_alert_mask(boost::uint32_t m) void session_handle::set_alert_mask(boost::uint32_t m)
@ -1111,12 +1109,12 @@ namespace libtorrent
int session_handle::add_port_mapping(session::protocol_type t, int external_port, int local_port) int session_handle::add_port_mapping(session::protocol_type t, int external_port, int local_port)
{ {
return TORRENT_SYNC_CALL_RET3(int, add_port_mapping, int(t), external_port, local_port); return sync_call_ret<int>(&session_impl::add_port_mapping, int(t), external_port, local_port);
} }
void session_handle::delete_port_mapping(int handle) void session_handle::delete_port_mapping(int handle)
{ {
TORRENT_ASYNC_CALL1(delete_port_mapping, handle); async_call(&session_impl::delete_port_mapping, handle);
} }
} // namespace libtorrent } // namespace libtorrent

View File

@ -5925,14 +5925,14 @@ namespace aux {
apply_settings_pack_impl(p); apply_settings_pack_impl(p);
} }
void session_impl::set_download_rate_limit(int bytes_per_second) void session_impl::set_download_rate_limit_depr(int bytes_per_second)
{ {
settings_pack p; settings_pack p;
p.set_int(settings_pack::download_rate_limit, bytes_per_second); p.set_int(settings_pack::download_rate_limit, bytes_per_second);
apply_settings_pack_impl(p); apply_settings_pack_impl(p);
} }
void session_impl::set_upload_rate_limit(int bytes_per_second) void session_impl::set_upload_rate_limit_depr(int bytes_per_second)
{ {
settings_pack p; settings_pack p;
p.set_int(settings_pack::upload_rate_limit, bytes_per_second); p.set_int(settings_pack::upload_rate_limit, bytes_per_second);
@ -5963,12 +5963,12 @@ namespace aux {
return download_rate_limit(m_local_peer_class); return download_rate_limit(m_local_peer_class);
} }
int session_impl::upload_rate_limit() const int session_impl::upload_rate_limit_depr() const
{ {
return upload_rate_limit(m_global_class); return upload_rate_limit(m_global_class);
} }
int session_impl::download_rate_limit() const int session_impl::download_rate_limit_depr() const
{ {
return download_rate_limit(m_global_class); return download_rate_limit(m_global_class);
} }

View File

@ -1434,7 +1434,7 @@ namespace libtorrent
m_extensions.erase(i); m_extensions.erase(i);
} }
void torrent::add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext void torrent::add_extension_fun(boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> const& ext
, void* userdata) , void* userdata)
{ {
boost::shared_ptr<torrent_plugin> tp(ext(get_handle(), userdata)); boost::shared_ptr<torrent_plugin> tp(ext(get_handle(), userdata));
@ -4773,7 +4773,7 @@ namespace libtorrent
m_state_subscription = false; m_state_subscription = false;
} }
void torrent::super_seeding(bool on) void torrent::set_super_seeding(bool on)
{ {
if (on == m_super_seeding) return; if (on == m_super_seeding) return;
@ -5948,7 +5948,7 @@ namespace libtorrent
update_want_tick(); update_want_tick();
} }
void torrent::remove_web_seed(std::list<web_seed_t>::iterator web) void torrent::remove_web_seed_iter(std::list<web_seed_t>::iterator web)
{ {
if (web->resolving) if (web->resolving)
{ {
@ -6014,7 +6014,7 @@ namespace libtorrent
, web->url, ec); , web->url, ec);
} }
// never try it again // never try it again
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -6029,7 +6029,7 @@ namespace libtorrent
, error_code(libtorrent::errors::peer_banned, get_libtorrent_category())); , error_code(libtorrent::errors::peer_banned, get_libtorrent_category()));
} }
// never try it again // never try it again
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -6044,7 +6044,7 @@ namespace libtorrent
m_ses.alerts().emplace_alert<url_seed_alert>(get_handle(), web->url, errors::unsupported_url_protocol); m_ses.alerts().emplace_alert<url_seed_alert>(get_handle(), web->url, errors::unsupported_url_protocol);
} }
// never try it again // never try it again
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -6056,7 +6056,7 @@ namespace libtorrent
, errors::invalid_hostname); , errors::invalid_hostname);
} }
// never try it again // never try it again
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -6068,7 +6068,7 @@ namespace libtorrent
, errors::invalid_port); , errors::invalid_port);
} }
// never try it again // never try it again
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -6080,7 +6080,7 @@ namespace libtorrent
, web->url, errors::port_blocked); , web->url, errors::port_blocked);
} }
// never try it again // never try it again
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -6146,7 +6146,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
debug_log("removed web seed"); debug_log("removed web seed");
#endif #endif
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -6162,7 +6162,7 @@ namespace libtorrent
// the name lookup failed for the http host. Don't try // the name lookup failed for the http host. Don't try
// this host again // this host again
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -6189,7 +6189,7 @@ namespace libtorrent
m_ses.alerts().emplace_alert<url_seed_alert>(get_handle() m_ses.alerts().emplace_alert<url_seed_alert>(get_handle()
, web->url, ec); , web->url, ec);
} }
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -6226,7 +6226,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING
debug_log("removed web seed"); debug_log("removed web seed");
#endif #endif
remove_web_seed(web); remove_web_seed_iter(web);
return; return;
} }
@ -9146,17 +9146,10 @@ namespace libtorrent
// add or remove a url that will be attempted for // add or remove a url that will be attempted for
// finding the file(s) in this torrent. // finding the file(s) in this torrent.
void torrent::add_web_seed(std::string const& url, web_seed_entry::type_t type) void torrent::add_web_seed(std::string const& url
{ , web_seed_entry::type_t type
web_seed_t ent(url, type); , std::string const& auth
// don't add duplicates , web_seed_entry::headers_t const& extra_headers)
if (std::find(m_web_seeds.begin(), m_web_seeds.end(), ent) != m_web_seeds.end()) return;
m_web_seeds.push_back(ent);
set_need_save_resume();
}
void torrent::add_web_seed(std::string const& url, web_seed_entry::type_t type
, std::string const& auth, web_seed_entry::headers_t const& extra_headers)
{ {
web_seed_t ent(url, type, auth, extra_headers); web_seed_t ent(url, type, auth, extra_headers);
// don't add duplicates // don't add duplicates
@ -10444,7 +10437,7 @@ namespace libtorrent
, (boost::bind(&web_seed_t::url, _1) , (boost::bind(&web_seed_t::url, _1)
== url && boost::bind(&web_seed_t::type, _1) == type)); == url && boost::bind(&web_seed_t::type, _1) == type));
if (i != m_web_seeds.end()) remove_web_seed(i); if (i != m_web_seeds.end()) remove_web_seed_iter(i);
} }
void torrent::disconnect_web_seed(peer_connection* p) void torrent::disconnect_web_seed(peer_connection* p)
@ -10465,7 +10458,7 @@ namespace libtorrent
i->peer_info.connection = 0; i->peer_info.connection = 0;
} }
void torrent::remove_web_seed(peer_connection* p, error_code const& ec void torrent::remove_web_seed_conn(peer_connection* p, error_code const& ec
, operation_t op, int error) , operation_t op, int error)
{ {
std::list<web_seed_t>::iterator i = std::find_if(m_web_seeds.begin() std::list<web_seed_t>::iterator i = std::find_if(m_web_seeds.begin()
@ -10485,7 +10478,7 @@ namespace libtorrent
peer->disconnect(ec, op, error); peer->disconnect(ec, op, error);
peer->set_peer_info(0); peer->set_peer_info(0);
} }
remove_web_seed(i); remove_web_seed_iter(i);
} }
void torrent::retry_web_seed(peer_connection* p, int retry) void torrent::retry_web_seed(peer_connection* p, int retry)
@ -10791,7 +10784,7 @@ namespace libtorrent
} }
#if !TORRENT_NO_FPU #if !TORRENT_NO_FPU
void torrent::file_progress(std::vector<float>& fp) void torrent::file_progress_float(std::vector<float>& fp)
{ {
TORRENT_ASSERT(is_single_thread()); TORRENT_ASSERT(is_single_thread());
if (!valid_metadata()) if (!valid_metadata())

View File

@ -30,19 +30,11 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <ctime> #include <ctime>
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <cctype> #include <cctype>
#include <algorithm>
#include <boost/optional.hpp>
#include <boost/bind.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/peer_id.hpp" #include "libtorrent/peer_id.hpp"
#include "libtorrent/bt_peer_connection.hpp" #include "libtorrent/bt_peer_connection.hpp"
@ -62,85 +54,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_info.hpp" // for peer_list_entry #include "libtorrent/peer_info.hpp" // for peer_list_entry
#endif #endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-macros"
#endif
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-macros"
#endif
#define TORRENT_ASYNC_CALL(x) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t))
#define TORRENT_ASYNC_CALL1(x, a1) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1))
#define TORRENT_ASYNC_CALL2(x, a1, a2) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2))
#define TORRENT_ASYNC_CALL3(x, a1, a2, a3) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2, a3))
#define TORRENT_ASYNC_CALL4(x, a1, a2, a3, a4) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (!t) return; \
session_impl& ses = static_cast<session_impl&>(t->session()); \
ses.get_io_service().dispatch(boost::bind(&torrent:: x, t, a1, a2, a3, a4))
#define TORRENT_SYNC_CALL(x) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t));
#define TORRENT_SYNC_CALL1(x, a1) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t, a1));
#define TORRENT_SYNC_CALL2(x, a1, a2) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t, a1, a2));
#define TORRENT_SYNC_CALL3(x, a1, a2, a3) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
if (t) aux::sync_call_handle(t, boost::bind(&torrent:: x, t, a1, a2, a3));
#define TORRENT_SYNC_CALL_RET(type, def, x) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
type r = def; \
if (t) aux::sync_call_ret_handle(t, r, boost::function<type(void)>(boost::bind(&torrent:: x, t)));
#define TORRENT_SYNC_CALL_RET1(type, def, x, a1) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
type r = def; \
if (t) aux::sync_call_ret_handle(t, r, boost::function<type(void)>(boost::bind(&torrent:: x, t, a1)));
#define TORRENT_SYNC_CALL_RET2(type, def, x, a1, a2) \
boost::shared_ptr<torrent> t = m_torrent.lock(); \
type r = def; \
if (t) aux::sync_call_ret_handle(t, r, boost::function<type(void)>(boost::bind(&torrent:: x, t, a1, a2)));
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
using libtorrent::aux::session_impl; using libtorrent::aux::session_impl;
namespace libtorrent namespace libtorrent
@ -153,6 +66,63 @@ namespace libtorrent
} }
#endif #endif
template<typename Fun, typename... Args>
void torrent_handle::async_call(Fun f, Args&&... a) const
{
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT_PRECOND(t);
if (!t) return;
session_impl& ses = static_cast<session_impl&>(t->session());
ses.get_io_service().dispatch([=] () { (t.get()->*f)(a...); } );
}
template<typename Fun, typename... Args>
void torrent_handle::sync_call(Fun f, Args&&... a) const
{
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT_PRECOND(t);
if (!t) return;
session_impl& ses = static_cast<session_impl&>(t->session());
// this is the flag to indicate the call has completed
bool done = false;
ses.get_io_service().dispatch([=,&done,&ses] ()
{
(t.get()->*f)(a...);
std::unique_lock<std::mutex> l(ses.mut);
done = true;
ses.cond.notify_all();
} );
aux::torrent_wait(done, ses);
}
template<typename Ret, typename Fun, typename... Args>
Ret torrent_handle::sync_call_ret(Ret def, Fun f, Args&&... a) const
{
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT_PRECOND(t);
Ret r = def;
if (!t) return r;
session_impl& ses = static_cast<session_impl&>(t->session());
// this is the flag to indicate the call has completed
bool done = false;
ses.get_io_service().dispatch([=,&r,&done,&ses] ()
{
r = (t.get()->*f)(a...);
std::unique_lock<std::mutex> l(ses.mut);
done = true;
ses.cond.notify_all();
} );
aux::torrent_wait(done, ses);
return r;
}
sha1_hash torrent_handle::info_hash() const sha1_hash torrent_handle::info_hash() const
{ {
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
@ -163,56 +133,52 @@ namespace libtorrent
int torrent_handle::max_uploads() const int torrent_handle::max_uploads() const
{ {
TORRENT_SYNC_CALL_RET(int, 0, max_uploads); return sync_call_ret<int>(0, &torrent::max_uploads);
return r;
} }
void torrent_handle::set_max_uploads(int max_uploads) const void torrent_handle::set_max_uploads(int max_uploads) const
{ {
TORRENT_ASSERT_PRECOND(max_uploads >= 2 || max_uploads == -1); TORRENT_ASSERT_PRECOND(max_uploads >= 2 || max_uploads == -1);
TORRENT_ASYNC_CALL2(set_max_uploads, max_uploads, true); async_call(&torrent::set_max_uploads, max_uploads, true);
} }
int torrent_handle::max_connections() const int torrent_handle::max_connections() const
{ {
TORRENT_SYNC_CALL_RET(int, 0, max_connections); return sync_call_ret<int>(0, &torrent::max_connections);
return r;
} }
void torrent_handle::set_max_connections(int max_connections) const void torrent_handle::set_max_connections(int max_connections) const
{ {
TORRENT_ASSERT_PRECOND(max_connections >= 2 || max_connections == -1); TORRENT_ASSERT_PRECOND(max_connections >= 2 || max_connections == -1);
TORRENT_ASYNC_CALL2(set_max_connections, max_connections, true); async_call(&torrent::set_max_connections, max_connections, true);
} }
void torrent_handle::set_upload_limit(int limit) const void torrent_handle::set_upload_limit(int limit) const
{ {
TORRENT_ASSERT_PRECOND(limit >= -1); TORRENT_ASSERT_PRECOND(limit >= -1);
TORRENT_ASYNC_CALL1(set_upload_limit, limit); async_call(&torrent::set_upload_limit, limit);
} }
int torrent_handle::upload_limit() const int torrent_handle::upload_limit() const
{ {
TORRENT_SYNC_CALL_RET(int, 0, upload_limit); return sync_call_ret<int>(0, &torrent::upload_limit);
return r;
} }
void torrent_handle::set_download_limit(int limit) const void torrent_handle::set_download_limit(int limit) const
{ {
TORRENT_ASSERT_PRECOND(limit >= -1); TORRENT_ASSERT_PRECOND(limit >= -1);
TORRENT_ASYNC_CALL1(set_download_limit, limit); async_call(&torrent::set_download_limit, limit);
} }
int torrent_handle::download_limit() const int torrent_handle::download_limit() const
{ {
TORRENT_SYNC_CALL_RET(int, 0, download_limit); return sync_call_ret<int>(0, &torrent::download_limit);
return r;
} }
void torrent_handle::move_storage( void torrent_handle::move_storage(
std::string const& save_path, int flags) const std::string const& save_path, int flags) const
{ {
TORRENT_ASYNC_CALL2(move_storage, save_path, flags); async_call(&torrent::move_storage, save_path, flags);
} }
#if TORRENT_USE_WSTRING #if TORRENT_USE_WSTRING
@ -222,21 +188,21 @@ namespace libtorrent
{ {
std::string utf8; std::string utf8;
wchar_utf8(save_path, utf8); wchar_utf8(save_path, utf8);
TORRENT_ASYNC_CALL2(move_storage, utf8, flags); async_call(&torrent::move_storage, utf8, flags);
} }
void torrent_handle::rename_file(int index, std::wstring const& new_name) const void torrent_handle::rename_file(int index, std::wstring const& new_name) const
{ {
std::string utf8; std::string utf8;
wchar_utf8(new_name, utf8); wchar_utf8(new_name, utf8);
TORRENT_ASYNC_CALL2(rename_file, index, utf8); async_call(&torrent::rename_file, index, utf8);
} }
#endif // TORRENT_NO_DEPRECATE #endif // TORRENT_NO_DEPRECATE
#endif // TORRENT_USE_WSTRING #endif // TORRENT_USE_WSTRING
void torrent_handle::rename_file(int index, std::string const& new_name) const void torrent_handle::rename_file(int index, std::string const& new_name) const
{ {
TORRENT_ASYNC_CALL2(rename_file, index, new_name); async_call(&torrent::rename_file, index, new_name);
} }
void torrent_handle::add_extension( void torrent_handle::add_extension(
@ -244,7 +210,7 @@ namespace libtorrent
, void* userdata) , void* userdata)
{ {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
TORRENT_ASYNC_CALL2(add_extension, ext, userdata); async_call(&torrent::add_extension_fun, ext, userdata);
#else #else
TORRENT_UNUSED(ext); TORRENT_UNUSED(ext);
TORRENT_UNUSED(userdata); TORRENT_UNUSED(userdata);
@ -253,38 +219,37 @@ namespace libtorrent
bool torrent_handle::set_metadata(char const* metadata, int size) const bool torrent_handle::set_metadata(char const* metadata, int size) const
{ {
TORRENT_SYNC_CALL_RET2(bool, false, set_metadata, metadata, size); return sync_call_ret<bool>(false, &torrent::set_metadata, metadata, size);
return r;
} }
void torrent_handle::pause(int flags) const void torrent_handle::pause(int flags) const
{ {
TORRENT_ASYNC_CALL1(pause, bool(flags & graceful_pause)); async_call(&torrent::pause, bool(flags & graceful_pause));
} }
void torrent_handle::stop_when_ready(bool b) const void torrent_handle::stop_when_ready(bool b) const
{ {
TORRENT_ASYNC_CALL1(stop_when_ready, b); async_call(&torrent::stop_when_ready, b);
} }
void torrent_handle::apply_ip_filter(bool b) const void torrent_handle::apply_ip_filter(bool b) const
{ {
TORRENT_ASYNC_CALL1(set_apply_ip_filter, b); async_call(&torrent::set_apply_ip_filter, b);
} }
void torrent_handle::set_share_mode(bool b) const void torrent_handle::set_share_mode(bool b) const
{ {
TORRENT_ASYNC_CALL1(set_share_mode, b); async_call(&torrent::set_share_mode, b);
} }
void torrent_handle::set_upload_mode(bool b) const void torrent_handle::set_upload_mode(bool b) const
{ {
TORRENT_ASYNC_CALL1(set_upload_mode, b); async_call(&torrent::set_upload_mode, b);
} }
void torrent_handle::flush_cache() const void torrent_handle::flush_cache() const
{ {
TORRENT_ASYNC_CALL(flush_cache); async_call(&torrent::flush_cache);
} }
void torrent_handle::set_ssl_certificate( void torrent_handle::set_ssl_certificate(
@ -294,7 +259,7 @@ namespace libtorrent
, std::string const& passphrase) , std::string const& passphrase)
{ {
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
TORRENT_ASYNC_CALL4(set_ssl_cert, certificate, private_key, dh_params, passphrase); async_call(&torrent::set_ssl_cert, certificate, private_key, dh_params, passphrase);
#else #else
TORRENT_UNUSED(certificate); TORRENT_UNUSED(certificate);
TORRENT_UNUSED(private_key); TORRENT_UNUSED(private_key);
@ -309,7 +274,7 @@ namespace libtorrent
, std::string const& dh_params) , std::string const& dh_params)
{ {
#ifdef TORRENT_USE_OPENSSL #ifdef TORRENT_USE_OPENSSL
TORRENT_ASYNC_CALL3(set_ssl_cert_buffer, certificate, private_key, dh_params); async_call(&torrent::set_ssl_cert_buffer, certificate, private_key, dh_params);
#else #else
TORRENT_UNUSED(certificate); TORRENT_UNUSED(certificate);
TORRENT_UNUSED(private_key); TORRENT_UNUSED(private_key);
@ -319,149 +284,148 @@ namespace libtorrent
void torrent_handle::save_resume_data(int f) const void torrent_handle::save_resume_data(int f) const
{ {
TORRENT_ASYNC_CALL1(save_resume_data, f); async_call(&torrent::save_resume_data, f);
} }
bool torrent_handle::need_save_resume_data() const bool torrent_handle::need_save_resume_data() const
{ {
TORRENT_SYNC_CALL_RET(bool, false, need_save_resume_data); return sync_call_ret<bool>(false, &torrent::need_save_resume_data);
return r;
} }
void torrent_handle::force_recheck() const void torrent_handle::force_recheck() const
{ {
TORRENT_ASYNC_CALL(force_recheck); async_call(&torrent::force_recheck);
} }
void torrent_handle::resume() const void torrent_handle::resume() const
{ {
TORRENT_ASYNC_CALL(resume); async_call(&torrent::resume);
} }
void torrent_handle::auto_managed(bool m) const void torrent_handle::auto_managed(bool m) const
{ {
TORRENT_ASYNC_CALL1(auto_managed, m); async_call(&torrent::auto_managed, m);
} }
void torrent_handle::set_priority(int p) const void torrent_handle::set_priority(int p) const
{ {
TORRENT_ASYNC_CALL1(set_priority, p); async_call(&torrent::set_priority, p);
} }
int torrent_handle::queue_position() const int torrent_handle::queue_position() const
{ {
TORRENT_SYNC_CALL_RET(int, -1, queue_position); return sync_call_ret<int>(-1, &torrent::queue_position);
return r;
} }
void torrent_handle::queue_position_up() const void torrent_handle::queue_position_up() const
{ {
TORRENT_ASYNC_CALL(queue_up); async_call(&torrent::queue_up);
} }
void torrent_handle::queue_position_down() const void torrent_handle::queue_position_down() const
{ {
TORRENT_ASYNC_CALL(queue_down); async_call(&torrent::queue_down);
} }
void torrent_handle::queue_position_top() const void torrent_handle::queue_position_top() const
{ {
TORRENT_ASYNC_CALL1(set_queue_position, 0); async_call(&torrent::set_queue_position, 0);
} }
void torrent_handle::queue_position_bottom() const void torrent_handle::queue_position_bottom() const
{ {
TORRENT_ASYNC_CALL1(set_queue_position, INT_MAX); async_call(&torrent::set_queue_position, INT_MAX);
} }
void torrent_handle::clear_error() const void torrent_handle::clear_error() const
{ {
TORRENT_ASYNC_CALL(clear_error); async_call(&torrent::clear_error);
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
void torrent_handle::set_tracker_login(std::string const& name void torrent_handle::set_tracker_login(std::string const& name
, std::string const& password) const , std::string const& password) const
{ {
TORRENT_ASYNC_CALL2(set_tracker_login, name, password); async_call(&torrent::set_tracker_login, name, password);
} }
#endif #endif
void torrent_handle::file_progress(std::vector<boost::int64_t>& progress, int flags) const void torrent_handle::file_progress(std::vector<boost::int64_t>& progress, int flags) const
{ {
TORRENT_SYNC_CALL2(file_progress, boost::ref(progress), flags); sync_call(&torrent::file_progress, std::ref(progress), flags);
} }
torrent_status torrent_handle::status(boost::uint32_t flags) const torrent_status torrent_handle::status(boost::uint32_t flags) const
{ {
torrent_status st; torrent_status st;
TORRENT_SYNC_CALL2(status, &st, flags); sync_call(&torrent::status, &st, flags);
return st; return st;
} }
void torrent_handle::set_pinned(bool p) const void torrent_handle::set_pinned(bool p) const
{ {
TORRENT_ASYNC_CALL1(set_pinned, p); async_call(&torrent::set_pinned, p);
} }
void torrent_handle::set_sequential_download(bool sd) const void torrent_handle::set_sequential_download(bool sd) const
{ {
TORRENT_ASYNC_CALL1(set_sequential_download, sd); async_call(&torrent::set_sequential_download, sd);
} }
void torrent_handle::piece_availability(std::vector<int>& avail) const void torrent_handle::piece_availability(std::vector<int>& avail) const
{ {
TORRENT_SYNC_CALL1(piece_availability, boost::ref(avail)); auto availr = std::ref(avail);
sync_call(&torrent::piece_availability, availr);
} }
void torrent_handle::piece_priority(int index, int priority) const void torrent_handle::piece_priority(int index, int priority) const
{ {
TORRENT_ASYNC_CALL2(set_piece_priority, index, priority); async_call(&torrent::set_piece_priority, index, priority);
} }
int torrent_handle::piece_priority(int index) const int torrent_handle::piece_priority(int index) const
{ {
TORRENT_SYNC_CALL_RET1(int, 0, piece_priority, index); return sync_call_ret<int>(0, &torrent::piece_priority, index);
return r;
} }
void torrent_handle::prioritize_pieces(std::vector<int> const& pieces) const void torrent_handle::prioritize_pieces(std::vector<int> const& pieces) const
{ {
TORRENT_ASYNC_CALL1(prioritize_pieces, pieces); async_call(&torrent::prioritize_pieces, pieces);
} }
void torrent_handle::prioritize_pieces(std::vector<std::pair<int, int> > const& pieces) const void torrent_handle::prioritize_pieces(std::vector<std::pair<int, int> > const& pieces) const
{ {
TORRENT_ASYNC_CALL1(prioritize_piece_list, pieces); async_call(&torrent::prioritize_piece_list, pieces);
} }
std::vector<int> torrent_handle::piece_priorities() const std::vector<int> torrent_handle::piece_priorities() const
{ {
std::vector<int> ret; std::vector<int> ret;
TORRENT_SYNC_CALL1(piece_priorities, &ret); auto retp = &ret;
sync_call(&torrent::piece_priorities, retp);
return ret; return ret;
} }
void torrent_handle::file_priority(int index, int priority) const void torrent_handle::file_priority(int index, int priority) const
{ {
TORRENT_ASYNC_CALL2(set_file_priority, index, priority); async_call(&torrent::set_file_priority, index, priority);
} }
int torrent_handle::file_priority(int index) const int torrent_handle::file_priority(int index) const
{ {
TORRENT_SYNC_CALL_RET1(int, 0, file_priority, index); return sync_call_ret<int>(0, &torrent::file_priority, index);
return r;
} }
void torrent_handle::prioritize_files(std::vector<int> const& files) const void torrent_handle::prioritize_files(std::vector<int> const& files) const
{ {
TORRENT_ASYNC_CALL1(prioritize_files, files); async_call(&torrent::prioritize_files, files);
} }
std::vector<int> torrent_handle::file_priorities() const std::vector<int> torrent_handle::file_priorities() const
{ {
std::vector<int> ret; std::vector<int> ret;
TORRENT_SYNC_CALL1(file_priorities, &ret); auto retp = &ret;
sync_call(&torrent::file_priorities, retp);
return ret; return ret;
} }
@ -475,84 +439,78 @@ namespace libtorrent
void torrent_handle::set_ratio(float) const {} void torrent_handle::set_ratio(float) const {}
void torrent_handle::use_interface(const char* net_interface) const void torrent_handle::use_interface(const char* net_interface) const
{ {
TORRENT_ASYNC_CALL1(use_interface, std::string(net_interface)); async_call(&torrent::use_interface, std::string(net_interface));
} }
#if !TORRENT_NO_FPU #if !TORRENT_NO_FPU
void torrent_handle::file_progress(std::vector<float>& progress) const void torrent_handle::file_progress(std::vector<float>& progress) const
{ {
TORRENT_SYNC_CALL1(file_progress, boost::ref(progress)); sync_call(&torrent::file_progress_float, std::ref(progress));
} }
#endif #endif
bool torrent_handle::is_seed() const bool torrent_handle::is_seed() const
{ {
TORRENT_SYNC_CALL_RET(bool, false, is_seed); return sync_call_ret<bool>(false, &torrent::is_seed);
return r;
} }
bool torrent_handle::is_finished() const bool torrent_handle::is_finished() const
{ {
TORRENT_SYNC_CALL_RET(bool, false, is_finished); return sync_call_ret<bool>(false, &torrent::is_finished);
return r;
} }
bool torrent_handle::is_paused() const bool torrent_handle::is_paused() const
{ {
TORRENT_SYNC_CALL_RET(bool, false, is_torrent_paused); return sync_call_ret<bool>(false, &torrent::is_torrent_paused);
return r;
} }
bool torrent_handle::is_sequential_download() const bool torrent_handle::is_sequential_download() const
{ {
TORRENT_SYNC_CALL_RET(bool, false, is_sequential_download); return sync_call_ret<bool>(false, &torrent::is_sequential_download);
return r;
} }
bool torrent_handle::is_auto_managed() const bool torrent_handle::is_auto_managed() const
{ {
TORRENT_SYNC_CALL_RET(bool, false, is_auto_managed); return sync_call_ret<bool>(false, &torrent::is_auto_managed);
return r;
} }
bool torrent_handle::has_metadata() const bool torrent_handle::has_metadata() const
{ {
TORRENT_SYNC_CALL_RET(bool, false, valid_metadata); return sync_call_ret<bool>(false, &torrent::valid_metadata);
return r;
} }
void torrent_handle::filter_piece(int index, bool filter) const void torrent_handle::filter_piece(int index, bool filter) const
{ {
TORRENT_ASYNC_CALL2(filter_piece, index, filter); async_call(&torrent::filter_piece, index, filter);
} }
void torrent_handle::filter_pieces(std::vector<bool> const& pieces) const void torrent_handle::filter_pieces(std::vector<bool> const& pieces) const
{ {
TORRENT_ASYNC_CALL1(filter_pieces, pieces); async_call(&torrent::filter_pieces, pieces);
} }
bool torrent_handle::is_piece_filtered(int index) const bool torrent_handle::is_piece_filtered(int index) const
{ {
TORRENT_SYNC_CALL_RET1(bool, false, is_piece_filtered, index); return sync_call_ret<bool>(false, &torrent::is_piece_filtered, index);
return r;
} }
std::vector<bool> torrent_handle::filtered_pieces() const std::vector<bool> torrent_handle::filtered_pieces() const
{ {
std::vector<bool> ret; std::vector<bool> ret;
TORRENT_SYNC_CALL1(filtered_pieces, ret); auto retr = std::ref(ret);
sync_call(&torrent::filtered_pieces, retr);
return ret; return ret;
} }
void torrent_handle::filter_files(std::vector<bool> const& files) const void torrent_handle::filter_files(std::vector<bool> const& files) const
{ {
TORRENT_ASYNC_CALL1(filter_files, files); auto filesr= std::ref(files);
async_call(&torrent::filter_files, filesr);
} }
bool torrent_handle::super_seeding() const bool torrent_handle::super_seeding() const
{ {
TORRENT_SYNC_CALL_RET(bool, false, super_seeding); return sync_call_ret<bool>(false, &torrent::super_seeding);
return r;
} }
// ============ end deprecation =============== // ============ end deprecation ===============
@ -561,75 +519,72 @@ namespace libtorrent
std::vector<announce_entry> torrent_handle::trackers() const std::vector<announce_entry> torrent_handle::trackers() const
{ {
static const std::vector<announce_entry> empty; static const std::vector<announce_entry> empty;
TORRENT_SYNC_CALL_RET(std::vector<announce_entry>, empty, trackers); return sync_call_ret<std::vector<announce_entry>>(empty, &torrent::trackers);
return r;
} }
void torrent_handle::add_url_seed(std::string const& url) const void torrent_handle::add_url_seed(std::string const& url) const
{ {
TORRENT_ASYNC_CALL2(add_web_seed, url, web_seed_entry::url_seed); async_call(&torrent::add_web_seed, url, web_seed_entry::url_seed
, std::string(), web_seed_entry::headers_t());
} }
void torrent_handle::remove_url_seed(std::string const& url) const void torrent_handle::remove_url_seed(std::string const& url) const
{ {
TORRENT_ASYNC_CALL2(remove_web_seed, url, web_seed_entry::url_seed); async_call(&torrent::remove_web_seed, url, web_seed_entry::url_seed);
} }
std::set<std::string> torrent_handle::url_seeds() const std::set<std::string> torrent_handle::url_seeds() const
{ {
static const std::set<std::string> empty; static const std::set<std::string> empty;
TORRENT_SYNC_CALL_RET1(std::set<std::string>, empty, web_seeds, web_seed_entry::url_seed); return sync_call_ret<std::set<std::string>>(empty, &torrent::web_seeds, web_seed_entry::url_seed);
return r;
} }
void torrent_handle::add_http_seed(std::string const& url) const void torrent_handle::add_http_seed(std::string const& url) const
{ {
TORRENT_ASYNC_CALL2(add_web_seed, url, web_seed_entry::http_seed); async_call(&torrent::add_web_seed, url, web_seed_entry::http_seed
, std::string(), web_seed_entry::headers_t());
} }
void torrent_handle::remove_http_seed(std::string const& url) const void torrent_handle::remove_http_seed(std::string const& url) const
{ {
TORRENT_ASYNC_CALL2(remove_web_seed, url, web_seed_entry::http_seed); async_call(&torrent::remove_web_seed, url, web_seed_entry::http_seed);
} }
std::set<std::string> torrent_handle::http_seeds() const std::set<std::string> torrent_handle::http_seeds() const
{ {
static const std::set<std::string> empty; static const std::set<std::string> empty;
TORRENT_SYNC_CALL_RET1(std::set<std::string>, empty, web_seeds, web_seed_entry::http_seed); return sync_call_ret<std::set<std::string>>(empty, &torrent::web_seeds, web_seed_entry::http_seed);
return r;
} }
void torrent_handle::replace_trackers( void torrent_handle::replace_trackers(
std::vector<announce_entry> const& urls) const std::vector<announce_entry> const& urls) const
{ {
TORRENT_ASYNC_CALL1(replace_trackers, urls); async_call(&torrent::replace_trackers, urls);
} }
void torrent_handle::add_tracker(announce_entry const& url) const void torrent_handle::add_tracker(announce_entry const& url) const
{ {
TORRENT_ASYNC_CALL1(add_tracker, url); async_call(&torrent::add_tracker, url);
} }
void torrent_handle::add_piece(int piece, char const* data, int flags) const void torrent_handle::add_piece(int piece, char const* data, int flags) const
{ {
TORRENT_SYNC_CALL3(add_piece, piece, data, flags); sync_call(&torrent::add_piece, piece, data, flags);
} }
void torrent_handle::read_piece(int piece) const void torrent_handle::read_piece(int piece) const
{ {
TORRENT_ASYNC_CALL1(read_piece, piece); async_call(&torrent::read_piece, piece);
} }
bool torrent_handle::have_piece(int piece) const bool torrent_handle::have_piece(int piece) const
{ {
TORRENT_SYNC_CALL_RET1(bool, false, have_piece, piece); return sync_call_ret<bool>(false, &torrent::have_piece, piece);
return r;
} }
storage_interface* torrent_handle::get_storage_impl() const storage_interface* torrent_handle::get_storage_impl() const
{ {
TORRENT_SYNC_CALL_RET(storage_interface*, 0, get_storage); return sync_call_ret<storage_interface*>(nullptr, &torrent::get_storage);
return r;
} }
bool torrent_handle::is_valid() const bool torrent_handle::is_valid() const
@ -639,9 +594,8 @@ namespace libtorrent
boost::shared_ptr<const torrent_info> torrent_handle::torrent_file() const boost::shared_ptr<const torrent_info> torrent_handle::torrent_file() const
{ {
TORRENT_SYNC_CALL_RET(boost::shared_ptr<const torrent_info> return sync_call_ret<boost::shared_ptr<const torrent_info>>(
, boost::shared_ptr<const torrent_info>(), get_torrent_copy); boost::shared_ptr<const torrent_info>(), &torrent::get_torrent_copy);
return r;
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -665,34 +619,33 @@ namespace libtorrent
entry torrent_handle::write_resume_data() const entry torrent_handle::write_resume_data() const
{ {
entry ret(entry::dictionary_t); entry ret(entry::dictionary_t);
TORRENT_SYNC_CALL1(write_resume_data, boost::ref(ret)); auto retr = std::ref(ret);
sync_call(&torrent::write_resume_data, retr);
return ret; return ret;
} }
std::string torrent_handle::save_path() const std::string torrent_handle::save_path() const
{ {
TORRENT_SYNC_CALL_RET(std::string, "", save_path); return sync_call_ret<std::string>("", &torrent::save_path);
return r;
} }
std::string torrent_handle::name() const std::string torrent_handle::name() const
{ {
TORRENT_SYNC_CALL_RET(std::string, "", name); return sync_call_ret<std::string>("", &torrent::name);
return r;
} }
#endif #endif
void torrent_handle::connect_peer(tcp::endpoint const& adr, int source, int flags) const void torrent_handle::connect_peer(tcp::endpoint const& adr, int source, int flags) const
{ {
TORRENT_ASYNC_CALL3(add_peer, adr, source, flags); async_call(&torrent::add_peer, adr, source, flags);
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
void torrent_handle::force_reannounce( void torrent_handle::force_reannounce(
boost::posix_time::time_duration duration) const boost::posix_time::time_duration duration) const
{ {
TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now() async_call(&torrent::force_tracker_request, aux::time_now()
+ seconds(duration.total_seconds()), -1); + seconds(duration.total_seconds()), -1);
} }
#endif #endif
@ -700,13 +653,13 @@ namespace libtorrent
void torrent_handle::force_dht_announce() const void torrent_handle::force_dht_announce() const
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL(dht_announce); async_call(&torrent::dht_announce);
#endif #endif
} }
void torrent_handle::force_reannounce(int s, int idx) const void torrent_handle::force_reannounce(int s, int idx) const
{ {
TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now() + seconds(s), idx); async_call(&torrent::force_tracker_request, aux::time_now() + seconds(s), idx);
} }
void torrent_handle::file_status(std::vector<pool_file_status>& status) const void torrent_handle::file_status(std::vector<pool_file_status>& status) const
@ -721,42 +674,45 @@ namespace libtorrent
void torrent_handle::scrape_tracker(int idx) const void torrent_handle::scrape_tracker(int idx) const
{ {
TORRENT_ASYNC_CALL2(scrape_tracker, idx, true); async_call(&torrent::scrape_tracker, idx, true);
} }
void torrent_handle::super_seeding(bool on) const void torrent_handle::super_seeding(bool on) const
{ {
TORRENT_ASYNC_CALL1(super_seeding, on); async_call(&torrent::set_super_seeding, on);
} }
void torrent_handle::get_full_peer_list(std::vector<peer_list_entry>& v) const void torrent_handle::get_full_peer_list(std::vector<peer_list_entry>& v) const
{ {
TORRENT_SYNC_CALL1(get_full_peer_list, &v); auto vp = &v;
sync_call(&torrent::get_full_peer_list, vp);
} }
void torrent_handle::get_peer_info(std::vector<peer_info>& v) const void torrent_handle::get_peer_info(std::vector<peer_info>& v) const
{ {
TORRENT_SYNC_CALL1(get_peer_info, &v); auto vp = &v;
sync_call(&torrent::get_peer_info, vp);
} }
void torrent_handle::get_download_queue(std::vector<partial_piece_info>& queue) const void torrent_handle::get_download_queue(std::vector<partial_piece_info>& queue) const
{ {
TORRENT_SYNC_CALL1(get_download_queue, &queue); auto queuep = &queue;
sync_call(&torrent::get_download_queue, queuep);
} }
void torrent_handle::set_piece_deadline(int index, int deadline, int flags) const void torrent_handle::set_piece_deadline(int index, int deadline, int flags) const
{ {
TORRENT_ASYNC_CALL3(set_piece_deadline, index, deadline, flags); async_call(&torrent::set_piece_deadline, index, deadline, flags);
} }
void torrent_handle::reset_piece_deadline(int index) const void torrent_handle::reset_piece_deadline(int index) const
{ {
TORRENT_ASYNC_CALL1(reset_piece_deadline, index); async_call(&torrent::reset_piece_deadline, index);
} }
void torrent_handle::clear_piece_deadlines() const void torrent_handle::clear_piece_deadlines() const
{ {
TORRENT_ASYNC_CALL(clear_time_critical); async_call(&torrent::clear_time_critical);
} }
boost::shared_ptr<torrent> torrent_handle::native_handle() const boost::shared_ptr<torrent> torrent_handle::native_handle() const

View File

@ -581,7 +581,7 @@ void web_peer_connection::handle_redirect(int bytes_left)
if (location.empty()) if (location.empty())
{ {
// we should not try this server again. // we should not try this server again.
t->remove_web_seed(this, errors::missing_location, op_bittorrent, 2); t->remove_web_seed_conn(this, errors::missing_location, op_bittorrent, 2);
m_web = NULL; m_web = NULL;
TORRENT_ASSERT(is_disconnecting()); TORRENT_ASSERT(is_disconnecting());
return; return;
@ -614,7 +614,7 @@ void web_peer_connection::handle_redirect(int bytes_left)
size_t i = location.rfind(path); size_t i = location.rfind(path);
if (i == std::string::npos) if (i == std::string::npos)
{ {
t->remove_web_seed(this, errors::invalid_redirection, op_bittorrent, 2); t->remove_web_seed_conn(this, errors::invalid_redirection, op_bittorrent, 2);
m_web = NULL; m_web = NULL;
TORRENT_ASSERT(is_disconnecting()); TORRENT_ASSERT(is_disconnecting());
return; return;
@ -630,7 +630,7 @@ void web_peer_connection::handle_redirect(int bytes_left)
peer_log(peer_log_alert::info, "LOCATION", "%s", location.c_str()); peer_log(peer_log_alert::info, "LOCATION", "%s", location.c_str());
#endif #endif
t->add_web_seed(location, web_seed_entry::url_seed, m_external_auth, m_extra_headers); t->add_web_seed(location, web_seed_entry::url_seed, m_external_auth, m_extra_headers);
t->remove_web_seed(this, errors::redirecting, op_bittorrent, 2); t->remove_web_seed_conn(this, errors::redirecting, op_bittorrent, 2);
m_web = NULL; m_web = NULL;
TORRENT_ASSERT(is_disconnecting()); TORRENT_ASSERT(is_disconnecting());
return; return;
@ -763,7 +763,7 @@ void web_peer_connection::on_receive(error_code const& error
{ {
received_bytes(0, recv_buffer.left()); received_bytes(0, recv_buffer.left());
// we should not try this server again. // we should not try this server again.
t->remove_web_seed(this, ec, op_bittorrent, 2); t->remove_web_seed_conn(this, ec, op_bittorrent, 2);
m_web = NULL; m_web = NULL;
TORRENT_ASSERT(is_disconnecting()); TORRENT_ASSERT(is_disconnecting());
return; return;