mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-13 04:36:16 +00:00
Fixed memory leak of PeerConnection::m_read and
PeerConnection::m_write. Moved src/net/protocol_* to src/peer/. Moved over to using PeerConnectionBase and created factory class and setting for seeder/leecher. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@483 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -31,6 +31,21 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
Download::Download() :
|
||||
m_connectionLeech("default"),
|
||||
m_connectionSeed("default") {
|
||||
}
|
||||
|
||||
void
|
||||
Download::start() {
|
||||
if (is_done())
|
||||
m_download.set_connection_type(m_connectionSeed);
|
||||
else
|
||||
m_download.set_connection_type(m_connectionLeech);
|
||||
|
||||
m_download.start();
|
||||
}
|
||||
|
||||
void
|
||||
Download::set_download(torrent::Download d) {
|
||||
m_download = d;
|
||||
@@ -49,9 +64,19 @@ Download::set_root_directory(const std::string& d) {
|
||||
|
||||
void
|
||||
Download::release_download() {
|
||||
if (!m_download.is_valid())
|
||||
return;
|
||||
|
||||
m_connTrackerSucceded.disconnect();
|
||||
m_connTrackerFailed.disconnect();
|
||||
m_connStorageError.disconnect();
|
||||
|
||||
m_download = torrent::Download();
|
||||
}
|
||||
|
||||
void
|
||||
Download::receive_finished() {
|
||||
m_download.set_connection_type(m_connectionSeed);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -31,9 +31,14 @@ namespace core {
|
||||
|
||||
class Download {
|
||||
public:
|
||||
Download();
|
||||
~Download() { release_download(); }
|
||||
|
||||
bool is_open() { return m_download.is_open(); }
|
||||
inline bool is_done();
|
||||
|
||||
void start();
|
||||
|
||||
void set_download(torrent::Download d);
|
||||
void release_download();
|
||||
|
||||
@@ -45,6 +50,9 @@ public:
|
||||
|
||||
void set_root_directory(const std::string& d);
|
||||
|
||||
void set_connection_leech(const std::string& name) { m_connectionLeech = name; }
|
||||
void set_connection_seed(const std::string& name) { m_connectionSeed = name; }
|
||||
|
||||
// Helper functions for calling functions in torrent::Download
|
||||
// through sigc++.
|
||||
template <typename Ret, Ret (torrent::Download::*func)()>
|
||||
@@ -55,6 +63,8 @@ public:
|
||||
|
||||
bool operator == (const std::string& str) { return str == m_download.get_hash(); }
|
||||
|
||||
void receive_finished();
|
||||
|
||||
private:
|
||||
void receive_tracker_msg(std::string msg);
|
||||
void receive_storage_error(std::string msg);
|
||||
@@ -63,6 +73,9 @@ private:
|
||||
|
||||
std::string m_message;
|
||||
|
||||
std::string m_connectionLeech;
|
||||
std::string m_connectionSeed;
|
||||
|
||||
sigc::connection m_connTrackerSucceded;
|
||||
sigc::connection m_connTrackerFailed;
|
||||
sigc::connection m_connStorageError;
|
||||
|
||||
@@ -50,6 +50,9 @@ public:
|
||||
using Base::empty;
|
||||
using Base::size;
|
||||
|
||||
HttpQueue() {}
|
||||
~HttpQueue() { clear(); }
|
||||
|
||||
// Note that any slots connected to the CurlGet signals must be
|
||||
// pushed in front of the erase slot added by HttpQueue::insert.
|
||||
iterator insert(const std::string& url);
|
||||
|
||||
+6
-5
@@ -69,13 +69,14 @@ Manager::initialize() {
|
||||
m_downloadList.slot_map_close().insert("1_download_close", sigc::mem_fun(&Download::call<void, &torrent::Download::close>));
|
||||
m_downloadList.slot_map_close().insert("1_hash_queue_remove", sigc::mem_fun(m_hashQueue, &HashQueue::remove));
|
||||
|
||||
m_downloadList.slot_map_start().insert("1_download_start", sigc::mem_fun(&Download::call<void, &torrent::Download::start>));
|
||||
m_downloadList.slot_map_start().insert("1_download_start", sigc::mem_fun(&Download::start));
|
||||
|
||||
m_downloadList.slot_map_stop().insert("1_download_stop", sigc::mem_fun(&Download::call<void, &torrent::Download::stop>));
|
||||
m_downloadList.slot_map_stop().insert("2_hash_resume_save", sigc::mem_fun(&Download::call<void, &torrent::Download::hash_resume_save>));
|
||||
m_downloadList.slot_map_stop().insert("3_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
|
||||
|
||||
m_downloadList.slot_map_finished().insert("1_download_done", sigc::bind(sigc::mem_fun(*this, &Manager::receive_download_done), false));
|
||||
m_downloadList.slot_map_finished().insert("2_receive_finished", sigc::mem_fun(&Download::receive_finished));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -84,7 +85,7 @@ Manager::cleanup() {
|
||||
// any more.
|
||||
|
||||
torrent::cleanup();
|
||||
core::CurlStack::cleanup();
|
||||
CurlStack::cleanup();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -207,11 +208,11 @@ Manager::listen_open() {
|
||||
|
||||
void
|
||||
Manager::create_http(const std::string& uri) {
|
||||
core::HttpQueue::iterator itr = m_httpQueue.insert(uri);
|
||||
HttpQueue::iterator itr = m_httpQueue.insert(uri);
|
||||
|
||||
(*itr)->signal_done().slots().push_front(sigc::bind(sigc::mem_fun(*this, &core::Manager::create_final),
|
||||
(*itr)->signal_done().slots().push_front(sigc::bind(sigc::mem_fun(*this, &Manager::create_final),
|
||||
(*itr)->get_stream()));
|
||||
(*itr)->signal_failed().slots().push_front(sigc::mem_fun(*this, &core::Manager::receive_http_failed));
|
||||
(*itr)->signal_failed().slots().push_front(sigc::mem_fun(*this, &Manager::receive_http_failed));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+5
-2
@@ -135,6 +135,9 @@ initialize_option_handler(ui::Control* c, OptionHandler* optionHandler) {
|
||||
optionHandler->insert("max_open_files", new OptionHandlerInt(c, &apply_max_open_files, &validate_fd));
|
||||
optionHandler->insert("throttle_interval", new OptionHandlerInt(c, &apply_throttle_interval, &validate_throttle_interval));
|
||||
|
||||
optionHandler->insert("connection_leech", new OptionHandlerString(c, &apply_connection_leech, &validate_non_empty));
|
||||
optionHandler->insert("connection_seed", new OptionHandlerString(c, &apply_connection_seed, &validate_non_empty));
|
||||
|
||||
optionHandler->insert("session", new OptionHandlerString(c, &apply_session_directory, &validate_directory));
|
||||
optionHandler->insert("tracker_dump", new OptionHandlerString(c, &apply_tracker_dump, &validate_yes_no));
|
||||
}
|
||||
@@ -183,11 +186,11 @@ initialize_core(ui::Control* c) {
|
||||
|
||||
int
|
||||
main(int argc, char** argv) {
|
||||
utils::Timer::update();
|
||||
|
||||
OptionHandler optionHandler;
|
||||
ui::Control uiControl;
|
||||
|
||||
utils::Timer::update();
|
||||
|
||||
srandom(utils::Timer::cache().usec());
|
||||
srand48(utils::Timer::cache().usec());
|
||||
|
||||
|
||||
@@ -54,6 +54,9 @@ public:
|
||||
|
||||
using Base::find;
|
||||
|
||||
OptionHandler() {}
|
||||
~OptionHandler() { clear(); }
|
||||
|
||||
// We take over ownership of opt.
|
||||
void insert(const std::string& key, OptionHandlerBase* opt);
|
||||
void erase(const std::string& key);
|
||||
|
||||
@@ -60,6 +60,11 @@ validate_yes_no(const std::string& arg) {
|
||||
return arg == "yes" || arg == "no";
|
||||
}
|
||||
|
||||
bool
|
||||
validate_non_empty(const std::string& arg) {
|
||||
return !arg.empty();
|
||||
}
|
||||
|
||||
bool
|
||||
validate_download_peers(int arg) {
|
||||
return arg > 0 && arg < (1 << 16);
|
||||
@@ -118,6 +123,16 @@ apply_download_directory(ui::Control* m, const std::string& arg) {
|
||||
m->get_core().get_download_list().slot_map_insert().erase("1_directory");
|
||||
}
|
||||
|
||||
void
|
||||
apply_connection_leech(ui::Control* m, const std::string& arg) {
|
||||
m->get_core().get_download_list().slot_map_insert().insert("1_connection_leech", sigc::bind(sigc::mem_fun(&core::Download::set_connection_leech), arg));
|
||||
}
|
||||
|
||||
void
|
||||
apply_connection_seed(ui::Control* m, const std::string& arg) {
|
||||
m->get_core().get_download_list().slot_map_insert().insert("1_connection_seed", sigc::bind(sigc::mem_fun(&core::Download::set_connection_seed), arg));
|
||||
}
|
||||
|
||||
void
|
||||
apply_global_download_rate(ui::Control* m, int arg) {
|
||||
torrent::set_read_throttle(arg * 1024);
|
||||
|
||||
@@ -38,6 +38,7 @@ bool validate_ip(const std::string& arg);
|
||||
bool validate_directory(const std::string& arg);
|
||||
bool validate_port_range(const std::string& arg);
|
||||
bool validate_yes_no(const std::string& arg);
|
||||
bool validate_non_empty(const std::string& arg);
|
||||
|
||||
bool validate_download_peers(int arg);
|
||||
bool validate_rate(int arg);
|
||||
@@ -51,9 +52,11 @@ bool validate_throttle_interval(int arg);
|
||||
void apply_download_min_peers(ui::Control* m, int arg);
|
||||
void apply_download_max_peers(ui::Control* m, int arg);
|
||||
void apply_download_max_uploads(ui::Control* m, int arg);
|
||||
|
||||
void apply_download_directory(ui::Control* m, const std::string& arg);
|
||||
|
||||
void apply_connection_leech(ui::Control* m, const std::string& arg);
|
||||
void apply_connection_seed(ui::Control* m, const std::string& arg);
|
||||
|
||||
void apply_global_download_rate(ui::Control* m, int arg);
|
||||
void apply_global_upload_rate(ui::Control* m, int arg);
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ public:
|
||||
typedef sigc::slot2<void, const std::string&, const std::string&> SlotStringPair;
|
||||
typedef sigc::slot2<void, int, int> SlotIntPair;
|
||||
|
||||
OptionParser() {}
|
||||
~OptionParser() { m_container.clear(); }
|
||||
|
||||
void insert_flag(char c, Slot s);
|
||||
void insert_option(char c, SlotString s);
|
||||
void insert_option_list(char c, SlotStringPair s);
|
||||
|
||||
Reference in New Issue
Block a user