コード例 #1
0
        private void ProcessUploads()
        {
            if (Interlocked.Exchange(ref _isProcessUploads, 1) == 1)
            {
                return;
            }

            while (!_uploadThrottle.IsThrottled && _outgoingBlocks.TryDequeue(out var block))
            {
                if (block.IsCancelled)
                {
                    continue;
                }

                if (!Torrent.IsPieceVerified[block.Piece])
                {
                    continue;
                }

                byte[] data = Torrent.ReadBlock(block.Piece, block.Begin, block.Length);
                if (data == null)
                {
                    continue;
                }

                block.Peer.SendPiece(block.Piece, block.Begin, data);
                _uploadThrottle.Add(block.Length);
                Torrent.Uploaded += block.Length;
            }

            Interlocked.Exchange(ref _isProcessUploads, 0);
        }