Author: alanmc
Date: 2008-01-03 12:09:49 -0500 (Thu, 03 Jan 2008)
New Revision: 92191

Modified:
   trunk/bitsharp/src/MonoTorrent/Client/ClientEngine.cs
   trunk/bitsharp/src/MonoTorrent/Client/Managers/DiskManager.cs
   trunk/bitsharp/src/MonoTorrent/Client/Settings/EngineSettings.cs
Log:
Moved the settings from diskmanager to EngineSettings. Correctly handling the 
case where the limits are 0.

Modified: trunk/bitsharp/src/MonoTorrent/Client/ClientEngine.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/ClientEngine.cs       2008-01-03 
16:58:11 UTC (rev 92190)
+++ trunk/bitsharp/src/MonoTorrent/Client/ClientEngine.cs       2008-01-03 
17:09:49 UTC (rev 92191)
@@ -416,8 +416,8 @@
             if (tickCount % (1000 / TickLength) == 0)
             {
                 diskManager.Monitor.TimePeriodPassed();
-                
diskManager.rateLimiter.UpdateDownloadChunks((int)(diskManager.MaxWriteRate * 
1024),
-                                                             
(int)(diskManager.MaxReadRate * 1024),
+                
diskManager.rateLimiter.UpdateDownloadChunks((int)(settings.MaxWriteRate * 
1024),
+                                                             
(int)(settings.MaxReadRate * 1024),
                                                              
(int)(diskManager.WriteRate * 1024),
                                                              
(int)(diskManager.ReadRate * 1024));
             }

Modified: trunk/bitsharp/src/MonoTorrent/Client/Managers/DiskManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/Managers/DiskManager.cs       
2008-01-03 16:58:11 UTC (rev 92190)
+++ trunk/bitsharp/src/MonoTorrent/Client/Managers/DiskManager.cs       
2008-01-03 17:09:49 UTC (rev 92191)
@@ -16,9 +16,7 @@
         Queue<BufferedFileRead> bufferedReads;
         Queue<BufferedIO> bufferedWrites;
         private ClientEngine engine;
-        private int maxOpenStreams;
-        private int maxReadRate;
-        private int maxWriteRate;
+
         private ConnectionMonitor monitor;
         internal RateLimiter rateLimiter;
         private int openStreams;
@@ -46,24 +44,6 @@
             get { return monitor; }
         }
 
-        public int MaxOpenStreams
-        {
-            get { return maxOpenStreams; }
-            set { maxOpenStreams = value; }
-        }
-
-        public int MaxReadRate
-        {
-            get { return maxReadRate; }
-            set { maxReadRate = value; }
-        }
-
-        public int MaxWriteRate
-        {
-            get { return maxWriteRate; }
-            set { maxWriteRate = value; }
-        }
-
         public int OpenFiles
         {
             get { return openStreams; }
@@ -106,7 +86,6 @@
             this.rateLimiter = new RateLimiter();
             this.streamsLock = new ReaderWriterLock();
             this.threadWait = new ManualResetEvent(false);
-            this.MaxReadRate = 1000;
             this.ioThread.Start();
         }
 
@@ -389,13 +368,13 @@
                 // performing the actual read/write to avoid blocking other 
threads
                 lock (this.queueLock)
                 {
-                    if (this.bufferedWrites.Count > 0 && 
(rateLimiter.DownloadChunks > 0))
+                    if (this.bufferedWrites.Count > 0 && 
(engine.Settings.MaxWriteRate == 0 || rateLimiter.DownloadChunks > 0))
                     {
                         write = this.bufferedWrites.Dequeue();
                         Interlocked.Add(ref rateLimiter.DownloadChunks, 
-write.Buffer.Count / ConnectionManager.ChunkLength);
                     }
 
-                    if (this.bufferedReads.Count > 0 && 
(rateLimiter.UploadChunks > 0))
+                    if (this.bufferedReads.Count > 0 && 
(engine.Settings.MaxReadRate == 0 || rateLimiter.UploadChunks > 0))
                     {
                         read = this.bufferedReads.Dequeue();
                         Interlocked.Add(ref rateLimiter.UploadChunks, 
-read.Count / ConnectionManager.ChunkLength);

Modified: trunk/bitsharp/src/MonoTorrent/Client/Settings/EngineSettings.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/Settings/EngineSettings.cs    
2008-01-03 16:58:11 UTC (rev 92190)
+++ trunk/bitsharp/src/MonoTorrent/Client/Settings/EngineSettings.cs    
2008-01-03 17:09:49 UTC (rev 92191)
@@ -50,6 +50,9 @@
         private int globalMaxHalfOpenConnections;       // The maximum number 
of simultaenous 1/2 open connections
         private int globalMaxDownloadSpeed;             // The maximum 
combined download speed
         private int globalMaxUploadSpeed;               // The maximum 
combined upload speed
+        private int maxOpenStreams;                     // The maximum number 
of simultaenous open filestreams
+        private int maxReadRate;                        // The maximum read 
rate from the harddisk (for all active torrentmanagers)
+        private int maxWriteRate;                       // The maximum write 
rate to the harddisk (for all active torrentmanagers)
         private string savePath;                        // The path that 
torrents will be downloaded to by default
 
         #endregion Private Fields
@@ -130,6 +133,36 @@
 
 
         /// <summary>
+        /// The maximum number of files which can be opened at the same time
+        /// </summary>
+        public int MaxOpenFiles
+        {
+            get { return maxOpenStreams; }
+            set { maxOpenStreams = value; }
+        }
+
+
+        /// <summary>
+        /// The maximum read rate from the hard disk
+        /// </summary>
+        public int MaxReadRate
+        {
+            get { return maxReadRate; }
+            set { maxReadRate = value; }
+        }
+
+
+        /// <summary>
+        /// The maximum write rate to the hard disk
+        /// </summary>
+        public int MaxWriteRate
+        {
+            get { return maxWriteRate; }
+            set { maxWriteRate = value; }
+        }
+
+
+        /// <summary>
         /// Specifies the minimum encryption level to use for outgoing 
connections.
         /// </summary>
         public EncryptionType MinEncryptionLevel

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

Reply via email to