Пример #1
0
 private void m_ProcessReceivedBlock(CReceivedBlock receivedBlock)
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("ProcessReceivedBlock",m_ID);
     #endif
     int blockIndex=0;
     CFileBlock block;
     //CElement Element=(CElement)CKernel.FilesList[CKernel.HashToString(DownFileHash)];
     CKernel.GlobalStatistics.IncSessionDown(receivedBlock.Data.Length);
     lock (m_DownloadBlocks)
     {
     while (blockIndex<m_DownloadBlocks.Count)
     {
         block=(CFileBlock)m_DownloadBlocks[blockIndex];
         if ((block.start<=receivedBlock.Start)&&(block.end+1>=receivedBlock.End))
         {
             if (block.buffer==null)
             {
                 block.buffer=new Byte[block.end+1-block.start];
             }
             block.position=receivedBlock.End;
             Buffer.BlockCopy(receivedBlock.Data,0,block.buffer,(int)(receivedBlock.Start-block.start),(int)(receivedBlock.End-receivedBlock.Start));
             if (block.end+1==receivedBlock.End)
             {
                 receivedBlock.Data=null;
                 receivedBlock=null;
                 if (!m_DownloadElement.File.WriteBlock(block.start,block.end,block.buffer))
                 {
                     m_DownloadElement.File.RemoveRequestedBlock(block.start,block.end);
                     CKernel.FilesList.StopFile(m_DownloadElement.File.FileHash);
                 }
                 m_DownloadElement.Statistics.IncSessionDownload(block.end-block.start+1);
                 block.buffer=null;
                 block=null;
                 if (m_DownloadBlocks.Count>0)
                 {
                     m_DownloadBlocks.RemoveAt(blockIndex);
                 }
                 //Debug.WriteLine(GC.GetTotalMemory(true).ToString());
                 //GC.Collect();
                 if ((m_DownloadBlocks.Count<4)
                         && (m_DownloadState==Protocol.DownloadState.Downloading)
                         && (m_DownloadElement.File.FileStatus==Protocol.FileState.Ready))
                 {
                     RequestBlocks();
                 }
             }
             break;
         }
         blockIndex++;
     }
     //              if (blockIndex==m_DownloadBlocks.Count)
     //              {
     //                  CLog.Log(Constants.Log.Verbose,"Requested part not found");
     //              }
     }
 }
Пример #2
0
 public void ReceiveBlock(byte[] packet)
 {
     #if VERBOSE
     CKernel.LogClient.AddLog("ReceiveBlock",m_ID);
     #endif
     MemoryStream streamPacket=new MemoryStream(packet);
     CReceivedBlock receivedBlock=new CReceivedBlock(streamPacket);
     streamPacket=null;
     m_DownloadedBytes+=receivedBlock.End-receivedBlock.Start;
     if (m_DownloadBlocks.Count<=0) return;
     if (!CKernel.SameHash(ref DownFileHash,ref receivedBlock.FileHash)) return;
     m_ProcessReceivedBlock(receivedBlock);
 }