⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bandwidth_limit.hpp

📁 LINUX下
💻 HPP
字号:
/*Copyright (c) 2007, Arvid NorbergAll rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditionsare met:    * Redistributions of source code must retain the above copyright      notice, this list of conditions and the following disclaimer.    * Redistributions in binary form must reproduce the above copyright      notice, this list of conditions and the following disclaimer in      the documentation and/or other materials provided with the distribution.    * Neither the name of the author nor the names of its      contributors may be used to endorse or promote products derived      from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSEARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BELIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OFSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESSINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER INCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF SUCH DAMAGE.*/#ifndef TORRENT_BANDWIDTH_LIMIT_HPP_INCLUDED#define TORRENT_BANDWIDTH_LIMIT_HPP_INCLUDED#include <boost/integer_traits.hpp>#include "libtorrent/assert.hpp"namespace libtorrent {// member of peer_connectionstruct bandwidth_limit{	static const int inf = boost::integer_traits<int>::const_max;	bandwidth_limit()		: m_quota_left(0)		, m_local_limit(inf)		, m_current_rate(0)	{}	void throttle(int limit)	{		TORRENT_ASSERT(limit > 0);		m_local_limit = limit;	}		int throttle() const	{		return m_local_limit;	}	void assign(int amount)	{		TORRENT_ASSERT(amount >= 0);		m_current_rate += amount;		m_quota_left += amount;	}	void use_quota(int amount)	{		TORRENT_ASSERT(amount <= m_quota_left);		m_quota_left -= amount;	}	int quota_left() const	{		return (std::max)(m_quota_left, 0);	}	void expire(int amount)	{		TORRENT_ASSERT(amount >= 0);		m_current_rate -= amount;	}	int max_assignable() const	{		if (m_local_limit == inf) return inf;		if (m_local_limit <= m_current_rate) return 0;		return m_local_limit - m_current_rate;	}private:	// this is the amount of bandwidth we have	// been assigned without using yet. i.e.	// the bandwidth that we use up every time	// we receive or send a message. Once this	// hits zero, we need to request more	// bandwidth from the torrent which	// in turn will request bandwidth from	// the bandwidth manager	int m_quota_left;	// the local limit is the number of bytes	// per window size we are allowed to use.	int m_local_limit;	// the current rate is the number of	// bytes we have been assigned within	// the window size.	int m_current_rate;};}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -