Author: alanmc
Date: 2006-10-27 11:09:15 -0400 (Fri, 27 Oct 2006)
New Revision: 67030

Modified:
   trunk/bitsharp/src/MonoTorrent.Client/Managers/BufferManager.cs
   trunk/bitsharp/src/MonoTorrent.Client/Managers/ConnectionManager.cs
   trunk/bitsharp/src/MonoTorrent.Client/Managers/TorrentManager.cs
Log:
2 more threading issues fixed. Also buffermanager temporarily disabled due to 
bug i can't trace. Download speeds should now be back to normal (ish).

Modified: trunk/bitsharp/src/MonoTorrent.Client/Managers/BufferManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/Managers/BufferManager.cs     
2006-10-27 15:06:43 UTC (rev 67029)
+++ trunk/bitsharp/src/MonoTorrent.Client/Managers/BufferManager.cs     
2006-10-27 15:09:15 UTC (rev 67030)
@@ -37,7 +37,10 @@
                         return new byte[SmallMessageBufferSize];
                     }
                     else
+                    {
+                        return new byte[SmallMessageBufferSize];
                         return this.smallMessageBuffers.Dequeue();
+                    }
                 }
 
             else if (type == BufferType.LargeMessageBuffer)
@@ -49,7 +52,10 @@
                         return new byte[LargeMessageBufferSize];
                     }
                     else
+                    {
+                        return new byte[LargeMessageBufferSize];
                         return this.largeMessageBuffers.Dequeue();
+                    }
                 }
 
             else
@@ -59,6 +65,9 @@
 
         public void FreeBuffer(byte[] buffer)
         {
+            buffer = null;
+            return;
+
             if (buffer == null)
                 return;
 

Modified: trunk/bitsharp/src/MonoTorrent.Client/Managers/ConnectionManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/Managers/ConnectionManager.cs 
2006-10-27 15:06:43 UTC (rev 67029)
+++ trunk/bitsharp/src/MonoTorrent.Client/Managers/ConnectionManager.cs 
2006-10-27 15:09:15 UTC (rev 67030)
@@ -269,6 +269,7 @@
 
             try
             {
+                lock(id.TorrentManager.listLock)
                 lock (id)
                 {
                     if (id.Peer.Connection == null)
@@ -425,6 +426,7 @@
 
             try
             {
+                lock(id.TorrentManager.listLock)
                 lock (id)
                 {
                     if (id.Peer.Connection == null)
@@ -536,9 +538,10 @@
                         else
                         {
 
-                            id.TorrentManager.downloadQueue.Enqueue(id);
+                            //id.TorrentManager.downloadQueue.Enqueue(id);
                             //int bytesRemaining = 
(id.Peer.Connection.BytesToRecieve - id.Peer.Connection.BytesRecieved) > 
ChunkLength ? ChunkLength : (id.Peer.Connection.BytesToRecieve - 
id.Peer.Connection.BytesRecieved);
-                            
//id.Peer.Connection.BeginReceive(id.Peer.Connection.recieveBuffer, 0, 
bytesRemaining, SocketFlags.None, peerMessageRecieved, id);
+                            
+                            
id.Peer.Connection.BeginReceive(id.Peer.Connection.recieveBuffer, 0, 
id.Peer.Connection.BytesToRecieve - id.Peer.Connection.BytesRecieved, 
SocketFlags.None, peerMessageRecieved, id, out id.ErrorCode);
                         }
                     }
             }
@@ -595,13 +598,17 @@
 
                         if (id.Peer.Connection.BytesRecieved != 
id.Peer.Connection.BytesToRecieve)
                         {
-
-                            id.TorrentManager.downloadQueue.Enqueue(id);
-
+                            
id.Peer.Connection.BeginReceive(id.Peer.Connection.recieveBuffer,
+                                                            
id.Peer.Connection.BytesRecieved,
+                                                            
id.Peer.Connection.BytesToRecieve - id.Peer.Connection.BytesRecieved,
+                                                            SocketFlags.None,
+                                                            
this.peerMessageRecieved, id, out id.ErrorCode);
                             return;
+                            //id.TorrentManager.downloadQueue.Enqueue(id);
+                            return;
                         }
 
-                        IPeerMessage message = 
PeerwireEncoder.Decode(id.Peer.Connection.recieveBuffer, 0, 
id.Peer.Connection.BytesRecieved, id.TorrentManager);
+                        IPeerMessage message = 
PeerwireEncoder.Decode(id.Peer.Connection.recieveBuffer, 0, 
id.Peer.Connection.BytesToRecieve, id.TorrentManager);
                         if (this.OnPeerMessages != null)
                             this.OnPeerMessages(id, new 
PeerMessageEventArgs(message, Direction.Incoming));
                         message.Handle(id); // FIXME: Is everything threadsafe 
here? Well, i know it isn't :p
@@ -637,7 +644,7 @@
 #warning should be unneccessary
                 cleanUp = true;
             }
-            catch
+            catch(Exception ex)
             {
 #warning remove this.
                 cleanUp = true;
@@ -689,8 +696,12 @@
 
                         if (id.Peer.Connection.BytesSent != 
id.Peer.Connection.BytesToSend)
                         {
-
-                            id.TorrentManager.uploadQueue.Enqueue(id);
+                            
id.Peer.Connection.BeginSend(id.Peer.Connection.sendBuffer,
+                                                        
id.Peer.Connection.BytesSent,
+                                                        
id.Peer.Connection.BytesToSend - id.Peer.Connection.BytesSent,
+                                                        SocketFlags.None,
+                                                        this.peerMessageSent, 
id, out id.ErrorCode);
+                            //id.TorrentManager.uploadQueue.Enqueue(id);
                             return;
                         }
 
@@ -749,7 +760,12 @@
                 id.Peer.Connection.BytesSent = 0;
                 id.Peer.Connection.BytesToSend = 
msg.Encode(id.Peer.Connection.sendBuffer, 0);
                 id.Peer.Connection.CurrentlySendingMessage = msg;
-                id.TorrentManager.uploadQueue.Enqueue(id);
+                id.Peer.Connection.BeginSend(id.Peer.Connection.sendBuffer,
+                                            id.Peer.Connection.BytesSent,
+                                            id.Peer.Connection.BytesToSend,
+                                            SocketFlags.None,
+                                            this.peerMessageSent, id, out 
id.ErrorCode);
+                //id.TorrentManager.uploadQueue.Enqueue(id);
             }
             catch (SocketException ex)
             {

Modified: trunk/bitsharp/src/MonoTorrent.Client/Managers/TorrentManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/Managers/TorrentManager.cs    
2006-10-27 15:06:43 UTC (rev 67029)
+++ trunk/bitsharp/src/MonoTorrent.Client/Managers/TorrentManager.cs    
2006-10-27 15:09:15 UTC (rev 67030)
@@ -66,8 +66,8 @@
 
 
         #region Member Variables
-        internal Queue<PeerConnectionID> downloadQueue;
-        internal Queue<PeerConnectionID> uploadQueue;
+        //internal Queue<PeerConnectionID> downloadQueue;
+        //internal Queue<PeerConnectionID> uploadQueue;
 
 
         /// <summary>
@@ -271,8 +271,8 @@
 
             this.connectedPeers = new Peers(16);
             this.available = new Peers(16);
-            this.uploadQueue = new Queue<PeerConnectionID>(16);
-            this.downloadQueue = new Queue<PeerConnectionID>(16);
+            //this.uploadQueue = new Queue<PeerConnectionID>(16);
+            //this.downloadQueue = new Queue<PeerConnectionID>(16);
             this.connectingTo = new 
Peers(ClientEngine.connectionManager.MaxHalfOpenConnections);
 
             this.savePath = savePath;
@@ -411,8 +411,8 @@
 
             this.SaveFastResume();
 
-            this.downloadQueue.Clear();
-            this.uploadQueue.Clear();
+            //this.downloadQueue.Clear();
+            //this.uploadQueue.Clear();
             this.connectedPeers = new Peers();
             this.available = new Peers();
             this.connectingTo = new Peers();
@@ -452,11 +452,11 @@
                     lock (this.connectedPeers[i])
                         
ClientEngine.connectionManager.CleanupSocket(this.connectedPeers[i]);
 
-                lock (this.listLock)
-                    this.downloadQueue.Clear();
+                //lock (this.listLock)
+                //    this.downloadQueue.Clear();
 
-                lock (this.listLock)
-                    this.uploadQueue.Clear();
+                //lock (this.listLock)
+                //    this.uploadQueue.Clear();
 
                 this.SaveFastResume();
             }
@@ -472,25 +472,25 @@
             //if (this.state == TorrentState.Downloading && this.Progress() == 
100.0)
             //    this.state = TorrentState.Seeding;
 
-            lock (this.listLock)
-            {
-                if (this.settings.MaxDownloadSpeed > 0)
-                    while ((this.DownloadSpeed() < 
this.settings.MaxDownloadSpeed * 1024) && this.downloadQueue.Count > 0)
-                        
ClientEngine.connectionManager.ResumePeer(this.downloadQueue.Dequeue(), true);
-                else
-                    while (this.downloadQueue.Count > 0)
-                        
ClientEngine.connectionManager.ResumePeer(this.downloadQueue.Dequeue(), true);
-            }
+            //lock (this.listLock)
+            //{
+                //if (this.settings.MaxDownloadSpeed > 0)
+                //    while ((this.DownloadSpeed() < 
this.settings.MaxDownloadSpeed * 1024) && this.downloadQueue.Count > 0)
+                //        
ClientEngine.connectionManager.ResumePeer(this.downloadQueue.Dequeue(), true);
+                //else
+                //    while (this.downloadQueue.Count > 0)
+                //        
ClientEngine.connectionManager.ResumePeer(this.downloadQueue.Dequeue(), true);
+            //}
 
-            lock (this.listLock)
-            {
-                if (this.settings.MaxUploadSpeed > 0)
-                    while ((this.UploadSpeed() < this.settings.MaxUploadSpeed 
* 1024) && (this.uploadQueue.Count > 0))
-                        
ClientEngine.connectionManager.ResumePeer(this.uploadQueue.Dequeue(), false);
-                else
-                    while (this.uploadQueue.Count > 0)
-                        
ClientEngine.connectionManager.ResumePeer(this.uploadQueue.Dequeue(), false);
-            }
+            //lock (this.listLock)
+            //{
+            //    if (this.settings.MaxUploadSpeed > 0)
+            //        while ((this.UploadSpeed() < 
this.settings.MaxUploadSpeed * 1024) && (this.uploadQueue.Count > 0))
+            //            
ClientEngine.connectionManager.ResumePeer(this.uploadQueue.Dequeue(), false);
+            //    else
+            //        while (this.uploadQueue.Count > 0)
+            //            
ClientEngine.connectionManager.ResumePeer(this.uploadQueue.Dequeue(), false);
+            //}
 
             lock (this.listLock)
             {
@@ -560,10 +560,10 @@
                         while (!id.Peer.Connection.IsChoking && 
id.Peer.Connection.AmRequestingPiecesCount < 6 && 
id.Peer.Connection.AmInterested)
                         {
                             msg = this.pieceManager.PickPiece(id, 
this.connectedPeers);
-                            
Console.WriteLine(((RequestMessage)msg).PieceIndex.ToString() + " - " + 
((RequestMessage)msg).StartOffset.ToString());
                             if (msg == null)
                                 break;
 
+                            
Console.WriteLine(((RequestMessage)msg).PieceIndex.ToString() + " - " + 
((RequestMessage)msg).StartOffset.ToString());
                             id.Peer.Connection.EnQueue(msg);
                             id.Peer.Connection.AmRequestingPiecesCount++;
                         }

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

Reply via email to