From d898b9db01f10df8da9745a37a80ba25ba531dcc Mon Sep 17 00:00:00 2001 From: rakshasa Date: Mon, 2 May 2005 01:20:51 +0000 Subject: [PATCH] Adding controls for download throttle. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@426 e378c898-3ddf-0310-93e7-cc216c733640 --- README | 12 ++++++------ src/display/window_statusbar.cc | 25 ++++++++++++++++--------- src/main.cc | 3 ++- src/ui/download.cc | 28 +++++++++++++++++++++------- src/ui/download.h | 3 ++- src/ui/download_list.cc | 28 +++++++++++++++++++++------- src/ui/download_list.h | 3 ++- 7 files changed, 70 insertions(+), 32 deletions(-) diff --git a/README b/README index 343af8c2..9a1940b5 100644 --- a/README +++ b/README @@ -25,14 +25,14 @@ All: Ctrl-Q - Quit - A - Increase Throttle by 1 KiB - Z - Decrease Throttle by 1 KiB + a/A - Increase upload/download throttle by 1 KiB + z/Z - Decrease upload/download throttle by 1 KiB - S - Increase Throttle by 5 KiB - X - Decrease Throttle by 5 KiB + s/S - Increase upload/download throttle by 5 KiB + x/X - Decrease upload/download throttle by 5 KiB - D - Increase Throttle by 50 KiB - C - Decrease Throttle by 50 KiB + d/D - Increase upload/download throttle by 50 KiB + c/C - Decrease upload/download throttle by 50 KiB In main window: diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index 5dd4e8e4..aace1efd 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -43,17 +43,24 @@ WindowStatusbar::redraw() { m_canvas->erase(); + int pos = 0; + char buf[128]; + if (torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) == 0) - m_canvas->print(0, 0, "Throttle: off Listen: %s:%i Handshakes: %i", - m_core->get_dns().empty() ? "" : m_core->get_dns().c_str(), - (int)torrent::get(torrent::LISTEN_PORT), - (int)torrent::get(torrent::HANDSHAKES_TOTAL)); + pos = snprintf(buf, 128, "off/"); else - m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i", - (int)torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) / 1024, - m_core->get_dns().empty() ? "" : m_core->get_dns().c_str(), - (int)torrent::get(torrent::LISTEN_PORT), - (int)torrent::get(torrent::HANDSHAKES_TOTAL)); + pos = snprintf(buf, 128, "%3i/", (int)torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) / 1024); + + if (torrent::get(torrent::THROTTLE_READ_CONST_RATE) == 0) + pos = snprintf(buf + pos, 128 - pos, "off"); + else + pos = snprintf(buf + pos, 128 - pos, "%-3i", (int)torrent::get(torrent::THROTTLE_READ_CONST_RATE) / 1024); + + m_canvas->print(0, 0, "Throttle U/D: %s Listen: %s:%i Handshakes: %i", + buf, + m_core->get_dns().empty() ? "" : m_core->get_dns().c_str(), + (int)torrent::get(torrent::LISTEN_PORT), + (int)torrent::get(torrent::HANDSHAKES_TOTAL)); } } diff --git a/src/main.cc b/src/main.cc index 4a55a205..b7742b7d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -239,7 +239,8 @@ print_help() { std::cout << " ^s Start torrent" << std::endl; std::cout << " ^d Stop torrent or delete a stopped torrent" << std::endl; std::cout << " ^q Initiate shutdown or skip shutdown process" << std::endl; - std::cout << " a,s,d,z,x,c Adjust throttle" << std::endl; + std::cout << " a,s,d,z,x,c Adjust upload throttle" << std::endl; + std::cout << " A,S,D,Z,X,C Adjust download throttle" << std::endl; std::cout << " right View torrent" << std::endl; std::cout << std::endl; std::cout << "Download view keys:" << std::endl; diff --git a/src/ui/download.cc b/src/ui/download.cc index e3a85584..2281a747 100644 --- a/src/ui/download.cc +++ b/src/ui/download.cc @@ -181,7 +181,14 @@ Download::receive_peer_disconnected(torrent::Peer p) { } void -Download::receive_throttle(int t) { +Download::receive_read_throttle(int t) { + m_windowMainStatus->mark_dirty(); + + torrent::set(torrent::THROTTLE_READ_CONST_RATE, torrent::get(torrent::THROTTLE_READ_CONST_RATE) + t * 1024); +} + +void +Download::receive_write_throttle(int t) { m_windowMainStatus->mark_dirty(); torrent::set(torrent::THROTTLE_ROOT_CONST_RATE, torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) + t * 1024); @@ -229,12 +236,19 @@ Download::receive_snub_peer() { void Download::bind_keys() { - (*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 1); - (*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -1); - (*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 5); - (*m_bindings)['x'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -5); - (*m_bindings)['d'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 50); - (*m_bindings)['c'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -50); + (*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), 1); + (*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), -1); + (*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), 5); + (*m_bindings)['x'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), -5); + (*m_bindings)['d'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), 50); + (*m_bindings)['c'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), -50); + + (*m_bindings)['A'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), 1); + (*m_bindings)['Z'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), -1); + (*m_bindings)['S'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), 5); + (*m_bindings)['X'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), -5); + (*m_bindings)['D'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), 50); + (*m_bindings)['C'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), -50); (*m_bindings)['1'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_uploads), -1); (*m_bindings)['2'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_uploads), 1); diff --git a/src/ui/download.h b/src/ui/download.h index 0b4d3aa4..0e57a506 100644 --- a/src/ui/download.h +++ b/src/ui/download.h @@ -83,7 +83,8 @@ private: void receive_peer_connected(torrent::Peer p); void receive_peer_disconnected(torrent::Peer p); - void receive_throttle(int t); + void receive_read_throttle(int t); + void receive_write_throttle(int t); void receive_max_uploads(int t); void receive_min_peers(int t); void receive_max_peers(int t); diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index b62d6535..8c36eaeb 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -169,7 +169,14 @@ DownloadList::receive_prev() { } void -DownloadList::receive_throttle(int t) { +DownloadList::receive_read_throttle(int t) { + m_windowStatus->mark_dirty(); + + torrent::set(torrent::THROTTLE_READ_CONST_RATE, torrent::get(torrent::THROTTLE_READ_CONST_RATE) + t * 1024); +} + +void +DownloadList::receive_write_throttle(int t) { m_windowStatus->mark_dirty(); torrent::set(torrent::THROTTLE_ROOT_CONST_RATE, torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) + t * 1024); @@ -274,12 +281,19 @@ DownloadList::task_update() { void DownloadList::setup_keys() { - (*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 1); - (*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -1); - (*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 5); - (*m_bindings)['x'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -5); - (*m_bindings)['d'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 50); - (*m_bindings)['c'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -50); + (*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), 1); + (*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), -1); + (*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), 5); + (*m_bindings)['x'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), -5); + (*m_bindings)['d'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), 50); + (*m_bindings)['c'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), -50); + + (*m_bindings)['A'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), 1); + (*m_bindings)['Z'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), -1); + (*m_bindings)['S'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), 5); + (*m_bindings)['X'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), -5); + (*m_bindings)['D'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), 50); + (*m_bindings)['C'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), -50); (*m_bindings)['\x13'] = sigc::mem_fun(*this, &DownloadList::receive_start_download); (*m_bindings)['\x04'] = sigc::mem_fun(*this, &DownloadList::receive_stop_download); diff --git a/src/ui/download_list.h b/src/ui/download_list.h index a570d784..3e2a6cd1 100644 --- a/src/ui/download_list.h +++ b/src/ui/download_list.h @@ -92,7 +92,8 @@ private: void receive_next(); void receive_prev(); - void receive_throttle(int t); + void receive_read_throttle(int t); + void receive_write_throttle(int t); void receive_start_download(); void receive_stop_download();