本文整理汇总了C#中Core.have_piece方法的典型用法代码示例。如果您正苦于以下问题:C# Core.have_piece方法的具体用法?C# Core.have_piece怎么用?C# Core.have_piece使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core
的用法示例。
在下文中一共展示了Core.have_piece方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StreamTorrent
public static void StreamTorrent(Core.TorrentHandle handle, int fileIndex)
{
var ti = handle.torrent_file();
var files = ti.files();
if(fileIndex < 0 || fileIndex > files.num_files())
{
throw new ArgumentOutOfRangeException();
}
var fileEntry = files.at(fileIndex);
var peer_req = ti.map_file(fileIndex, 0, 1048576);
var startPiece = peer_req.piece;
var piece_length = ti.piece_length();
var num_pieces = (int)Math.Ceiling((double)(fileEntry.size / piece_length));
var end_piece = Math.Min(startPiece + num_pieces, ti.num_pieces() - 1);
for (int i = startPiece; i < end_piece; i++)
handle.piece_priority(i,0);
//set first piece with higher priority
handle.piece_priority(startPiece, 7);
var lastPiece = startPiece;
start_window = startPiece;
end_window = Math.Min(end_window, lastPiece);
for (int i = start_window; i <= end_window; i++)
handle.piece_priority(i, 1);
while (start_window <= end_window)
{
if (handle.have_piece(start_window))
{
handle.piece_priority(++start_window, 7);
continue;
}
Thread.Sleep(200);
}
}