applied patch from Sergei Vorobyov to allow changing the limit on outstanding alerts

This commit is contained in:
Arvid Norberg 2008-10-07 05:46:42 +00:00
parent 468ec140ac
commit b355541a7d
7 changed files with 36 additions and 5 deletions

View File

@ -151,6 +151,7 @@ The ``session`` class has the following synopsis::
std::auto_ptr<alert> pop_alert(); std::auto_ptr<alert> pop_alert();
alert const* wait_for_alert(time_duration max_wait); alert const* wait_for_alert(time_duration max_wait);
void set_alert_mask(int m); void set_alert_mask(int m);
size_t set_alert_queue_size_limit(size_t queue_size_limit_);
void add_extension(boost::function< void add_extension(boost::function<
boost::shared_ptr<torrent_plugin>(torrent*)> ext); boost::shared_ptr<torrent_plugin>(torrent*)> ext);
@ -742,14 +743,15 @@ with a DHT ping packet, and connect to those that responds first. On windows one
can only connect to a few peers at a time because of a built in limitation (in XP can only connect to a few peers at a time because of a built in limitation (in XP
Service pack 2). Service pack 2).
pop_alert() set_alert_mask() wait_for_alert() pop_alert() set_alert_mask() wait_for_alert() set_alert_queue_size_limit()
--------------------------------------------- --------------------------------------------------------------------------
:: ::
std::auto_ptr<alert> pop_alert(); std::auto_ptr<alert> pop_alert();
alert const* wait_for_alert(time_duration max_wait); alert const* wait_for_alert(time_duration max_wait);
void set_alert_mask(int m); void set_alert_mask(int m);
size_t set_alert_queue_size_limit(size_t queue_size_limit_);
``pop_alert()`` is used to ask the session if any errors or events has occurred. With ``pop_alert()`` is used to ask the session if any errors or events has occurred. With
``set_alert_mask()`` you can filter which alerts to receive through ``pop_alert()``. ``set_alert_mask()`` you can filter which alerts to receive through ``pop_alert()``.
@ -763,6 +765,9 @@ same pointer until the alert is popped by calling ``pop_alert``. This is useful
leaving any alert dispatching mechanism independent of this blocking call, the dispatcher leaving any alert dispatching mechanism independent of this blocking call, the dispatcher
can be called and it can pop the alert independently. can be called and it can pop the alert independently.
``set_alert_queue_size_limit()`` you can specify how many alerts can be awaiting for dispatching.
If this limit is reached, new incoming alerts can not be received until alerts are popped
by calling ``pop_alert``. Default value is 1000.
add_extension() add_extension()
--------------- ---------------

View File

@ -111,6 +111,8 @@ namespace libtorrent {
class TORRENT_EXPORT alert_manager class TORRENT_EXPORT alert_manager
{ {
public: public:
enum { queue_size_limit_default = 1000 };
alert_manager(); alert_manager();
~alert_manager(); ~alert_manager();
@ -125,11 +127,15 @@ namespace libtorrent {
void set_alert_mask(int m) { m_alert_mask = m; } void set_alert_mask(int m) { m_alert_mask = m; }
size_t alert_queue_size_limit() const { return m_queue_size_limit; }
size_t set_alert_queue_size_limit(size_t queue_size_limit_);
private: private:
std::queue<alert*> m_alerts; std::queue<alert*> m_alerts;
mutable boost::mutex m_mutex; mutable boost::mutex m_mutex;
boost::condition m_condition; boost::condition m_condition;
int m_alert_mask; int m_alert_mask;
size_t m_queue_size_limit;
}; };
struct TORRENT_EXPORT unhandled_alert : std::exception struct TORRENT_EXPORT unhandled_alert : std::exception

View File

@ -212,6 +212,7 @@ namespace libtorrent
void done_checking(boost::shared_ptr<torrent> const& t); void done_checking(boost::shared_ptr<torrent> const& t);
void set_alert_mask(int m); void set_alert_mask(int m);
size_t set_alert_queue_size_limit(size_t queue_size_limit_);
std::auto_ptr<alert> pop_alert(); std::auto_ptr<alert> pop_alert();
alert const* wait_for_alert(time_duration max_wait); alert const* wait_for_alert(time_duration max_wait);

View File

@ -331,6 +331,7 @@ namespace libtorrent
void set_severity_level(alert::severity_t s) TORRENT_DEPRECATED; void set_severity_level(alert::severity_t s) TORRENT_DEPRECATED;
#endif #endif
void set_alert_mask(int m); void set_alert_mask(int m);
size_t set_alert_queue_size_limit(size_t queue_size_limit_);
alert const* wait_for_alert(time_duration max_wait); alert const* wait_for_alert(time_duration max_wait);

View File

@ -35,8 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alert.hpp" #include "libtorrent/alert.hpp"
#include <boost/thread/xtime.hpp> #include <boost/thread/xtime.hpp>
enum { queue_size_limit = 1000 };
namespace libtorrent { namespace libtorrent {
alert::alert() : m_timestamp(time_now()) {} alert::alert() : m_timestamp(time_now()) {}
@ -45,6 +43,7 @@ namespace libtorrent {
alert_manager::alert_manager() alert_manager::alert_manager()
: m_alert_mask(alert::error_notification) : m_alert_mask(alert::error_notification)
, m_queue_size_limit(queue_size_limit_default)
{} {}
alert_manager::~alert_manager() alert_manager::~alert_manager()
@ -85,7 +84,7 @@ namespace libtorrent {
{ {
boost::mutex::scoped_lock lock(m_mutex); boost::mutex::scoped_lock lock(m_mutex);
if (m_alerts.size() >= queue_size_limit) return; if (m_alerts.size() >= m_queue_size_limit) return;
m_alerts.push(alert_.clone().release()); m_alerts.push(alert_.clone().release());
m_condition.notify_all(); m_condition.notify_all();
} }
@ -108,5 +107,13 @@ namespace libtorrent {
return !m_alerts.empty(); return !m_alerts.empty();
} }
size_t alert_manager::set_alert_queue_size_limit(size_t queue_size_limit_)
{
boost::mutex::scoped_lock lock(m_mutex);
std::swap(m_queue_size_limit, queue_size_limit_);
return queue_size_limit_;
}
} // namespace libtorrent } // namespace libtorrent

View File

@ -553,6 +553,11 @@ namespace libtorrent
m_impl->set_alert_mask(m); m_impl->set_alert_mask(m);
} }
size_t set_alert_queue_size_limit(size_t queue_size_limit_);
{
return m_impl->set_alert_queue_size_limit(queue_size_limit_);
}
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
void session::set_severity_level(alert::severity_t s) void session::set_severity_level(alert::severity_t s)
{ {

View File

@ -2312,6 +2312,12 @@ namespace aux {
m_alerts.set_alert_mask(m); m_alerts.set_alert_mask(m);
} }
size_t session_impl::set_alert_queue_size_limit(size_t queue_size_limit_)
{
mutex_t::scoped_lock l(m_mutex);
return m_alerts.set_alert_queue_size_limit(queue_size_limit_);
}
int session_impl::upload_rate_limit() const int session_impl::upload_rate_limit() const
{ {
mutex_t::scoped_lock l(m_mutex); mutex_t::scoped_lock l(m_mutex);