當前位置: 首頁>>代碼示例>>C#>>正文


C# PeerId.Dequeue方法代碼示例

本文整理匯總了C#中MonoTorrent.Client.PeerId.Dequeue方法的典型用法代碼示例。如果您正苦於以下問題:C# PeerId.Dequeue方法的具體用法?C# PeerId.Dequeue怎麽用?C# PeerId.Dequeue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MonoTorrent.Client.PeerId的用法示例。


在下文中一共展示了PeerId.Dequeue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ProcessQueue

        /// <param name="id">The peer whose message queue you want to start processing</param>
        internal void ProcessQueue(PeerId id)
        {
            if (id.QueueLength == 0)
            {
                id.ProcessingQueue = false;
                return;
            }

            PeerMessage msg = id.Dequeue();
            if (msg is PieceMessage)
            {
                using (ManualResetEvent handle = new ManualResetEvent(false)) {
                    PieceMessage pm = (PieceMessage)msg;
                    pm.Data = BufferManager.EmptyBuffer;
                    ClientEngine.BufferManager.GetBuffer(ref pm.Data, pm.ByteLength);
                    engine.DiskManager.QueueRead(id.TorrentManager, pm.StartOffset + ((long) pm.PieceIndex * id.TorrentManager.Torrent.PieceLength), pm.Data, pm.RequestLength, delegate
                    {
                        handle.Set();
                    });
                    handle.WaitOne();
                    id.PiecesSent++;
                }
            }
            try
            {
                SendMessage(id, msg, this.messageSentCallback);
            }
            catch (Exception e)
            {
                CleanupSocket(id, "Exception calling SendMessage: " + e.Message);
            }
        }
開發者ID:fallaciousreasoning,項目名稱:monotorrent,代碼行數:33,代碼來源:ConnectionManager.cs

示例2: RejectPendingRequests

        /// <summary>
        /// Checks the send queue of the peer to see if there are any outstanding pieces which they requested
        /// and rejects them as necessary
        /// </summary>
        /// <param name="Peer"></param>
        private void RejectPendingRequests(PeerId Peer)
        {
            PeerMessage message;
            PieceMessage pieceMessage;
            int length = Peer.QueueLength;

            for (int i = 0; i < length; i++)
            {
                message = Peer.Dequeue();
                if (!(message is PieceMessage))
                {
                    Peer.Enqueue(message);
                    continue;
                }

                pieceMessage = (PieceMessage)message;

                // If the peer doesn't support fast peer, then we will never requeue the message
                if (!(Peer.SupportsFastPeer && ClientEngine.SupportsFastPeer))
                {
                    Peer.IsRequestingPiecesCount--;
                    continue;
                }

                // If the peer supports fast peer, queue the message if it is an AllowedFast piece
                // Otherwise send a reject message for the piece
                if (Peer.AmAllowedFastPieces.Contains(pieceMessage.PieceIndex))
                    Peer.Enqueue(pieceMessage);
                else
                {
                    Peer.IsRequestingPiecesCount--;
                    Peer.Enqueue(new RejectRequestMessage(pieceMessage));
                }
            }
        }
開發者ID:burris,項目名稱:monotorrent,代碼行數:40,代碼來源:ChokeUnchokeManager.cs

示例3: HandleCancelMessage

        protected virtual void HandleCancelMessage(PeerId id, CancelMessage message)
        {
            PeerMessage msg;
            for (int i = 0; i < id.QueueLength; i++)
            {
                msg = id.Dequeue();
                if (!(msg is PieceMessage))
                {
                    id.Enqueue(msg);
                    continue;
                }

                PieceMessage piece = msg as PieceMessage;
                if (!(piece.PieceIndex == message.PieceIndex && piece.StartOffset == message.StartOffset && piece.RequestLength == message.RequestLength))
                {
                    id.Enqueue(msg);
                }
                else
                {
                    id.IsRequestingPiecesCount--;
                }
            }

            for (int i = 0; i < id.PieceReads.Count; i++)
            {
                if (id.PieceReads[i].PieceIndex == message.PieceIndex && id.PieceReads[i].StartOffset == message.StartOffset && id.PieceReads[i].RequestLength == message.RequestLength)
                {
                    id.IsRequestingPiecesCount--;
                    id.PieceReads.RemoveAt(i);
                    break;
                }
            }
        }
開發者ID:Cyarix,項目名稱:monotorrent,代碼行數:33,代碼來源:Mode.cs

示例4: ProcessQueue

        /// <summary>
        /// This method should be called to begin processing messages stored in the SendQueue
        /// </summary>
        /// <param name="id">The peer whose message queue you want to start processing</param>
        internal void ProcessQueue(PeerId id)
        {
            if (id.QueueLength == 0)
            {
                id.ProcessingQueue = false;
                return;
            }

            PeerMessage msg = id.Dequeue();
            if (msg is PieceMessage)
                id.PiecesSent++;

            try
            {
                SendMessage(id, msg, this.messageSentCallback);
            }
            catch (Exception e)
            {
                CleanupSocket(id, "Exception calling SendMessage: " + e.Message);
            }
        }
開發者ID:burris,項目名稱:monotorrent,代碼行數:25,代碼來源:ConnectionManager.cs


注:本文中的MonoTorrent.Client.PeerId.Dequeue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。