applied patch from Sergei Vorobyov to allow changing the limit on outstanding alerts
This commit is contained in:
parent
468ec140ac
commit
b355541a7d
|
@ -151,6 +151,7 @@ The ``session`` class has the following synopsis::
|
|||
std::auto_ptr<alert> pop_alert();
|
||||
alert const* wait_for_alert(time_duration max_wait);
|
||||
void set_alert_mask(int m);
|
||||
size_t set_alert_queue_size_limit(size_t queue_size_limit_);
|
||||
|
||||
void add_extension(boost::function<
|
||||
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
|
||||
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();
|
||||
alert const* wait_for_alert(time_duration max_wait);
|
||||
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
|
||||
``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
|
||||
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()
|
||||
---------------
|
||||
|
|
|
@ -111,6 +111,8 @@ namespace libtorrent {
|
|||
class TORRENT_EXPORT alert_manager
|
||||
{
|
||||
public:
|
||||
enum { queue_size_limit_default = 1000 };
|
||||
|
||||
alert_manager();
|
||||
~alert_manager();
|
||||
|
||||
|
@ -125,11 +127,15 @@ namespace libtorrent {
|
|||
|
||||
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:
|
||||
std::queue<alert*> m_alerts;
|
||||
mutable boost::mutex m_mutex;
|
||||
boost::condition m_condition;
|
||||
int m_alert_mask;
|
||||
size_t m_queue_size_limit;
|
||||
};
|
||||
|
||||
struct TORRENT_EXPORT unhandled_alert : std::exception
|
||||
|
|
|
@ -212,6 +212,7 @@ namespace libtorrent
|
|||
void done_checking(boost::shared_ptr<torrent> const& t);
|
||||
|
||||
void set_alert_mask(int m);
|
||||
size_t set_alert_queue_size_limit(size_t queue_size_limit_);
|
||||
std::auto_ptr<alert> pop_alert();
|
||||
|
||||
alert const* wait_for_alert(time_duration max_wait);
|
||||
|
|
|
@ -331,6 +331,7 @@ namespace libtorrent
|
|||
void set_severity_level(alert::severity_t s) TORRENT_DEPRECATED;
|
||||
#endif
|
||||
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);
|
||||
|
||||
|
|
|
@ -35,8 +35,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/alert.hpp"
|
||||
#include <boost/thread/xtime.hpp>
|
||||
|
||||
enum { queue_size_limit = 1000 };
|
||||
|
||||
namespace libtorrent {
|
||||
|
||||
alert::alert() : m_timestamp(time_now()) {}
|
||||
|
@ -45,6 +43,7 @@ namespace libtorrent {
|
|||
|
||||
alert_manager::alert_manager()
|
||||
: m_alert_mask(alert::error_notification)
|
||||
, m_queue_size_limit(queue_size_limit_default)
|
||||
{}
|
||||
|
||||
alert_manager::~alert_manager()
|
||||
|
@ -85,7 +84,7 @@ namespace libtorrent {
|
|||
{
|
||||
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_condition.notify_all();
|
||||
}
|
||||
|
@ -108,5 +107,13 @@ namespace libtorrent {
|
|||
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
|
||||
|
||||
|
|
|
@ -553,6 +553,11 @@ namespace libtorrent
|
|||
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
|
||||
void session::set_severity_level(alert::severity_t s)
|
||||
{
|
||||
|
|
|
@ -2312,6 +2312,12 @@ namespace aux {
|
|||
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
|
||||
{
|
||||
mutex_t::scoped_lock l(m_mutex);
|
||||
|
|
Loading…
Reference in New Issue