From b3fc488e5f424dd1ca7e2d7a44747b98677dcede Mon Sep 17 00:00:00 2001 From: rakshasa Date: Wed, 19 Jul 2006 00:42:23 +0000 Subject: [PATCH] * Initial work on a global chunk manager for controlling memory usage, and checking if enough disk space is available for MS_ASYNC to be safe. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@743 e378c898-3ddf-0310-93e7-cc216c733640 --- configure.ac | 4 ++-- rak/error_number.h | 1 + rak/fs_stat.h | 4 ++-- scripts/checks.m4 | 3 +++ src/display/client_info.cc | 1 + src/display/window_peer_info.cc | 30 +++++++++++++++--------------- src/option_handler_rules.cc | 10 ++++++++-- 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/configure.ac b/configure.ac index 9faaa034..de8d4287 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.6.0, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.6.1, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) @@ -23,7 +23,7 @@ TORRENT_WITHOUT_NCURSESW() TORRENT_WITHOUT_STATVFS() TORRENT_WITHOUT_STATFS() -PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.10.0, +PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.10.1, CXXFLAGS="$CXXFLAGS $STUFF_CFLAGS $CURL_CFLAGS"; LIBS="$LIBS $STUFF_LIBS $CURL_LIBS") diff --git a/rak/error_number.h b/rak/error_number.h index 2eef3193..400c7989 100644 --- a/rak/error_number.h +++ b/rak/error_number.h @@ -51,6 +51,7 @@ public: static const int e_deadlk = EDEADLK; static const int e_noent = ENOENT; + static const int e_nomem = ENOMEM; static const int e_notdir = ENOTDIR; static const int e_intr = EINTR; diff --git a/rak/fs_stat.h b/rak/fs_stat.h index 44e4978e..04c0b54e 100644 --- a/rak/fs_stat.h +++ b/rak/fs_stat.h @@ -71,9 +71,9 @@ public: bool update(const char* fn) { return FS_STAT_FN; } bool update(const std::string& filename) { return update(filename.c_str()); } - blocksize_type blocksize() { return m_stat.f_bsize; } + blocksize_type blocksize() { return FS_STAT_BLOCK_SIZE; } blockcount_type blocks_avail() { return m_stat.f_bavail; } - int64_t bytes_avail() { return (int64_t) m_stat.f_bsize * m_stat.f_bavail; } + int64_t bytes_avail() { return (int64_t) blocksize() * m_stat.f_bavail; } private: fs_stat_type m_stat; diff --git a/scripts/checks.m4 b/scripts/checks.m4 index 9b575090..a09b4a94 100644 --- a/scripts/checks.m4 +++ b/scripts/checks.m4 @@ -229,6 +229,7 @@ AC_DEFUN([TORRENT_CHECK_STATVFS], [ AC_DEFINE(FS_STAT_STRUCT, [struct statvfs], Type of second argument to statfs function) AC_DEFINE(FS_STAT_SIZE_TYPE, [unsigned long], Type of block size member in stat struct) AC_DEFINE(FS_STAT_COUNT_TYPE, [fsblkcnt_t], Type of block count member in stat struct) + AC_DEFINE(FS_STAT_BLOCK_SIZE, [(m_stat.f_frsize)], Determine the block size) AC_MSG_RESULT(ok) have_stat_vfs=yes ], @@ -265,6 +266,7 @@ AC_DEFUN([TORRENT_CHECK_STATFS], [ AC_DEFINE(FS_STAT_STRUCT, [struct statfs], Type of second argument to statfs function) AC_DEFINE(FS_STAT_SIZE_TYPE, [long], Type of block size member in stat struct) AC_DEFINE(FS_STAT_COUNT_TYPE, [long], Type of block count member in stat struct) + AC_DEFINE(FS_STAT_BLOCK_SIZE, [(m_stat.f_bsize)], Determine the block size) AC_MSG_RESULT(ok) ], [ @@ -278,6 +280,7 @@ AC_DEFUN([TORRENT_DISABLED_STATFS], [ AC_DEFINE(FS_STAT_STRUCT, [struct {blocksize_type f_bsize; blockcount_type f_bavail;}], Type of second argument to statfs function) AC_DEFINE(FS_STAT_SIZE_TYPE, [int], Type of block size member in stat struct) AC_DEFINE(FS_STAT_COUNT_TYPE, [int], Type of block count member in stat struct) + AC_DEFINE(FS_STAT_BLOCK_SIZE, [(4096)], Determine the block size) AC_MSG_RESULT(No filesystem stats available) ]) diff --git a/src/display/client_info.cc b/src/display/client_info.cc index 75057d6e..16a52f10 100644 --- a/src/display/client_info.cc +++ b/src/display/client_info.cc @@ -72,6 +72,7 @@ ClientInfo::ClientInfo() { insert(TYPE_AZUREUS, "CT", "CTorrent"); insert(TYPE_AZUREUS, "MT", "MoonlightTorrent"); insert(TYPE_AZUREUS, "LT", "libtorrent"); + insert(TYPE_AZUREUS, "LP", "Lphant"); insert(TYPE_AZUREUS, "KT", "KTorrent"); insert(TYPE_AZUREUS, "BX", "Bittorrent X"); insert(TYPE_AZUREUS, "TS", "Torrentstorm"); diff --git a/src/display/window_peer_info.cc b/src/display/window_peer_info.cc index bdf7fed0..3efdd502 100644 --- a/src/display/window_peer_info.cc +++ b/src/display/window_peer_info.cc @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include "core/download.h" @@ -73,10 +73,7 @@ WindowPeerInfo::redraw() { m_canvas->print(0, y++, "Hash: %s", rak::transform_hex(d->info_hash()).c_str()); m_canvas->print(0, y++, "Id: %s", rak::copy_escape_html(d->local_id()).c_str()); - m_canvas->print(0, y++, "Chunks: %u / %u * %u", - d->chunks_done(), - d->chunks_total(), - d->chunks_size()); + m_canvas->print(0, y++, "Chunks: %u / %u * %u", d->chunks_done(), d->chunks_total(), d->chunks_size()); y++; @@ -89,9 +86,9 @@ WindowPeerInfo::redraw() { y++; m_canvas->print(0, y++, "Connection Type: %s ( %s / %s )", - m_download->variable()->get("connection_current").as_string().c_str(), - m_download->variable()->get("connection_seed").as_string().c_str(), - m_download->variable()->get("connection_leech").as_string().c_str()); + m_download->variable()->get("connection_current").as_string().c_str(), + m_download->variable()->get("connection_seed").as_string().c_str(), + m_download->variable()->get("connection_leech").as_string().c_str()); m_canvas->print(0, y++, "Priority: %u", torrent::download_priority(*m_download->download())); m_canvas->print(0, y++, "Directory: %s", m_download->variable_string("directory").c_str()); @@ -103,7 +100,10 @@ WindowPeerInfo::redraw() { // m_canvas->print(0, y++, "SndBuf: %u", torrent::connection_manager()->send_buffer_size()); // m_canvas->print(0, y++, "RcvBuf: %u", torrent::connection_manager()->receive_buffer_size()); -// y++; + m_canvas->print(0, y++, "MemUsage: %llu", torrent::chunk_manager()->memory_usage()); + m_canvas->print(0, y++, "MaxMemUsage: %llu", torrent::chunk_manager()->max_memory_usage()); + + y++; if (*m_focus == m_list->end()) { m_canvas->print(0, y++, "No peer in focus"); @@ -114,8 +114,8 @@ WindowPeerInfo::redraw() { m_canvas->print(0, y++, "*** Peer Info ***"); m_canvas->print(0, y++, "IP: %s:%hu", - rak::socket_address::cast_from((*m_focus)->address())->address_str().c_str(), - rak::socket_address::cast_from((*m_focus)->address())->port()); + rak::socket_address::cast_from((*m_focus)->address())->address_str().c_str(), + rak::socket_address::cast_from((*m_focus)->address())->port()); m_canvas->print(0, y++, "ID: %s" , rak::copy_escape_html((*m_focus)->id()).c_str()); @@ -131,10 +131,10 @@ WindowPeerInfo::redraw() { m_canvas->print(0, y++, "Done: %i%", done_percentage(**m_focus)); m_canvas->print(0, y++, "Rate: %5.1f/%5.1f KB Total: %.1f/%.1f MB", - (double)(*m_focus)->up_rate()->rate() / (double)(1 << 10), - (double)(*m_focus)->down_rate()->rate() / (double)(1 << 10), - (double)(*m_focus)->up_rate()->total() / (double)(1 << 20), - (double)(*m_focus)->down_rate()->total() / (double)(1 << 20)); + (double)(*m_focus)->up_rate()->rate() / (double)(1 << 10), + (double)(*m_focus)->down_rate()->rate() / (double)(1 << 10), + (double)(*m_focus)->up_rate()->total() / (double)(1 << 20), + (double)(*m_focus)->down_rate()->total() / (double)(1 << 20)); } int diff --git a/src/option_handler_rules.cc b/src/option_handler_rules.cc index 051402eb..6994b467 100644 --- a/src/option_handler_rules.cc +++ b/src/option_handler_rules.cc @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -213,8 +214,10 @@ apply_stop_on_ratio(Control* m, const std::string& arg) { int64_t totalUpload = (*itr)->download()->up_rate()->total(); int64_t totalDone = (*itr)->download()->bytes_done(); - if ((totalUpload >= minUpload && totalUpload * 100 >= totalDone * minRatio) || (maxRatio > 0 && totalUpload * 100 > totalDone * maxRatio)) - m->core()->download_list()->stop_try(*itr); + if ((totalUpload >= minUpload && totalUpload * 100 >= totalDone * minRatio) || (maxRatio > 0 && totalUpload * 100 > totalDone * maxRatio)) { + m->core()->download_list()->stop_try(*itr); + (*itr)->variable()->set("ignore_commands", (int64_t)1); + } ++itr; } @@ -463,6 +466,9 @@ initialize_option_handler(Control* c) { variables->insert("receive_buffer_size", new utils::VariableValueSlot(rak::mem_fn(torrent::connection_manager(), &torrent::ConnectionManager::receive_buffer_size), rak::mem_fn(torrent::connection_manager(), &torrent::ConnectionManager::set_receive_buffer_size))); + variables->insert("max_memory_usage", new utils::VariableValueSlot(rak::mem_fn(torrent::chunk_manager(), &torrent::ChunkManager::max_memory_usage), + rak::mem_fn(torrent::chunk_manager(), &torrent::ChunkManager::set_max_memory_usage))); + variables->insert("port_range", new utils::VariableStringSlot(rak::value_fn(std::string()), rak::bind_ptr_fn(&apply_port_range, c))); variables->insert("hash_read_ahead", new utils::VariableValueSlot(rak::ptr_fn(torrent::hash_read_ahead), rak::bind_ptr_fn(&apply_hash_read_ahead, c)));