本文整理汇总了C++中libtorrent::session::remove_torrent方法的典型用法代码示例。如果您正苦于以下问题:C++ session::remove_torrent方法的具体用法?C++ session::remove_torrent怎么用?C++ session::remove_torrent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libtorrent::session
的用法示例。
在下文中一共展示了session::remove_torrent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_alert
bool on_alert(libtorrent::alert const* alert
, int session_idx
, std::vector<libtorrent::torrent_handle> const& handles
, libtorrent::session& ses) override
{
if (alert_cast<metadata_received_alert>(alert))
{
m_metadata_alerts += 1;
}
// make sure this function can be called on
// torrents without metadata
if ((m_flags & disconnect) == 0)
{
handles[session_idx].status();
}
if ((m_flags & disconnect)
&& session_idx == 1
&& alert_cast<metadata_received_alert>(alert))
{
ses.remove_torrent(handles[session_idx]);
return true;
}
return false;
}
示例2: GetTorrentHandle
//-----------------------------------------------------------------------------
JNIEXPORT jboolean JNICALL Java_com_softwarrior_libtorrent_LibTorrent_RemoveTorrent
(JNIEnv *env, jobject obj, jstring ContentFile)
{
jboolean result = JNI_FALSE;
try {
if(gSessionState){
libtorrent::torrent_handle* pTorrent = GetTorrentHandle(env,ContentFile);
if(pTorrent){
LOG_INFO("Remove torrent name %s", pTorrent->name().c_str());
pTorrent->auto_managed(false);
pTorrent->pause();
// the alert handler for save_resume_data_alert
// will save it to disk
/*pTorrent->save_resume_data();
// loop through the alert queue to see if anything has happened.
std::auto_ptr<libtorrent::alert> a;
a = gSession.pop_alert();
while (a.get()){
//LOG_INFO("RemoveTorrent Alert: %s", a->message().c_str());
HandleAlert(a.get());
a = gSession.pop_alert();
}*/
gSession.remove_torrent(*pTorrent);
LOG_INFO("remove_torrent");
gTorrents.erase(TorrentFileInfo(env,ContentFile));
result = JNI_TRUE;
}
}
} catch(...){
LOG_ERR("Exception: failed to remove torrent");
try {
gTorrents.erase(TorrentFileInfo(env,ContentFile));
}catch(...){}
}
return result;
}
示例3: test_transfer
//.........这里部分代码省略.........
cnt = get_counters(ses);
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())
{
fprintf(stderr, "testing ban: URL seed removed\n");
// when we don't have any web seeds left, we know we successfully banned it
break;
}
if (s.is_seeding)
{
fprintf(stderr, "SEEDING\n");
fprintf(stderr, "session.payload: %d session.redundant: %d\n"
, int(cnt["net.recv_payload_bytes"]), int(cnt["net.recv_redundant_bytes"]));
fprintf(stderr, "torrent.payload: %d torrent.redundant: %d\n"
, int(s.total_payload_download), int(s.total_redundant_bytes));
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
// commented out because it takes such a long time
// TEST_EQUAL(ses.status().total_payload_download - ses.status().total_redundant_bytes
// , total_size - pad_file_size);
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;
test_sleep(100);
}
// for test_ban tests, make sure we removed
// the url seed (i.e. banned it)
TEST_CHECK(!test_ban || (th.url_seeds().empty() && th.http_seeds().empty()));
cnt = get_counters(ses);
// if the web seed senr corrupt data and we banned it, we probably didn't
// end up using all the cache anyway
if (!test_ban)
{
torrent_status st = th.status();
TEST_EQUAL(st.is_seeding, true);
if (st.is_seeding)
{
for (int i = 0; i < 50; ++i)
{
cnt = get_counters(ses);
if (cnt["disk.read_cache_blocks"]
== (torrent_file->total_size() + 0x3fff) / 0x4000
&& cnt["disk.disk_blocks_in_use"]
== (torrent_file->total_size() + 0x3fff) / 0x4000)
break;
fprintf(stderr, "cache_size: %d/%d\n", int(cnt["disk.read_cache_blocks"])
, int(cnt["disk.disk_blocks_in_use"]));
test_sleep(100);
}
TEST_EQUAL(cnt["disk.disk_blocks_in_use"]
, (torrent_file->total_size() + 0x3fff) / 0x4000);
}
}
std::cerr << "total_size: " << total_size
<< " read cache size: " << cnt["disk.disk_blocks_in_use"]
<< " total used buffer: " << cnt["disk.disk_blocks_in_use"]
<< " session total download: " << cnt["net.recv_payload_bytes"]
<< " torrent total download: " << th.status().total_payload_download
<< " redundant: " << th.status().total_redundant_bytes
<< std::endl;
// if test_ban is true, we're not supposed to have completed the download
// otherwise, we are supposed to have
TEST_CHECK(th.status().is_seeding == !test_ban);
if (proxy) stop_proxy(proxy_port);
th.flush_cache();
// synchronize to make sure the files have been created on disk
wait_for_alert(ses, cache_flushed_alert::alert_type, "ses");
print_alerts(ses, " >> ses", true, true, false, &on_alert, true);
if (!test_ban)
{
std::string first_file_path = combine_path(save_path, torrent_file->files().file_path(0));
fprintf(stderr, "checking file: %s\n", first_file_path.c_str());
TEST_CHECK(exists(first_file_path));
}
ses.remove_torrent(th);
remove_all(save_path, ec);
}