java libtorrent_基于libtorrent最简单的BT下载程序 | 学步园

java libtorrent_基于libtorrent最简单的BT下载程序 | 学步园libtorrent 测试程序 2010 04 27aya 创建 include include include include include include include include include include include include include include include include curl get h

/*

libtorrent 测试程序

2010-04-27 aya 创建

*/

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include “curl_get.h”

#include “curl_stack.h”

using namespace torrent;

using namespace core;

Poll* poll;

Object* object = NULL;

Download* download = NULL;

Object* createObjectFromTorrentFile (char* torrenFilePath);

Download* createDownloadObject (Object* object);

void tryCleanup ();

void recvShutdown (int s);

void

chunk_passed (Download* d) {

std::cout <

}

void

finished_download (Download* d) {

d->stop();

connection_manager()->listen_close();

}

void

hash_check_done (Download* d) {

std::cout << "Hash check completed." << std::endl;

d->start();

chunk_passed(d);

}

int main (int argc, char args)

{

core::CurlStack curlStack;

if (argc != 2) {

return 0;

}

std::cout <

signal (SIGINT, recvShutdown);

signal (SIGTERM, recvShutdown);

poll = PollEPoll::create (512); / 创建poll,供libtorrent使用/

CurlStack::global_init(); / 初始化curlstack /

Http::set_factory (curlStack.get_http_factory());

initialize (poll); / 初始化 /

/ 打开监听端口 /

if (!connection_manager()->listen_open(10000, 14000)) {

std::cout <

tryCleanup ();

return 0;

}

down_throttle_global ()->set_max_rate (0);

up_throttle_global ()->set_max_rate (16 * 1024);

/ 创建一个torrent 对象 /

object = createObjectFromTorrentFile (args[1]);

if (!object) {

std::cout <

tryCleanup ();

return 0;

}

/ 根据torrent 对象创建一个下载对象 /

download = createDownloadObject (object);

if (!download) {

std::cout <

tryCleanup ();

return 0;

}

download->info()->signal_initial_hash().connect (sigc::bind(sigc::ptr_fun(&hash_check_done), download));

download->info()->signal_download_done().connect (sigc::bind(sigc::ptr_fun(&finished_download), download));

download->open ();

download->hash_check (false);

std::cout <

while (1) {

perform();

rak::timer

timeout = next_timeout() + 1000;

static_cast(poll)->poll (timeout.usec()/1000);

curlStack.perform ();

torrent::perform ();

static_cast(poll)->perform ();

if (1024 > down_rate()->rate()) {

if (1024 > (download->bytes_done() / 1024)) {

std::cout


} else {

std::cout


}

} else {

if (1024 > (download->bytes_done() / 1024)) {

std::cout


} else {

std::cout


}

}

}

return 0;

}

void tryCleanup ()

{

download->stop();

connection_manager()->listen_close();

cleanup ();

core::CurlStack::global_cleanup();

delete poll;

if (download) {

delete download;

}

}

void recvShutdown (int s)

{

std::cout<

tryCleanup ();

signal (s, NULL);

raise (s);

}

Object* createObjectFromTorrentFile (char* torrenFilePath)

{

Object* obj;

std::fstream stream (torrenFilePath, std::ios::in | std::ios::binary);

if (!stream.is_open()) {

return NULL;

}

obj = new Object;

stream >> *obj;

if (!stream.good()) {

delete obj;

return NULL;

}

return obj;

}

Download* createDownloadObject (Object* object)

{

Download d = download_add(object);

return new Download (d);

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/221745.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 下午5:23
下一篇 2026年3月17日 下午5:23


相关推荐

  • OpenClaw部署保姆级教程:0元开通,1分钟搞定,小白也能轻松上手!

    OpenClaw部署保姆级教程:0元开通,1分钟搞定,小白也能轻松上手!

    2026年3月13日
    4
  • Kimi-VL—月之暗面开源轻量多模态视觉语言模型

    Kimi-VL—月之暗面开源轻量多模态视觉语言模型

    2026年3月12日
    2
  • java中int转string,string转int效率对比

    java中int转string,string转int效率对比string 转 int 两种方法 1 Interger parseInt String 2 Interger valueOf String intValue 第二种方法可以去看源码 实现了第一种方法 注释大概就是这样的意思 nbsp nbsp nbsp 返回一个包含整数的对象 nbsp nbsp nbsp 指定的 StringString 的值 这个说法是 nbsp nbsp nbsp 被解释为

    2026年3月26日
    2
  • ZUUL-API网关[通俗易懂]

    ZUUL-API网关[通俗易懂]更多干货 分布式实战(干货) springcloud实战(干货) mybatis实战(干货) springboot实战(干货) React入门实战(干货) 构建中小型互联网企业架构(干货) python学习持续更新 ElasticSearch笔记 kafkastorm实战(干货) …

    2022年8月15日
    8
  • 系统web服务器配置,简单介绍Web服务器的配置方法

    系统web服务器配置,简单介绍Web服务器的配置方法关于 Web 服务器的配置方法如果不说的具体一些的话 恐怕一些不是高手的用户就会比较难懂 因此本教程就结合实例给大家说说吧 近日 笔者将学校服务器的操作系统升级为 WindowsServe 在 Web 服务器的配置过程中发现了许多与 windows2000S 的不同之处 为了同行少走弯路 现将配置中应注意的问题简单总结如下 WindowsServe 中 Internet

    2026年3月18日
    1
  • Java字符串匹配_获取字符串

    Java字符串匹配_获取字符串文章目录一、示例二、解释1.replace()方法2.replaceAll()方法3.replaceFirst()方法4.常用的字符列表一、示例如图,都是为了替换字符串s中的”(“符号,但三种匹配方法,有三种不同的效果及写法。二、解释1.replace()方法replace()方法没有用到正则表达式,但会匹配所有的参数并进行替换2.replaceAll()方法replaceAll()方法使用的是正则表达式来匹配,而括号在正则表达式中是特殊字符,所以需要用双斜杠来进行转义,同时会匹配所..

    2022年8月21日
    8

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号