From 2e7333792ff0e8acd32ebf9a46f2c9fe6788dc82 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Tue, 7 Jun 2005 01:19:18 +0000 Subject: [PATCH] Changed api for listen ip and bind. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@454 e378c898-3ddf-0310-93e7-cc216c733640 --- rak/functional.h | 116 +++++++++++++++++++++++++++++++- src/core/manager.cc | 4 +- src/core/manager.h | 2 - src/display/window_statusbar.cc | 5 +- src/main.cc | 5 +- src/option_handler_rules.cc | 12 ++-- src/option_handler_rules.h | 2 +- 7 files changed, 131 insertions(+), 15 deletions(-) diff --git a/rak/functional.h b/rak/functional.h index e5c36db5..dce5b446 100644 --- a/rak/functional.h +++ b/rak/functional.h @@ -27,6 +27,16 @@ namespace rak { +template +struct reference_fix { + typedef Type type; +}; + +template +struct reference_fix { + typedef Type type; +}; + template struct _accumulate { _accumulate(Type& t, Ftor f) : m_t(t), m_f(f) {} @@ -44,6 +54,8 @@ accumulate(Type& t, Ftor f) { return _accumulate(t, f); } +// Operators: + template struct _equal { _equal(Type t, Ftor f) : m_t(t), m_f(f) {} @@ -63,11 +75,87 @@ equal(Type t, Ftor f) { return _equal(t, f); } +template +struct _less { + _less(Type t, Ftor f) : m_t(t), m_f(f) {} + + template + bool operator () (Arg& a) { + return m_t < m_f(a); + } + + Type m_t; + Ftor m_f; +}; + +template +inline _less +less(Type t, Ftor f) { + return _less(t, f); +} + +template +struct _greater { + _greater(Type t, Ftor f) : m_t(t), m_f(f) {} + + template + bool operator () (Arg& a) { + return m_t > m_f(a); + } + + Type m_t; + Ftor m_f; +}; + +template +inline _greater +greater(Type t, Ftor f) { + return _greater(t, f); +} + +template +struct _less_equal { + _less_equal(Type t, Ftor f) : m_t(t), m_f(f) {} + + template + bool operator () (Arg& a) { + return m_t <= m_f(a); + } + + Type m_t; + Ftor m_f; +}; + +template +inline _less_equal +less_equal(Type t, Ftor f) { + return _less_equal(t, f); +} + +template +struct _greater_equal { + _greater_equal(Type t, Ftor f) : m_t(t), m_f(f) {} + + template + bool operator () (Arg& a) { + return m_t >= m_f(a); + } + + Type m_t; + Ftor m_f; +}; + +template +inline _greater_equal +greater_equal(Type t, Ftor f) { + return _greater_equal(t, f); +} + template struct _on : public std::unary_function { _on(Src s, Dest d) : m_dest(d), m_src(s) {} - typename Dest::result_type operator () (typename Src::argument_type arg) { + typename Dest::result_type operator () (typename reference_fix::type arg) { return m_dest(m_src(arg)); } @@ -126,6 +214,32 @@ struct call_delete : public std::unary_function { } }; +template +class bind1st_t : public std::unary_function { +protected: + typedef typename reference_fix::type value_type; + typedef typename reference_fix::type argument_type; + + Operation m_op; + value_type m_value; + +public: + bind1st_t(const Operation& op, const value_type v) : + m_op(op), m_value(v) {} + + typename Operation::result_type + operator () (const argument_type arg) { + return m_op(m_value, arg); + } +}; + +template +inline bind1st_t +bind1st(const Operation& op, const Type& val) { + return bind1st_t(op, val); +} + } #endif diff --git a/src/core/manager.cc b/src/core/manager.cc index 7c82c6d3..0f761634 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -47,9 +47,9 @@ Manager::initialize() { CurlStack::init(); - torrent::initialize(); + //torrent::initialize(); - if (!torrent::listen_open(m_portFirst, m_portLast, m_listenIp)) + if (!torrent::listen_open(m_portFirst, m_portLast)) throw std::runtime_error("Could not open port for listening."); // Register log signals. diff --git a/src/core/manager.h b/src/core/manager.h index 35fee60f..b8ab1c81 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -68,7 +68,6 @@ public: void stop(Download* d); void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; } - void set_listen_ip(const std::string& ip) { m_listenIp = ip; } void debug_tracker() { m_debugTracker = 0; } @@ -97,7 +96,6 @@ private: int m_portFirst; int m_portLast; - std::string m_listenIp; int m_debugTracker; }; diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index 5f901c0a..90c55260 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -56,10 +56,11 @@ WindowStatusbar::redraw() { else pos = snprintf(buf + pos, 128 - pos, "%-3i", (int)torrent::get(torrent::THROTTLE_READ_CONST_RATE) / 1024); - m_canvas->print(0, 0, "Throttle U/D: %s Listen: %i Handshakes: %i", + m_canvas->print(0, 0, "Throttle U/D: %s Listen: %s:%i%s Handshakes: %i", buf, - //m_core->get_dns().empty() ? "" : m_core->get_dns().c_str(), + !torrent::get_ip().empty() ? torrent::get_ip().c_str() : "", (int)torrent::get(torrent::LISTEN_PORT), + !torrent::get_bind().empty() ? (" Bind: " + torrent::get_bind()).c_str() : "", (int)torrent::get(torrent::HANDSHAKES_TOTAL)); } diff --git a/src/main.cc b/src/main.cc index 85e787ef..59b7ac16 100644 --- a/src/main.cc +++ b/src/main.cc @@ -122,8 +122,8 @@ initialize_option_handler(ui::Control* c, OptionHandler* optionHandler) { optionHandler->insert("upload_rate", new OptionHandlerInt(c, &apply_global_upload_rate, &validate_rate)); optionHandler->insert("directory", new OptionHandlerDownloadString(dsm, &apply_download_directory, &validate_directory)); - optionHandler->insert("ip", new OptionHandlerDownloadString(dsm, &apply_download_ip, &validate_ip)); + optionHandler->insert("ip", new OptionHandlerString(c, &apply_ip, &validate_ip)); optionHandler->insert("bind", new OptionHandlerString(c, &apply_bind, &validate_ip)); optionHandler->insert("port", new OptionHandlerString(c, &apply_port_range, &validate_port_range)); } @@ -190,6 +190,9 @@ main(int argc, char** argv) { SignalHandler::set_handler(SIGSEGV, sigc::bind(sigc::ptr_fun(&do_panic), SIGSEGV)); SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS)); + // Need to initialize this before parseing options. + torrent::initialize(); + if (getenv("HOME")) load_option_file(getenv("HOME") + std::string("/.rtorrent.rc"), &optionHandler); diff --git a/src/option_handler_rules.cc b/src/option_handler_rules.cc index 64f899c7..b6f1b1b9 100644 --- a/src/option_handler_rules.cc +++ b/src/option_handler_rules.cc @@ -80,11 +80,6 @@ apply_download_directory(core::Download* d, const std::string& arg) { (d->get_download().get_entry_size() > 1 ? d->get_download().get_name() : "")); } -void -apply_download_ip(core::Download* d, const std::string& arg) { - d->get_download().set_ip(arg); -} - void apply_global_download_rate(ui::Control* m, int arg) { torrent::set(torrent::THROTTLE_READ_CONST_RATE, arg * 1024); @@ -97,7 +92,12 @@ apply_global_upload_rate(ui::Control* m, int arg) { void apply_bind(ui::Control* m, const std::string& arg) { - m->get_core().set_listen_ip(arg); + torrent::set_bind(arg); +} + +void +apply_ip(ui::Control* m, const std::string& arg) { + torrent::set_ip(arg); } // The arg string *must* have been checked with validate_port_range diff --git a/src/option_handler_rules.h b/src/option_handler_rules.h index 02a15798..56b07e96 100644 --- a/src/option_handler_rules.h +++ b/src/option_handler_rules.h @@ -46,11 +46,11 @@ void apply_download_max_peers(core::Download* d, int arg); void apply_download_max_uploads(core::Download* d, int arg); void apply_download_directory(core::Download* d, const std::string& arg); -void apply_download_ip(core::Download* d, const std::string& arg); void apply_global_download_rate(ui::Control* m, int arg); void apply_global_upload_rate(ui::Control* m, int arg); +void apply_ip(ui::Control* m, const std::string& arg); void apply_bind(ui::Control* m, const std::string& arg); void apply_port_range(ui::Control* m, const std::string& arg);