当前位置: 首页>>代码示例>>C++>>正文


C++ intrusive_ptr::total_size方法代码示例

本文整理汇总了C++中boost::intrusive_ptr::total_size方法的典型用法代码示例。如果您正苦于以下问题:C++ intrusive_ptr::total_size方法的具体用法?C++ intrusive_ptr::total_size怎么用?C++ intrusive_ptr::total_size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::intrusive_ptr的用法示例。


在下文中一共展示了intrusive_ptr::total_size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_transfer

// proxy: 0=none, 1=socks4, 2=socks5, 3=socks5_pw 4=http 5=http_pw
void test_transfer(session& ses, boost::intrusive_ptr<torrent_info> torrent_file
	, int proxy, int port, char const* protocol, bool url_seed
	, bool chunked_encoding, bool test_ban, bool keepalive, bool proxy_peers)
{
	using namespace libtorrent;

	std::string save_path = "tmp2_web_seed";
	save_path += proxy_name[proxy];

	error_code ec;
	remove_all(save_path, ec);

	static char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};

	fprintf(stderr, "\n\n  ==== TESTING === proxy: %s ==== protocol: %s "
		"==== seed: %s === transfer-encoding: %s === corruption: %s "
		"==== keepalive: %s\n\n\n"
		, test_name[proxy], protocol, url_seed ? "URL seed" : "HTTP seed"
		, chunked_encoding ? "chunked": "none", test_ban ? "yes" : "no"
		, keepalive ? "yes" : "no");

	proxy_settings ps;
	
	if (proxy)
	{
		ps.port = start_proxy(proxy);
		ps.hostname = "127.0.0.1";
		ps.username = "testuser";
		ps.password = "testpass";
		ps.type = (proxy_settings::proxy_type)proxy;
		ps.proxy_peer_connections = proxy_peers;
		ses.set_proxy(ps);
	}
	else
	{
		ps.port = 0;
		ps.hostname.clear();
		ps.username.clear();
		ps.password.clear();
		ps.type = proxy_settings::none;
		ps.proxy_peer_connections = proxy_peers;
		ses.set_proxy(ps);
	}

	add_torrent_params p;
	p.flags &= ~add_torrent_params::flag_paused;
	p.flags &= ~add_torrent_params::flag_auto_managed;
	p.ti = torrent_file;
	p.save_path = save_path;
#ifndef TORRENT_NO_DEPRECATE
	p.storage_mode = storage_mode_compact;
#endif
	torrent_handle th = ses.add_torrent(p, ec);

	std::vector<announce_entry> empty;
	th.replace_trackers(empty);

	const size_type total_size = torrent_file->total_size();

	float rate_sum = 0.f;
	float ses_rate_sum = 0.f;

	cache_status cs;

	file_storage const& fs = torrent_file->files();
	int pad_file_size = 0;
	for (int i = 0; i < fs.num_files(); ++i)
	{
		file_entry f = fs.at(i);
		if (f.pad_file) pad_file_size += f.size;
	}

	peer_disconnects = 0;

	for (int i = 0; i < 40; ++i)
	{
		torrent_status s = th.status();
		session_status ss = ses.status();
		rate_sum += s.download_payload_rate;
		ses_rate_sum += ss.payload_download_rate;

		cs = ses.get_cache_status();
		if (cs.blocks_read < 1) cs.blocks_read = 1;
		if (cs.blocks_written < 1) cs.blocks_written = 1;

		print_ses_rate(i / 10.f, &s, NULL);

		print_alerts(ses, "  >>  ses", test_ban, false, false, &on_alert);

		if (test_ban && th.url_seeds().empty() && th.http_seeds().empty())
		{
			// when we don't have any web seeds left, we know we successfully banned it
			break;
		}

		// if the web seed connection is disconnected, we're going to fail
		// the test. make sure to do so quickly
		if (keepalive && peer_disconnects >= 1) break;

//.........这里部分代码省略.........
开发者ID:ycopy,项目名称:libtorrent,代码行数:101,代码来源:web_seed_suite.cpp

示例2: test_transfer

// proxy: 0=none, 1=socks4, 2=socks5, 3=socks5_pw 4=http 5=http_pw
void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
	, int proxy, int port, char const* protocol, bool url_seed, bool chunked_encoding, bool test_ban)
{
	using namespace libtorrent;

	session ses(fingerprint("  ", 0,0,0,0), 0);
	session_settings settings;
	settings.max_queued_disk_bytes = 256 * 1024;
	ses.set_settings(settings);
	ses.set_alert_mask(~(alert::progress_notification | alert::stats_notification));
	error_code ec;
	ses.listen_on(std::make_pair(51000, 52000), ec);
	if (ec) fprintf(stderr, "listen_on failed: %s\n", ec.message().c_str());

	remove_all("tmp2_web_seed", ec);

	char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};

	fprintf(stderr, "\n\n  ==== TESTING === proxy: %s ==== protocol: %s ==== seed: %s === transfer-encoding: %s === corruption: %s\n\n\n"
		, test_name[proxy], protocol, url_seed ? "URL seed" : "HTTP seed", chunked_encoding ? "chunked": "none", test_ban ? "yes" : "no");
	
	if (proxy)
	{
		start_proxy(8002, proxy);
		proxy_settings ps;
		ps.hostname = "127.0.0.1";
		ps.port = 8002;
		ps.username = "testuser";
		ps.password = "testpass";
		ps.type = (proxy_settings::proxy_type)proxy;
		ses.set_proxy(ps);
	}

	add_torrent_params p;
	p.flags &= ~add_torrent_params::flag_paused;
	p.flags &= ~add_torrent_params::flag_auto_managed;
	p.ti = torrent_file;
	p.save_path = "tmp2_web_seed";
	p.storage_mode = storage_mode_compact;
	torrent_handle th = ses.add_torrent(p, ec);

	std::vector<announce_entry> empty;
	th.replace_trackers(empty);

	const size_type total_size = torrent_file->total_size();

	float rate_sum = 0.f;
	float ses_rate_sum = 0.f;

	cache_status cs;

	file_storage const& fs = torrent_file->files();
	int pad_file_size = 0;
	for (int i = 0; i < fs.num_files(); ++i)
	{
		file_entry f = fs.at(i);
		if (f.pad_file) pad_file_size += f.size;
	}

	for (int i = 0; i < 30; ++i)
	{
		torrent_status s = th.status();
		session_status ss = ses.status();
		rate_sum += s.download_payload_rate;
		ses_rate_sum += ss.payload_download_rate;

		sha1_hash ih(0);
		ses.get_cache_info(ih, &cs);
		if (cs.blocks_read < 1) cs.blocks_read = 1;
		if (cs.blocks_written < 1) cs.blocks_written = 1;
/*
		std::cerr << (s.progress * 100.f) << " %"
			<< " torrent rate: " << (s.download_rate / 1000.f) << " kB/s"
			<< " session rate: " << (ss.download_rate / 1000.f) << " kB/s"
			<< " session total: " << ss.total_payload_download
			<< " torrent total: " << s.total_payload_download
			<< " rate sum:" << ses_rate_sum
			<< " w-cache: " << cs.write_cache_size
			<< " r-cache: " << cs.read_cache_size
			<< " buffers: " << cs.total_used_buffers
			<< std::endl;
*/
		print_alerts(ses, "  >>  ses", test_ban, false, false, 0, true);

		if (test_ban && th.url_seeds().empty())
		{
			// when we don't have any web seeds left, we know we successfully banned it
			break;
		}

		if (s.is_seeding /* && ss.download_rate == 0.f*/)
		{
			TEST_EQUAL(s.total_payload_download - s.total_redundant_bytes, total_size - pad_file_size);
			// we need to sleep here a bit to let the session sync with the torrent stats
			test_sleep(1000);
			TEST_EQUAL(ses.status().total_payload_download - ses.status().total_redundant_bytes
				, total_size - pad_file_size);
			break;
		}
//.........这里部分代码省略.........
开发者ID:svn2github,项目名称:libtorrent-rasterbar,代码行数:101,代码来源:test_web_seed.cpp

示例3: test_transfer

// proxy: 0=none, 1=socks4, 2=socks5, 3=socks5_pw 4=http 5=http_pw
void test_transfer(boost::intrusive_ptr<torrent_info> torrent_file
	, int proxy, int port, char const* protocol, bool url_seed, bool chunked_encoding)
{
	using namespace libtorrent;

	session ses(fingerprint("  ", 0,0,0,0), 0);
	session_settings settings;
	settings.max_queued_disk_bytes = 256 * 1024;
	ses.set_settings(settings);
	ses.set_alert_mask(~(alert::progress_notification | alert::stats_notification));
	error_code ec;
	ses.listen_on(std::make_pair(51000, 52000), ec);
	if (ec) fprintf(stderr, "listen_on failed: %s\n", ec.message().c_str());

	remove_all("./tmp2_web_seed", ec);

	char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};

	fprintf(stderr, "\n\n  ==== TESTING === proxy: %s ==== protocol: %s ==== seed: %s === transfer-encoding: %s\n\n\n"
		, test_name[proxy], protocol, url_seed ? "URL seed" : "HTTP seed", chunked_encoding ? "chunked": "none");
	
	if (proxy)
	{
		start_proxy(8002, proxy);
		proxy_settings ps;
		ps.hostname = "127.0.0.1";
		ps.port = 8002;
		ps.username = "testuser";
		ps.password = "testpass";
		ps.type = (proxy_settings::proxy_type)proxy;
		ses.set_proxy(ps);
	}

	add_torrent_params p;
	p.auto_managed = false;
	p.paused = false;
	p.ti = torrent_file;
	p.save_path = "./tmp2_web_seed";
	p.storage_mode = storage_mode_compact;
	torrent_handle th = ses.add_torrent(p, ec);

	std::vector<announce_entry> empty;
	th.replace_trackers(empty);

	const size_type total_size = torrent_file->total_size();

	float rate_sum = 0.f;
	float ses_rate_sum = 0.f;

	cache_status cs;

	for (int i = 0; i < 30; ++i)
	{
		torrent_status s = th.status();
		session_status ss = ses.status();
		rate_sum += s.download_payload_rate;
		ses_rate_sum += ss.payload_download_rate;

		cs = ses.get_cache_status();
		if (cs.blocks_read < 1) cs.blocks_read = 1;
		if (cs.blocks_written < 1) cs.blocks_written = 1;
/*
		std::cerr << (s.progress * 100.f) << " %"
			<< " torrent rate: " << (s.download_rate / 1000.f) << " kB/s"
			<< " session rate: " << (ss.download_rate / 1000.f) << " kB/s"
			<< " session total: " << ss.total_payload_download
			<< " torrent total: " << s.total_payload_download
			<< " rate sum:" << ses_rate_sum
			<< " cache: " << cs.cache_size
			<< " rcache: " << cs.read_cache_size
			<< " buffers: " << cs.total_used_buffers
			<< std::endl;
*/
		print_alerts(ses, "  >>  ses", false, false, false, 0, true);

		if (s.is_seeding /* && ss.download_rate == 0.f*/)
		{
			TEST_EQUAL(s.total_payload_download - s.total_redundant_bytes, total_size);
			// we need to sleep here a bit to let the session sync with the torrent stats
			test_sleep(1000);
			TEST_EQUAL(ses.status().total_payload_download - ses.status().total_redundant_bytes
				, total_size);
			break;
		}
		test_sleep(500);
	}

	TEST_EQUAL(cs.cache_size, 0);
	TEST_EQUAL(cs.total_used_buffers, 0);

	std::cerr << "total_size: " << total_size
		<< " rate_sum: " << rate_sum
		<< " session_rate_sum: " << ses_rate_sum
		<< " session total download: " << ses.status().total_payload_download
		<< " torrent total download: " << th.status().total_payload_download
		<< " redundant: " << th.status().total_redundant_bytes
		<< std::endl;

	// the rates for each second should sum up to the total, with a 10% error margin
//.........这里部分代码省略.........
开发者ID:kuro,项目名称:libtorrent,代码行数:101,代码来源:test_web_seed.cpp


注:本文中的boost::intrusive_ptr::total_size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。