From 4ceb6a02ea79ec32efcdc2f64c669dbb6bffe61f Mon Sep 17 00:00:00 2001
From: Arvid Norberg
Date: Tue, 10 Apr 2007 09:25:17 +0000
Subject: [PATCH] added download_limit and upload_limit functions to
torrent_handle
---
docs/manual.html | 10 ++++++++--
docs/manual.rst | 11 +++++++++--
include/libtorrent/torrent.hpp | 3 +++
include/libtorrent/torrent_handle.hpp | 3 +++
src/torrent.cpp | 14 ++++++++++++++
src/torrent_handle.cpp | 14 ++++++++++++++
6 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/docs/manual.html b/docs/manual.html
index 884cc8ba0..722764200 100644
--- a/docs/manual.html
+++ b/docs/manual.html
@@ -79,7 +79,7 @@
connect_peer()
name()
set_ratio()
-set_upload_limit() set_download_limit()
+set_upload_limit() set_download_limit() upload_limit() download_limit()
set_sequenced_download_threshold()
set_peer_upload_limit() set_peer_download_limit()
pause() resume() is_paused()
@@ -1258,7 +1258,9 @@ struct torrent_handle
void set_max_uploads(int max_uploads) const;
void set_max_connections(int max_connections) const;
void set_upload_limit(int limit) const;
+ int upload_limit() const;
void set_download_limit(int limit) const;
+ int download_limit() const;
void set_sequenced_download_threshold(int threshold) const;
void set_peer_upload_limit(asio::ip::tcp::endpoint ip, int limit) const;
@@ -1442,11 +1444,13 @@ attempt to upload in return for each download. e.g. if set to 2, the client will
as a standard client.
-
+
void set_upload_limit(int limit) const;
void set_download_limit(int limit) const;
+int upload_limit() const;
+int download_limit() const;
set_upload_limit will limit the upload bandwidth used by this particular torrent to the
@@ -1455,6 +1459,8 @@ limit you set. It is given as the number of bytes per second the torrent is allo
Note that setting a higher limit on a torrent then the global limit (session::set_upload_rate_limit)
will not override the global rate limit. The torrent can never upload more than the global rate
limit.
+
upload_limit and download_limit will return the current limit setting, for upload and
+download, respectively.
diff --git a/docs/manual.rst b/docs/manual.rst
index 06f53d466..f5873c788 100644
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -1202,7 +1202,9 @@ Its declaration looks like this::
void set_max_uploads(int max_uploads) const;
void set_max_connections(int max_connections) const;
void set_upload_limit(int limit) const;
+ int upload_limit() const;
void set_download_limit(int limit) const;
+ int download_limit() const;
void set_sequenced_download_threshold(int threshold) const;
void set_peer_upload_limit(asio::ip::tcp::endpoint ip, int limit) const;
@@ -1397,13 +1399,15 @@ attempt to upload in return for each download. e.g. if set to 2, the client will
as a standard client.
-set_upload_limit() set_download_limit()
----------------------------------------
+set_upload_limit() set_download_limit() upload_limit() download_limit()
+-----------------------------------------------------------------------
::
void set_upload_limit(int limit) const;
void set_download_limit(int limit) const;
+ int upload_limit() const;
+ int download_limit() const;
``set_upload_limit`` will limit the upload bandwidth used by this particular torrent to the
limit you set. It is given as the number of bytes per second the torrent is allowed to upload.
@@ -1412,6 +1416,9 @@ Note that setting a higher limit on a torrent then the global limit (``session::
will not override the global rate limit. The torrent can never upload more than the global rate
limit.
+``upload_limit`` and ``download_limit`` will return the current limit setting, for upload and
+download, respectively.
+
set_sequenced_download_threshold()
----------------------------------
diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp
index e291384de..fde1fc016 100755
--- a/include/libtorrent/torrent.hpp
+++ b/include/libtorrent/torrent.hpp
@@ -467,7 +467,10 @@ namespace libtorrent
void set_peer_download_limit(tcp::endpoint ip, int limit);
void set_upload_limit(int limit);
+ int upload_limit() const;
void set_download_limit(int limit);
+ int download_limit() const;
+
void set_max_uploads(int limit);
void set_max_connections(int limit);
bool move_storage(boost::filesystem::path const& save_path);
diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp
index c645fae9c..33210e4a0 100755
--- a/include/libtorrent/torrent_handle.hpp
+++ b/include/libtorrent/torrent_handle.hpp
@@ -301,7 +301,10 @@ namespace libtorrent
// abort the torrent.
void set_upload_limit(int limit) const;
+ int upload_limit() const;
void set_download_limit(int limit) const;
+ int download_limit() const;
+
void set_sequenced_download_threshold(int threshold) const;
void set_peer_upload_limit(tcp::endpoint ip, int limit) const;
diff --git a/src/torrent.cpp b/src/torrent.cpp
index f8c7d7e56..b8b87076b 100755
--- a/src/torrent.cpp
+++ b/src/torrent.cpp
@@ -2406,6 +2406,13 @@ namespace libtorrent
m_bandwidth_limit[peer_connection::upload_channel].throttle(limit);
}
+ int torrent::upload_limit() const
+ {
+ int limit = m_bandwidth_limit[peer_connection::upload_channel].throttle();
+ if (limit == std::numeric_limits
::max()) limit = -1;
+ return limit;
+ }
+
void torrent::set_download_limit(int limit)
{
assert(limit >= -1);
@@ -2414,6 +2421,13 @@ namespace libtorrent
m_bandwidth_limit[peer_connection::download_channel].throttle(limit);
}
+ int torrent::download_limit() const
+ {
+ int limit = m_bandwidth_limit[peer_connection::download_channel].throttle();
+ if (limit == std::numeric_limits::max()) limit = -1;
+ return limit;
+ }
+
void torrent::pause()
{
INVARIANT_CHECK;
diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp
index a21e919ec..8495e653a 100755
--- a/src/torrent_handle.cpp
+++ b/src/torrent_handle.cpp
@@ -181,6 +181,13 @@ namespace libtorrent
, bind(&torrent::set_upload_limit, _1, limit));
}
+ int torrent_handle::upload_limit() const
+ {
+ INVARIANT_CHECK;
+ return call_member(m_ses, m_chk, m_info_hash
+ , bind(&torrent::upload_limit, _1));
+ }
+
void torrent_handle::set_download_limit(int limit) const
{
INVARIANT_CHECK;
@@ -191,6 +198,13 @@ namespace libtorrent
, bind(&torrent::set_download_limit, _1, limit));
}
+ int torrent_handle::download_limit() const
+ {
+ INVARIANT_CHECK;
+ return call_member(m_ses, m_chk, m_info_hash
+ , bind(&torrent::download_limit, _1));
+ }
+
bool torrent_handle::move_storage(
boost::filesystem::path const& save_path) const
{