mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-07 14:49:21 +00:00
Cleaned up configure.ac and fixed it to properly handles CXXFLAGS.
Ignore SIGPIPE. Fixed(?) bug in hash queue code when a queued torrent got deleted. Also reorganized core::Manager to catch all torrent::local_error's. Fixed display bug in display::FileList which hid the last element. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@441 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+21
-10
@@ -34,12 +34,10 @@ namespace core {
|
||||
|
||||
void
|
||||
HashQueue::insert(Download* d, Slot s) {
|
||||
if (d->get_download().is_hash_checking())
|
||||
if (d->get_download().is_hash_checking() ||
|
||||
find(d) != end())
|
||||
return;
|
||||
|
||||
if (std::find_if(begin(), end(), rak::equal(d, std::mem_fun(&HashQueueNode::get_download))) != end())
|
||||
throw std::logic_error("core::HashQueue::insert(...) received a Download that is already queued");
|
||||
|
||||
if (d->get_download().is_hash_checked()) {
|
||||
s();
|
||||
return;
|
||||
@@ -47,21 +45,23 @@ HashQueue::insert(Download* d, Slot s) {
|
||||
|
||||
iterator itr = Base::insert(end(), new HashQueueNode(d, s));
|
||||
|
||||
(*itr)->set_connection(d->get_download().signal_hash_done(sigc::bind(sigc::mem_fun(*this, &HashQueue::receive_hash_done), itr)));
|
||||
(*itr)->set_connection(d->get_download().signal_hash_done(sigc::bind(sigc::mem_fun(*this, &HashQueue::receive_hash_done),
|
||||
(*itr)->get_download())));
|
||||
|
||||
fill_queue();
|
||||
}
|
||||
|
||||
void
|
||||
HashQueue::remove(Download* d) {
|
||||
iterator itr = std::find_if(begin(), end(), rak::equal(d, std::mem_fun(&HashQueueNode::get_download)));
|
||||
iterator itr = find(d);
|
||||
|
||||
if (itr == end())
|
||||
return;
|
||||
|
||||
if ((*itr)->get_download()->get_download().is_hash_checking())
|
||||
// What do we do if we're already checking?
|
||||
;
|
||||
// We don't do anything if we're already checking, just disconnect.
|
||||
// if ((*itr)->get_download()->get_download().is_hash_checking()) {
|
||||
// // What do we do if we're already checking?
|
||||
// }
|
||||
|
||||
delete *itr;
|
||||
Base::erase(itr);
|
||||
@@ -69,13 +69,24 @@ HashQueue::remove(Download* d) {
|
||||
fill_queue();
|
||||
}
|
||||
|
||||
HashQueue::iterator
|
||||
HashQueue::find(Download* d) {
|
||||
return std::find_if(begin(), end(), rak::equal(d, std::mem_fun(&HashQueueNode::get_download)));
|
||||
}
|
||||
|
||||
void
|
||||
HashQueue::receive_hash_done(Base::iterator itr) {
|
||||
HashQueue::receive_hash_done(Download* d) {
|
||||
iterator itr = find(d);
|
||||
|
||||
if (itr == end())
|
||||
return;
|
||||
|
||||
Slot s = (*itr)->get_slot();
|
||||
|
||||
delete *itr;
|
||||
Base::erase(itr);
|
||||
|
||||
// Can we call this before the delete?
|
||||
s();
|
||||
fill_queue();
|
||||
}
|
||||
|
||||
@@ -54,14 +54,16 @@ public:
|
||||
using Base::empty;
|
||||
using Base::size;
|
||||
|
||||
// Should it be safe to try inserting already present/checked downloads?
|
||||
void insert(Download* d, Slot s);
|
||||
|
||||
// It's safe to try to remove downloads not in the queue.
|
||||
// It's safe to try to remove downloads not in the queue. The hash
|
||||
// checking is not stopped if it has already started.
|
||||
void remove(Download* d);
|
||||
|
||||
iterator find(Download* d);
|
||||
|
||||
private:
|
||||
void receive_hash_done(Base::iterator itr);
|
||||
void receive_hash_done(Download* d);
|
||||
|
||||
void fill_queue();
|
||||
};
|
||||
@@ -69,7 +71,9 @@ private:
|
||||
class HashQueueNode {
|
||||
public:
|
||||
HashQueueNode(Download* d, HashQueue::Slot s) : m_download(d), m_slot(s) {}
|
||||
~HashQueueNode() { m_connection.disconnect(); }
|
||||
~HashQueueNode() { disconnect(); }
|
||||
|
||||
void disconnect() { m_connection.disconnect(); }
|
||||
|
||||
Download* get_download() { return m_download; }
|
||||
HashQueue::Slot get_slot() { return m_slot; }
|
||||
|
||||
+55
-57
@@ -80,6 +80,7 @@ Manager::erase(DownloadList::iterator itr) {
|
||||
if (!(*itr)->get_download().is_open())
|
||||
throw std::logic_error("core::Manager::erase(...) called on an closed download");
|
||||
|
||||
m_hashQueue.remove(*itr);
|
||||
m_downloadStore.remove(*itr);
|
||||
|
||||
return m_downloadList.erase(itr);
|
||||
@@ -87,35 +88,36 @@ Manager::erase(DownloadList::iterator itr) {
|
||||
|
||||
void
|
||||
Manager::start(Download* d) {
|
||||
if (d->get_download().is_active())
|
||||
return;
|
||||
try {
|
||||
if (d->get_download().is_active())
|
||||
return;
|
||||
|
||||
if (!d->get_download().is_open())
|
||||
d->open();
|
||||
if (!d->get_download().is_open())
|
||||
d->open();
|
||||
|
||||
if (d->get_download().is_hash_checked())
|
||||
d->start();
|
||||
else
|
||||
// This can cause infinit loops.
|
||||
m_hashQueue.insert(d, sigc::mem_fun(d, &Download::start));
|
||||
if (d->get_download().is_hash_checked())
|
||||
d->start();
|
||||
else
|
||||
// This can cause infinit loops.
|
||||
m_hashQueue.insert(d, sigc::mem_fun(d, &Download::start));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
m_logImportant.push_front(e.what());
|
||||
m_logComplete.push_front(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Manager::stop(Download* d) {
|
||||
m_hashQueue.remove(d);
|
||||
|
||||
d->stop();
|
||||
|
||||
if (d->get_download().is_hash_checked())
|
||||
d->get_download().hash_save();
|
||||
|
||||
m_downloadStore.save(d);
|
||||
}
|
||||
|
||||
void
|
||||
Manager::start_safe(Download* d) {
|
||||
try {
|
||||
start(d);
|
||||
m_hashQueue.remove(d);
|
||||
d->stop();
|
||||
|
||||
if (d->get_download().is_hash_checked())
|
||||
d->get_download().hash_save();
|
||||
|
||||
m_downloadStore.save(d);
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
m_logImportant.push_front(e.what());
|
||||
m_logComplete.push_front(e.what());
|
||||
@@ -124,6 +126,7 @@ Manager::start_safe(Download* d) {
|
||||
|
||||
void
|
||||
Manager::set_dns(const std::string& dns) {
|
||||
// TODO: Switch with the inet version of this thingie.
|
||||
unsigned int a, b, c, d;
|
||||
|
||||
if (std::sscanf(dns.c_str(), "%i.%i.%i.%i", &a, &b, &c, &d) != 4 ||
|
||||
@@ -136,18 +139,6 @@ Manager::set_dns(const std::string& dns) {
|
||||
m_dns = str.str();
|
||||
}
|
||||
|
||||
void
|
||||
Manager::receive_http_done(CurlGet* http) {
|
||||
try {
|
||||
create_final(http->get_stream());
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
// What to do? Keep in list for now.
|
||||
m_logImportant.push_front(e.what());
|
||||
m_logComplete.push_front(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Manager::receive_http_failed(std::string msg) {
|
||||
m_logImportant.push_front("Http download error: \"" + msg + "\"");
|
||||
@@ -156,10 +147,29 @@ Manager::receive_http_failed(std::string msg) {
|
||||
|
||||
void
|
||||
Manager::create_file(const std::string& uri) {
|
||||
std::fstream f(uri.c_str(), std::ios::in);
|
||||
|
||||
create_final(&f);
|
||||
}
|
||||
|
||||
void
|
||||
Manager::create_http(const std::string& uri) {
|
||||
core::HttpQueue::iterator itr = m_httpQueue.insert(uri);
|
||||
|
||||
(*itr)->signal_done().slots().push_front(sigc::bind(sigc::mem_fun(*this, &core::Manager::create_final),
|
||||
(*itr)->get_stream()));
|
||||
(*itr)->signal_failed().slots().push_front(sigc::mem_fun(*this, &core::Manager::receive_http_failed));
|
||||
}
|
||||
|
||||
void
|
||||
Manager::create_final(std::istream* s) {
|
||||
try {
|
||||
std::fstream f(uri.c_str(), std::ios::in);
|
||||
|
||||
create_final(&f);
|
||||
iterator itr = m_downloadList.insert(s);
|
||||
|
||||
setup_download(*itr);
|
||||
start(*itr);
|
||||
|
||||
m_downloadStore.save(*itr);
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
// What to do? Keep in list for now.
|
||||
@@ -169,32 +179,20 @@ Manager::create_file(const std::string& uri) {
|
||||
}
|
||||
|
||||
void
|
||||
Manager::create_http(const std::string& uri) {
|
||||
core::HttpQueue::iterator itr = m_httpQueue.insert(uri);
|
||||
|
||||
(*itr)->signal_done().slots().push_front(sigc::bind(sigc::mem_fun(*this, &core::Manager::receive_http_done), *itr));
|
||||
(*itr)->signal_failed().slots().push_front(sigc::mem_fun(*this, &core::Manager::receive_http_failed));
|
||||
}
|
||||
|
||||
Manager::iterator
|
||||
Manager::create_final(std::istream* s) {
|
||||
iterator itr = m_downloadList.insert(s);
|
||||
|
||||
(*itr)->get_download().set_ip(m_dns);
|
||||
Manager::setup_download(Download* d) {
|
||||
d->get_download().set_ip(m_dns);
|
||||
|
||||
if (!m_defaultRoot.empty())
|
||||
(*itr)->get_download().set_root_dir(m_defaultRoot + ((*itr)->get_download().get_entry_size() > 1 ? (*itr)->get_download().get_name() : ""));
|
||||
|
||||
start(*itr);
|
||||
m_downloadStore.save(*itr);
|
||||
d->get_download().set_root_dir(m_defaultRoot +
|
||||
(d->get_download().get_entry_size() > 1 ?
|
||||
d->get_download().get_name() :
|
||||
""));
|
||||
|
||||
if (m_debugTracker >= 0)
|
||||
(*itr)->get_download().signal_tracker_dump(sigc::mem_fun(*this, &Manager::receive_debug_tracker));
|
||||
d->get_download().signal_tracker_dump(sigc::mem_fun(*this, &Manager::receive_debug_tracker));
|
||||
|
||||
// If we want to monitor network stuff.
|
||||
(*itr)->get_download().signal_network_log(sigc::mem_fun(m_logComplete, &Log::push_front));
|
||||
|
||||
return itr;
|
||||
d->get_download().signal_network_log(sigc::mem_fun(m_logComplete, &Log::push_front));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+3
-4
@@ -64,8 +64,6 @@ public:
|
||||
void start(Download* d);
|
||||
void stop(Download* d);
|
||||
|
||||
void start_safe(Download* d);
|
||||
|
||||
const std::string& get_dns() { return m_dns; }
|
||||
void set_dns(const std::string& dns);
|
||||
|
||||
@@ -77,13 +75,14 @@ public:
|
||||
void debug_tracker() { m_debugTracker = 0; }
|
||||
|
||||
private:
|
||||
void receive_http_done(CurlGet* http);
|
||||
void receive_http_failed(std::string msg);
|
||||
|
||||
void create_file(const std::string& uri);
|
||||
void create_http(const std::string& uri);
|
||||
|
||||
iterator create_final(std::istream* s);
|
||||
void create_final(std::istream* s);
|
||||
|
||||
void setup_download(Download* itr);
|
||||
|
||||
void receive_debug_tracker(std::istream* s);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user