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


C# PeerId.TryProcessAsyncReads方法代码示例

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


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

示例1: HandleRequestMessage

        protected virtual void HandleRequestMessage(PeerId id, RequestMessage message)
        {
            // If we are not on the last piece and the user requested a stupidly big/small amount of data
            // we will close the connection
            if (manager.Torrent.Pieces.Count != (message.PieceIndex + 1))
                if (message.RequestLength > RequestMessage.MaxSize || message.RequestLength < RequestMessage.MinSize)
                    throw new MessageException("Illegal piece request received. Peer requested " + message.RequestLength.ToString() + " byte");

            PieceMessage m = new PieceMessage(message.PieceIndex, message.StartOffset, message.RequestLength);

            // If we're not choking the peer, enqueue the message right away
            if (!id.AmChoking)
            {
                id.IsRequestingPiecesCount++;
                id.PieceReads.Add(m);
                id.TryProcessAsyncReads();
            }

            // If the peer supports fast peer and the requested piece is one of the allowed pieces, enqueue it
            // otherwise send back a reject request message
            else if (id.SupportsFastPeer && ClientEngine.SupportsFastPeer)
            {
                if (id.AmAllowedFastPieces.Contains(message.PieceIndex))
                {
                    id.IsRequestingPiecesCount++;
                    id.PieceReads.Add(m);
                    id.TryProcessAsyncReads();
                }
                else
                    id.Enqueue(new RejectRequestMessage(m));
            }
        }
开发者ID:Cyarix,项目名称:monotorrent,代码行数:32,代码来源:Mode.cs


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