Changed api for listen ip and bind.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@454 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-06-07 01:19:18 +00:00
parent 3092a583ca
commit 2e7333792f
7 changed files with 131 additions and 15 deletions
+115 -1
View File
@@ -27,6 +27,16 @@
namespace rak {
template <typename Type>
struct reference_fix {
typedef Type type;
};
template <typename Type>
struct reference_fix<Type&> {
typedef Type type;
};
template <typename Type, typename Ftor>
struct _accumulate {
_accumulate(Type& t, Ftor f) : m_t(t), m_f(f) {}
@@ -44,6 +54,8 @@ accumulate(Type& t, Ftor f) {
return _accumulate<Type, Ftor>(t, f);
}
// Operators:
template <typename Type, typename Ftor>
struct _equal {
_equal(Type t, Ftor f) : m_t(t), m_f(f) {}
@@ -63,11 +75,87 @@ equal(Type t, Ftor f) {
return _equal<Type, Ftor>(t, f);
}
template <typename Type, typename Ftor>
struct _less {
_less(Type t, Ftor f) : m_t(t), m_f(f) {}
template <typename Arg>
bool operator () (Arg& a) {
return m_t < m_f(a);
}
Type m_t;
Ftor m_f;
};
template <typename Type, typename Ftor>
inline _less<Type, Ftor>
less(Type t, Ftor f) {
return _less<Type, Ftor>(t, f);
}
template <typename Type, typename Ftor>
struct _greater {
_greater(Type t, Ftor f) : m_t(t), m_f(f) {}
template <typename Arg>
bool operator () (Arg& a) {
return m_t > m_f(a);
}
Type m_t;
Ftor m_f;
};
template <typename Type, typename Ftor>
inline _greater<Type, Ftor>
greater(Type t, Ftor f) {
return _greater<Type, Ftor>(t, f);
}
template <typename Type, typename Ftor>
struct _less_equal {
_less_equal(Type t, Ftor f) : m_t(t), m_f(f) {}
template <typename Arg>
bool operator () (Arg& a) {
return m_t <= m_f(a);
}
Type m_t;
Ftor m_f;
};
template <typename Type, typename Ftor>
inline _less_equal<Type, Ftor>
less_equal(Type t, Ftor f) {
return _less_equal<Type, Ftor>(t, f);
}
template <typename Type, typename Ftor>
struct _greater_equal {
_greater_equal(Type t, Ftor f) : m_t(t), m_f(f) {}
template <typename Arg>
bool operator () (Arg& a) {
return m_t >= m_f(a);
}
Type m_t;
Ftor m_f;
};
template <typename Type, typename Ftor>
inline _greater_equal<Type, Ftor>
greater_equal(Type t, Ftor f) {
return _greater_equal<Type, Ftor>(t, f);
}
template <typename Src, typename Dest>
struct _on : public std::unary_function<typename Src::argument_type, typename Dest::result_type> {
_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<typename Src::argument_type>::type arg) {
return m_dest(m_src(arg));
}
@@ -126,6 +214,32 @@ struct call_delete : public std::unary_function<T*, void> {
}
};
template <typename Operation>
class bind1st_t : public std::unary_function<typename Operation::second_argument_type,
typename Operation::result_type> {
protected:
typedef typename reference_fix<typename Operation::first_argument_type>::type value_type;
typedef typename reference_fix<typename Operation::second_argument_type>::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 <typename Operation, typename Type>
inline bind1st_t<Operation>
bind1st(const Operation& op, const Type& val) {
return bind1st_t<Operation>(op, val);
}
}
#endif
+2 -2
View File
@@ -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.
-2
View File
@@ -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;
};
+3 -2
View File
@@ -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() ? "<default>" : m_core->get_dns().c_str(),
!torrent::get_ip().empty() ? torrent::get_ip().c_str() : "<default>",
(int)torrent::get(torrent::LISTEN_PORT),
!torrent::get_bind().empty() ? (" Bind: " + torrent::get_bind()).c_str() : "",
(int)torrent::get(torrent::HANDSHAKES_TOTAL));
}
+4 -1
View File
@@ -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);
+6 -6
View File
@@ -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
+1 -1
View File
@@ -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);