mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-08 23:29:21 +00:00
* Minor cleanup in rtorrent.
* Changing priorities of closed torrents caused a crash due to empty ChunkSelector, fixed. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@615 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -87,6 +87,7 @@ Control::initialize() {
|
||||
m_core->get_poll_manager()->get_http_stack()->set_user_agent(std::string(PACKAGE "/" VERSION "/") + torrent::version());
|
||||
|
||||
m_core->initialize_second();
|
||||
m_core->listen_open();
|
||||
|
||||
m_ui->init(this);
|
||||
|
||||
|
||||
+20
-24
@@ -46,10 +46,29 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
Download::Download() :
|
||||
Download::Download(torrent::Download d) :
|
||||
m_download(d),
|
||||
|
||||
m_chunksFailed(0),
|
||||
m_connectionLeech(torrent::Download::CONNECTION_LEECH),
|
||||
m_connectionSeed(torrent::Download::CONNECTION_SEED) {
|
||||
|
||||
m_connTrackerSucceded = m_download.signal_tracker_succeded(sigc::bind(sigc::mem_fun(*this, &Download::receive_tracker_msg), ""));
|
||||
m_connTrackerFailed = m_download.signal_tracker_failed(sigc::mem_fun(*this, &Download::receive_tracker_msg));
|
||||
m_connStorageError = m_download.signal_storage_error(sigc::mem_fun(*this, &Download::receive_storage_error));
|
||||
|
||||
m_download.signal_chunk_failed(sigc::mem_fun(*this, &Download::receive_chunk_failed));
|
||||
}
|
||||
|
||||
Download::~Download() {
|
||||
if (!m_download.is_valid())
|
||||
return;
|
||||
|
||||
m_connTrackerSucceded.disconnect();
|
||||
m_connTrackerFailed.disconnect();
|
||||
m_connStorageError.disconnect();
|
||||
|
||||
m_download = torrent::Download();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -65,17 +84,6 @@ Download::start() {
|
||||
m_download.start();
|
||||
}
|
||||
|
||||
void
|
||||
Download::set_download(torrent::Download d) {
|
||||
m_download = d;
|
||||
|
||||
m_connTrackerSucceded = m_download.signal_tracker_succeded(sigc::bind(sigc::mem_fun(*this, &Download::receive_tracker_msg), ""));
|
||||
m_connTrackerFailed = m_download.signal_tracker_failed(sigc::mem_fun(*this, &Download::receive_tracker_msg));
|
||||
m_connStorageError = m_download.signal_storage_error(sigc::mem_fun(*this, &Download::receive_storage_error));
|
||||
|
||||
m_download.signal_chunk_failed(sigc::mem_fun(*this, &Download::receive_chunk_failed));
|
||||
}
|
||||
|
||||
void
|
||||
Download::set_root_directory(const std::string& d) {
|
||||
m_download.set_root_dir(d +
|
||||
@@ -93,18 +101,6 @@ Download::enable_udp_trackers(bool state) {
|
||||
m_download.tracker(i).disable();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
+2
-5
@@ -47,17 +47,14 @@ class Download {
|
||||
public:
|
||||
typedef torrent::Download::ConnectionType ConnType;
|
||||
|
||||
Download();
|
||||
~Download() { release_download(); }
|
||||
Download(torrent::Download d);
|
||||
~Download();
|
||||
|
||||
bool is_open() { return m_download.is_open(); }
|
||||
inline bool is_done();
|
||||
|
||||
void start();
|
||||
|
||||
void set_download(torrent::Download d);
|
||||
void release_download();
|
||||
|
||||
torrent::Download& get_download() { return m_download; }
|
||||
const torrent::Download& get_download() const { return m_download; }
|
||||
std::string get_hash() { return m_download.info_hash(); }
|
||||
|
||||
@@ -51,8 +51,7 @@ DownloadList::iterator
|
||||
DownloadList::insert(std::istream* str) {
|
||||
torrent::Download d = torrent::download_add(str);
|
||||
|
||||
iterator itr = Base::insert(end(), new Download);
|
||||
(*itr)->set_download(d);
|
||||
iterator itr = Base::insert(end(), new Download(d));
|
||||
(*itr)->get_download().signal_download_done(sigc::bind(sigc::mem_fun(*this, &DownloadList::finished), *itr));
|
||||
|
||||
m_slotMapInsert.for_each(*itr);
|
||||
@@ -65,7 +64,6 @@ DownloadList::erase(iterator itr) {
|
||||
m_slotMapErase.for_each(*itr);
|
||||
|
||||
torrent::download_remove((*itr)->get_download());
|
||||
(*itr)->release_download();
|
||||
delete *itr;
|
||||
|
||||
return Base::erase(itr);
|
||||
|
||||
@@ -98,7 +98,6 @@ Manager::initialize_second() {
|
||||
m_httpQueue.slot_factory(m_pollManager->get_http_stack()->get_http_factory());
|
||||
|
||||
CurlStack::global_init();
|
||||
listen_open();
|
||||
|
||||
// Register slots to be called when a download is inserted/erased,
|
||||
// opened or closed.
|
||||
|
||||
+26
-27
@@ -66,21 +66,21 @@ print_hhmmss(char* buf, unsigned int length, time_t t) {
|
||||
if (u == NULL)
|
||||
return "inv_time";
|
||||
|
||||
unsigned int s = snprintf(buf, length, "%2u:%02u:%02u", u->tm_hour, u->tm_min, u->tm_sec);
|
||||
int s = snprintf(buf, length, "%2u:%02u:%02u", u->tm_hour, u->tm_min, u->tm_sec);
|
||||
|
||||
return buf + std::min(s, length);
|
||||
return buf + std::max(s, 0);
|
||||
}
|
||||
|
||||
char*
|
||||
print_ddhhmm(char* buf, unsigned int length, time_t t) {
|
||||
unsigned int s;
|
||||
int s;
|
||||
|
||||
if (t / (24 * 3600) < 100)
|
||||
s = snprintf(buf, length, "%2i:%02i:%02i", (int)t / (24 * 3600), ((int)t / 3600) % 24, ((int)t / 60) % 60);
|
||||
else
|
||||
s = snprintf(buf, length, "--:--:--");
|
||||
|
||||
return buf + std::min(s, length);
|
||||
return buf + std::max(s, 0);
|
||||
}
|
||||
|
||||
char*
|
||||
@@ -90,37 +90,36 @@ print_ddmmyyyy(char* buf, unsigned int length, time_t t) {
|
||||
if (u == NULL)
|
||||
return "inv_time";
|
||||
|
||||
unsigned int s = snprintf(buf, length, "%02u/%02u/%04u", u->tm_mday, (u->tm_mon + 1), (1900 + u->tm_year));
|
||||
int s = snprintf(buf, length, "%02u/%02u/%04u", u->tm_mday, (u->tm_mon + 1), (1900 + u->tm_year));
|
||||
|
||||
return buf + std::min(s, length);
|
||||
return buf + std::max(s, 0);
|
||||
}
|
||||
|
||||
char*
|
||||
print_download_title(char* buf, unsigned int length, core::Download* d) {
|
||||
return buf + std::max(0, snprintf(buf, length, "%s",
|
||||
d->get_download().name().c_str()));
|
||||
return buf + std::max(snprintf(buf, length, "%s", d->get_download().name().c_str()), 0);
|
||||
}
|
||||
|
||||
char*
|
||||
print_download_info(char* buf, unsigned int length, core::Download* d) {
|
||||
char* last = buf + length;
|
||||
|
||||
buf += std::max(0, snprintf(buf, last - buf, "Torrent: "));
|
||||
buf += std::max(snprintf(buf, last - buf, "Torrent: "), 0);
|
||||
|
||||
if (!d->get_download().is_open())
|
||||
buf += std::max(0, snprintf(buf, last - buf, "closed "));
|
||||
buf += std::max(snprintf(buf, last - buf, "closed "), 0);
|
||||
else if (d->is_done())
|
||||
buf += std::max(0, snprintf(buf, last - buf, "done %10.1f MB",
|
||||
(double)d->get_download().bytes_total() / (double)(1 << 20)));
|
||||
buf += std::max(snprintf(buf, last - buf, "done %10.1f MB",
|
||||
(double)d->get_download().bytes_total() / (double)(1 << 20)), 0);
|
||||
else
|
||||
buf += std::max(0, snprintf(buf, last - buf, "%6.1f / %6.1f MB",
|
||||
(double)d->get_download().bytes_done() / (double)(1 << 20),
|
||||
(double)d->get_download().bytes_total() / (double)(1 << 20)));
|
||||
buf += std::max(snprintf(buf, last - buf, "%6.1f / %6.1f MB",
|
||||
(double)d->get_download().bytes_done() / (double)(1 << 20),
|
||||
(double)d->get_download().bytes_total() / (double)(1 << 20)), 0);
|
||||
|
||||
buf += std::max(0, snprintf(buf, last - buf, " Rate: %5.1f / %5.1f KB Uploaded: %7.1f MB ",
|
||||
(double)d->get_download().up_rate()->rate() / (1 << 10),
|
||||
(double)d->get_download().down_rate()->rate() / (1 << 10),
|
||||
(double)d->get_download().up_rate()->total() / (1 << 20)));
|
||||
buf += std::max(snprintf(buf, last - buf, " Rate: %5.1f / %5.1f KB Uploaded: %7.1f MB ",
|
||||
(double)d->get_download().up_rate()->rate() / (1 << 10),
|
||||
(double)d->get_download().down_rate()->rate() / (1 << 10),
|
||||
(double)d->get_download().up_rate()->total() / (1 << 20)), 0);
|
||||
|
||||
//buf += std::max(0, snprintf(buf, length, " Left: "));
|
||||
buf = print_download_time_left(buf, length, d);
|
||||
@@ -131,21 +130,21 @@ print_download_info(char* buf, unsigned int length, core::Download* d) {
|
||||
char*
|
||||
print_download_status(char* buf, unsigned int length, core::Download* d) {
|
||||
if (!d->get_download().is_active())
|
||||
buf += std::max(0, snprintf(buf, length, "Inactive: "));
|
||||
buf += std::max(snprintf(buf, length, "Inactive: "), 0);
|
||||
|
||||
if (d->get_download().is_hash_checking())
|
||||
buf += std::max(0, snprintf(buf, length, "Checking hash [%2i%%]",
|
||||
(d->get_download().chunks_hashed() * 100) / d->get_download().chunks_total()));
|
||||
buf += std::max(snprintf(buf, length, "Checking hash [%2i%%]",
|
||||
(d->get_download().chunks_hashed() * 100) / d->get_download().chunks_total()), 0);
|
||||
|
||||
else if (d->get_download().is_tracker_busy() &&
|
||||
d->get_download().tracker_focus() < d->get_download().size_trackers())
|
||||
buf += std::max(0, snprintf(buf, length, "Tracker[%i:%i]: Connecting to %s",
|
||||
d->get_download().tracker(d->get_download().tracker_focus()).group(),
|
||||
d->get_download().tracker_focus(),
|
||||
d->get_download().tracker(d->get_download().tracker_focus()).url().c_str()));
|
||||
buf += std::max(snprintf(buf, length, "Tracker[%i:%i]: Connecting to %s",
|
||||
d->get_download().tracker(d->get_download().tracker_focus()).group(),
|
||||
d->get_download().tracker_focus(),
|
||||
d->get_download().tracker(d->get_download().tracker_focus()).url().c_str()), 0);
|
||||
|
||||
else if (!d->get_message().empty())
|
||||
buf += std::max(0, snprintf(buf, length, "%s", d->get_message().c_str()));
|
||||
buf += std::max(snprintf(buf, length, "%s", d->get_message().c_str()), 0);
|
||||
|
||||
else
|
||||
buf[0] = '\0';
|
||||
|
||||
@@ -158,15 +158,14 @@ apply_max_open_sockets(Control* m, int arg) {
|
||||
|
||||
void
|
||||
apply_bind(Control* m, const std::string& arg) {
|
||||
bool reopenListen = torrent::listen_port();
|
||||
|
||||
if (reopenListen)
|
||||
if (torrent::listen_port() != 0) {
|
||||
torrent::listen_close();
|
||||
|
||||
torrent::set_bind_address(arg);
|
||||
|
||||
if (reopenListen)
|
||||
torrent::set_bind_address(arg);
|
||||
m->core()->listen_open();
|
||||
|
||||
} else {
|
||||
torrent::set_bind_address(arg);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user