From 4e9124019bf80764aadd5914776112bc6441821e Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 8 Nov 2008 07:40:55 +0000 Subject: [PATCH] added accessor to query for the max number of connections --- docs/manual.rst | 16 ++++++++++++---- include/libtorrent/session.hpp | 2 ++ include/libtorrent/torrent_handle.hpp | 1 + src/connection_queue.cpp | 2 +- src/disk_io_thread.cpp | 1 + src/session.cpp | 5 +++++ src/torrent_handle.cpp | 6 ++++++ 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index 5cb9aae24..fdfeed6c4 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -116,6 +116,7 @@ The ``session`` class has the following synopsis:: int download_rate_limit() const; void set_max_uploads(int limit); void set_max_connections(int limit); + int max_connections() const; void set_max_half_open_connections(int limit); int max_half_open_connections() const; @@ -406,13 +407,14 @@ of upload rate. set limits. -set_max_uploads() set_max_connections() ---------------------------------------- +set_max_uploads() set_max_connections() max_connections() +--------------------------------------------------------- :: void set_max_uploads(int limit); void set_max_connections(int limit); + int max_connections() const; These functions will set a global limit on the number of unchoked peers (uploads) and the number of connections opened. The number of connections is set to a hard @@ -420,6 +422,8 @@ minimum of at least two connections per torrent, so if you set a too low connections limit, and open too many torrents, the limit will not be met. The number of uploads is at least one per torrent. +``max_connections()`` returns the current setting. + num_uploads() num_connections() ------------------------------- @@ -1616,6 +1620,7 @@ Its declaration looks like this:: void set_ratio(float ratio) const; void set_max_uploads(int max_uploads) const; void set_max_connections(int max_connections) const; + int max_connections() const; void set_upload_limit(int limit) const; int upload_limit() const; void set_download_limit(int limit) const; @@ -2123,13 +2128,14 @@ info_hash() ``info_hash()`` returns the info-hash for the torrent. -set_max_uploads() set_max_connections() ---------------------------------------- +set_max_uploads() set_max_connections() max_connections() +--------------------------------------------------------- :: void set_max_uploads(int max_uploads) const; void set_max_connections(int max_connections) const; + int max_connections() const; ``set_max_uploads()`` sets the maximum number of peers that's unchoked at the same time on this torrent. If you set this to -1, there will be no limit. @@ -2139,6 +2145,8 @@ connections are used up, incoming connections may be refused or poor connections This must be at least 2. The default is unlimited number of connections. If -1 is given to the function, it means unlimited. +``max_connections()`` returns the current setting. + save_resume_data() ------------------ diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 1f837e317..52f82977c 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -326,6 +326,8 @@ namespace libtorrent void set_max_connections(int limit); void set_max_half_open_connections(int limit); + int max_connections() const; + std::auto_ptr pop_alert(); #ifndef TORRENT_NO_DEPRECATE void set_severity_level(alert::severity_t s) TORRENT_DEPRECATED; diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 37da340c2..84a3785f7 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -463,6 +463,7 @@ namespace libtorrent // -1 means unlimited connections void set_max_connections(int max_connections) const; + int max_connections() const; void set_tracker_login(std::string const& name , std::string const& password) const; diff --git a/src/connection_queue.cpp b/src/connection_queue.cpp index 560f31e59..715064b17 100644 --- a/src/connection_queue.cpp +++ b/src/connection_queue.cpp @@ -122,7 +122,7 @@ namespace libtorrent while (!m_queue.empty()) { // we don't want to call the timeout callback while we're locked - // since that is a recepie for dead-locks + // since that is a recipie for dead-locks entry e = m_queue.front(); m_queue.pop_front(); if (e.connecting) --m_num_connecting; diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 0635a60b5..bb78aad2d 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -714,6 +714,7 @@ namespace libtorrent void disk_io_thread::free_buffer(char* buf) { + TORRENT_ASSERT(buf); mutex_t::scoped_lock l(m_pool_mutex); #ifdef TORRENT_STATS --m_allocations; diff --git a/src/session.cpp b/src/session.cpp index 64a39e08c..08cdbd954 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -501,6 +501,11 @@ namespace libtorrent m_impl->set_max_uploads(limit); } + int session::max_connections() const + { + return m_impl->max_connections(); + } + void session::set_max_connections(int limit) { m_impl->set_max_connections(limit); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index cbcb9ad09..44e823f17 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -161,6 +161,12 @@ namespace libtorrent TORRENT_FORWARD(use_interface(net_interface)); } + int torrent_handle::max_connections() const + { + INVARIANT_CHECK; + TORRENT_FORWARD_RETURN(max_connections(), 0); + } + void torrent_handle::set_max_connections(int max_connections) const { INVARIANT_CHECK;