Author: alanmc
Date: 2007-04-01 16:03:11 -0400 (Sun, 01 Apr 2007)
New Revision: 75266

Modified:
   trunk/bitsharp/src/MonoTorrent.Client/PeerMessages/PieceMessage.cs
Log:
Updated to remove dependance on the current receive buffer.

Modified: trunk/bitsharp/src/MonoTorrent.Client/PeerMessages/PieceMessage.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/PeerMessages/PieceMessage.cs  
2007-04-01 19:55:12 UTC (rev 75265)
+++ trunk/bitsharp/src/MonoTorrent.Client/PeerMessages/PieceMessage.cs  
2007-04-01 20:03:11 UTC (rev 75266)
@@ -48,6 +48,8 @@
         private int pieceIndex;
         private int startOffset;
         private int blockLength;
+
+               private byte[] data;
         #endregion
 
         #region Properties
@@ -156,6 +158,10 @@
             this.blockLength = length - offset;
 
             this.dataOffset = offset;
+
+                       this.data = BufferManager.EmptyBuffer;
+                       ClientEngine.BufferManager.GetBuffer(ref this.data, 
buffer.Length);
+                       Buffer.BlockCopy(buffer, 0, this.data, 0, 
buffer.Length);
         }
 
 
@@ -242,9 +248,17 @@
         /// <param name="id">The Peer who's message will be handled</param>
         internal void Handle(PeerConnectionID id)
         {
-            id.TorrentManager.PieceManager.ReceivedPieceMessage(id, 
id.Peer.Connection.recieveBuffer, this);
-            // Keep adding new piece requests to this peers queue until we 
reach the max pieces we're allowed queue
-            while (id.TorrentManager.AddPieceRequest(id)) { }
+                       try
+                       {
+                               
id.TorrentManager.PieceManager.ReceivedPieceMessage(id, this.data, this);
+
+                               // Keep adding new piece requests to this peers 
queue until we reach the max pieces we're allowed queue
+                               while (id.TorrentManager.AddPieceRequest(id)) { 
}
+                       }
+                       finally
+                       {
+                               ClientEngine.BufferManager.FreeBuffer(ref 
this.data);
+                       }
         }
 
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to