refactor for more use of move with settings_pack (#1162)

This commit is contained in:
Alden Torres 2016-09-28 13:28:43 -04:00 committed by Arvid Norberg
parent 85dd682551
commit 84e735c0ea
6 changed files with 28 additions and 18 deletions

View File

@ -1311,7 +1311,7 @@ int main(int argc, char* argv[])
switch (argv[i][1]) switch (argv[i][1])
{ {
case 'f': g_log_file = std::fopen(arg, "w+"); break; case 'f': g_log_file = std::fopen(arg, "w+"); break;
case 'k': high_performance_seed(settings); --i; break; case 'k': settings = high_performance_seed(); --i; break;
case 'G': seed_mode = true; --i; break; case 'G': seed_mode = true; --i; break;
case 's': save_path = arg; break; case 's': save_path = arg; break;
case 'U': torrent_upload_limit = atoi(arg) * 1000; break; case 'U': torrent_upload_limit = atoi(arg) * 1000; break;

View File

@ -216,7 +216,7 @@ namespace libtorrent
session_impl(io_service& ios); session_impl(io_service& ios);
virtual ~session_impl(); virtual ~session_impl();
void start_session(settings_pack const& pack); void start_session(settings_pack pack);
void set_load_function(user_load_function_t fun) void set_load_function(user_load_function_t fun)
{ m_user_load_torrent = fun; } { m_user_load_torrent = fun; }

View File

@ -76,8 +76,16 @@ namespace libtorrent
// serving many peers and that doesn't do any downloading. It has a 128 MB // serving many peers and that doesn't do any downloading. It has a 128 MB
// disk cache and has a limit of 400 files in its file pool. It support fast // disk cache and has a limit of 400 files in its file pool. It support fast
// upload rates by allowing large send buffers. // upload rates by allowing large send buffers.
TORRENT_EXPORT void min_memory_usage(settings_pack& set); TORRENT_EXPORT settings_pack min_memory_usage();
TORRENT_EXPORT void high_performance_seed(settings_pack& set); TORRENT_EXPORT settings_pack high_performance_seed();
#ifndef TORRENT_NO_DEPRECATE
TORRENT_DEPRECATED
inline void min_memory_usage(settings_pack& set)
{ set = min_memory_usage(); }
TORRENT_DEPRECATED
inline void high_performance_seed(settings_pack& set)
{ set = high_performance_seed(); }
#endif
#ifndef TORRENT_CFG #ifndef TORRENT_CFG
#error TORRENT_CFG is not defined! #error TORRENT_CFG is not defined!
@ -215,7 +223,7 @@ namespace libtorrent
: session_handle(nullptr) : session_handle(nullptr)
{ {
TORRENT_CFG(); TORRENT_CFG();
start(flags, pack, nullptr); start(flags, std::move(pack), nullptr);
} }
// moveable // moveable
@ -245,7 +253,7 @@ namespace libtorrent
: session_handle(nullptr) : session_handle(nullptr)
{ {
TORRENT_CFG(); TORRENT_CFG();
start(flags, pack, &ios); start(flags, std::move(pack), &ios);
} }
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE

View File

@ -38,12 +38,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/aux_/session_call.hpp" #include "libtorrent/aux_/session_call.hpp"
using libtorrent::aux::session_impl;
namespace libtorrent namespace libtorrent
{ {
void min_memory_usage(settings_pack& set) settings_pack min_memory_usage()
{ {
settings_pack set;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
// receive data directly into disk buffers // receive data directly into disk buffers
// this yields more system calls to read() and // this yields more system calls to read() and
@ -128,10 +127,12 @@ namespace libtorrent
// whole pieces // whole pieces
set.set_bool(settings_pack::coalesce_reads, false); set.set_bool(settings_pack::coalesce_reads, false);
set.set_bool(settings_pack::coalesce_writes, false); set.set_bool(settings_pack::coalesce_writes, false);
return set;
} }
void high_performance_seed(settings_pack& set) settings_pack high_performance_seed()
{ {
settings_pack set;
// don't throttle TCP, assume there is // don't throttle TCP, assume there is
// plenty of bandwidth // plenty of bandwidth
set.set_int(settings_pack::mixed_mode_algorithm, settings_pack::prefer_tcp); set.set_int(settings_pack::mixed_mode_algorithm, settings_pack::prefer_tcp);
@ -246,6 +247,7 @@ namespace libtorrent
// the disk cache performs better with the pool allocator // the disk cache performs better with the pool allocator
set.set_bool(settings_pack::use_disk_cache_pool, true); set.set_bool(settings_pack::use_disk_cache_pool, true);
return set;
} }
#ifndef TORRENT_CFG #ifndef TORRENT_CFG
@ -308,7 +310,7 @@ namespace libtorrent
ios = m_io_service.get(); ios = m_io_service.get();
} }
m_impl = std::make_shared<session_impl>(*ios); m_impl = std::make_shared<aux::session_impl>(*ios);
*static_cast<session_handle*>(this) = session_handle(m_impl.get()); *static_cast<session_handle*>(this) = session_handle(m_impl.get());
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
@ -330,7 +332,7 @@ namespace libtorrent
{ {
// start a thread for the message pump // start a thread for the message pump
m_thread = std::make_shared<std::thread>( m_thread = std::make_shared<std::thread>(
[&]() { m_io_service->run(); }); [&] { m_io_service->run(); });
} }
} }
@ -341,7 +343,7 @@ namespace libtorrent
{ {
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
if (empty) return {}; if (empty) return {};
using wrapper = session_impl::session_plugin_wrapper; using wrapper = aux::session_impl::session_plugin_wrapper;
return { return {
std::make_shared<wrapper>(create_ut_pex_plugin), std::make_shared<wrapper>(create_ut_pex_plugin),
std::make_shared<wrapper>(create_ut_metadata_plugin), std::make_shared<wrapper>(create_ut_metadata_plugin),
@ -365,11 +367,11 @@ namespace libtorrent
aux::dump_call_profile(); aux::dump_call_profile();
TORRENT_ASSERT(m_impl); TORRENT_ASSERT(m_impl);
std::shared_ptr<session_impl> ptr = m_impl; std::shared_ptr<aux::session_impl> ptr = m_impl;
// capture the shared_ptr in the dispatched function // capture the shared_ptr in the dispatched function
// to keep the session_impl alive // to keep the session_impl alive
m_impl->get_io_service().dispatch([=]() { ptr->abort(); }); m_impl->get_io_service().dispatch([=] { ptr->abort(); });
#if defined TORRENT_ASIO_DEBUGGING #if defined TORRENT_ASIO_DEBUGGING
int counter = 0; int counter = 0;

View File

@ -833,7 +833,7 @@ namespace libtorrent
|| s.get_int(settings_pack::allowed_enc_level) || s.get_int(settings_pack::allowed_enc_level)
<= settings_pack::pe_both); <= settings_pack::pe_both);
std::shared_ptr<settings_pack> copy = std::make_shared<settings_pack>(std::move(s)); auto copy = std::make_shared<settings_pack>(std::move(s));
async_call(&session_impl::apply_settings_pack, copy); async_call(&session_impl::apply_settings_pack, copy);
} }

View File

@ -447,7 +447,7 @@ namespace aux {
// io_service thread. // io_service thread.
// TODO: 2 is there a reason not to move all of this into init()? and just // TODO: 2 is there a reason not to move all of this into init()? and just
// post it to the io_service? // post it to the io_service?
void session_impl::start_session(settings_pack const& pack) void session_impl::start_session(settings_pack pack)
{ {
if (pack.has_val(settings_pack::alert_mask)) if (pack.has_val(settings_pack::alert_mask))
{ {
@ -520,7 +520,7 @@ namespace aux {
} }
#endif #endif
std::shared_ptr<settings_pack> copy = std::make_shared<settings_pack>(pack); auto copy = std::make_shared<settings_pack>(std::move(pack));
m_io_service.post(std::bind(&session_impl::init, this, copy)); m_io_service.post(std::bind(&session_impl::init, this, copy));
} }