* Saves file priorities along with fast-resume data.

* Cleaned up the shutdown code, moved some unnessesary stuff out of
the main loop.

* Made a TrackerBase and an empty TrackerUdp class. The proper
Tracker* class is selected based on the url.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@492 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-07-09 18:28:57 +00:00
parent 26a7907f0a
commit 8ca61a79ac
8 changed files with 80 additions and 39 deletions
+2
View File
@@ -147,6 +147,8 @@ DownloadFactory::receive_success() {
} else {
if (m_start)
m_manager->start(*itr);
m_manager->get_download_store().save(*itr);
}
m_slotFinished();
+9 -11
View File
@@ -69,7 +69,7 @@ Manager::initialize() {
// opened or closed.
m_downloadList.slot_map_insert().insert("0_initialize_bencode", sigc::mem_fun(*this, &Manager::initialize_bencode));
m_downloadList.slot_map_insert().insert("1_connect_network_log", sigc::bind(sigc::ptr_fun(&connect_signal_network_log), sigc::mem_fun(m_logComplete, &Log::push_front)));
m_downloadList.slot_map_insert().insert("4_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
//m_downloadList.slot_map_insert().insert("4_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save));
m_downloadList.slot_map_erase().insert("1_hash_queue_remove", sigc::mem_fun(m_hashQueue, &HashQueue::remove));
m_downloadList.slot_map_erase().insert("1_store_remove", sigc::mem_fun(m_downloadStore, &DownloadStore::remove));
@@ -149,7 +149,7 @@ Manager::start(Download* d) {
if (d->get_download().is_hash_checked())
m_downloadList.start(d);
else
// This can cause infinit loops.
// This can cause infinit loops?
m_hashQueue.insert(d, sigc::bind(sigc::mem_fun(m_downloadList, &DownloadList::start), d));
} catch (torrent::local_error& e) {
@@ -226,15 +226,13 @@ void
Manager::initialize_bencode(Download* d) {
torrent::Bencode& bencode = d->get_bencode();
// TODO: Check that stuff are the right type, like state etc.
if (bencode.has_key("rtorrent") &&
bencode["rtorrent"].is_map() &&
bencode["rtorrent"].has_key("state") &&
bencode["rtorrent"]["state"].is_string())
return;
bencode.insert_key("rtorrent", torrent::Bencode(torrent::Bencode::TYPE_MAP));
bencode["rtorrent"].insert_key("state", "started");
if (!bencode.has_key("rtorrent") ||
!bencode["rtorrent"].is_map())
bencode.insert_key("rtorrent", torrent::Bencode(torrent::Bencode::TYPE_MAP));
if (!bencode["rtorrent"].has_key("state") ||
!bencode["rtorrent"]["state"].is_string())
bencode["rtorrent"].insert_key("state", "started");
}
void
+3 -25
View File
@@ -72,8 +72,6 @@
int64_t utils::Timer::m_cache;
bool is_shutting_down = false;
void do_panic(int signum);
void print_help();
@@ -95,21 +93,6 @@ is_resized() {
return r;
}
void
do_shutdown(ui::Control* c) {
if (!is_shutting_down) {
is_shutting_down = true;
torrent::listen_close();
c->get_core().shutdown(false);
} else {
// Close all torrents, this will stop all tracker connections and cause
// a quick shutdown.
c->get_core().shutdown(true);
}
}
int
parse_options(ui::Control* c, OptionHandler* optionHandler, int argc, char** argv) {
OptionParser optionParser;
@@ -233,7 +216,7 @@ main(int argc, char** argv) {
try {
SignalHandler::set_ignore(SIGPIPE);
SignalHandler::set_handler(SIGINT, sigc::bind(sigc::mem_fun(uiControl, &ui::Control::set_shutdown_received), true));
SignalHandler::set_handler(SIGINT, sigc::mem_fun(uiControl, &ui::Control::receive_shutdown));
SignalHandler::set_handler(SIGSEGV, sigc::bind(sigc::ptr_fun(&do_panic), SIGSEGV));
SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS));
SignalHandler::set_handler(SIGFPE, sigc::bind(sigc::ptr_fun(&do_panic), SIGFPE));
@@ -256,13 +239,7 @@ main(int argc, char** argv) {
uiControl.get_display().adjust_layout();
while (!is_shutting_down || !torrent::is_inactive()) {
if (uiControl.get_shutdown_received()) {
do_shutdown(&uiControl);
uiControl.set_shutdown_received(false);
}
while (!uiControl.is_shutdown_completed()) {
utils::Timer::update();
utils::taskScheduler.execute(utils::Timer::cache());
@@ -272,6 +249,7 @@ main(int argc, char** argv) {
utils::displayScheduler.get_next_timeout() <= utils::Timer::cache())
uiControl.get_display().do_update();
// Do shutdown check before poll, not after.
uiControl.get_core().get_poll().poll(!utils::taskScheduler.empty() ?
utils::taskScheduler.get_next_timeout() - utils::Timer::cache() :
60 * 1000000);
+1
View File
@@ -1,6 +1,7 @@
noinst_LIBRARIES = libsub_ui.a
libsub_ui_a_SOURCES = \
control.cc \
control.h \
download.cc \
download.h \
+54
View File
@@ -0,0 +1,54 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include "control.h"
namespace ui {
// I think it should be safe to initiate the shutdown from anywhere,
// but if it isn't, use a delay task.
void
Control::receive_shutdown() {
if (!m_shutdownReceived)
torrent::listen_close();
m_core.shutdown(m_shutdownReceived);
m_shutdownReceived = true;
}
}
+6 -2
View File
@@ -37,6 +37,8 @@
#ifndef RTORRENT_UI_CONTROL_H
#define RTORRENT_UI_CONTROL_H
#include <torrent/torrent.h>
#include "core/manager.h"
#include "display/manager.h"
#include "input/manager.h"
@@ -49,14 +51,16 @@ class Control {
public:
Control() : m_shutdownReceived(false) {}
bool get_shutdown_received() { return m_shutdownReceived; }
void set_shutdown_received(bool v) { m_shutdownReceived = v; }
bool is_shutdown_completed() { return m_shutdownReceived && torrent::is_inactive(); }
bool is_shutdown_received() { return m_shutdownReceived; }
Root& get_ui() { return m_ui; }
core::Manager& get_core() { return m_core; }
display::Manager& get_display() { return m_display; }
input::Manager& get_input() { return m_input; }
void receive_shutdown();
private:
Control(const Control&);
void operator = (const Control&);
+4
View File
@@ -275,6 +275,10 @@ DownloadList::receive_exit_input(bool useDefault) {
m_bindings->erase('\n');
m_bindings->erase(KEY_ENTER);
// Urgh... this is ugly...
(*m_bindings)['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), false);
(*m_bindings)[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), false);
receive_change(DISPLAY_DOWNLOAD_LIST);
}
+1 -1
View File
@@ -107,7 +107,7 @@ Root::setup_keys() {
m_bindings['C'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_read_throttle), -50);
m_bindings[KEY_RESIZE] = sigc::mem_fun(m_control->get_display(), &display::Manager::adjust_layout);
m_bindings['\x11'] = sigc::bind(sigc::mem_fun(*m_control, &Control::set_shutdown_received), true);
m_bindings['\x11'] = sigc::mem_fun(*m_control, &Control::receive_shutdown);
}
void