A Throttle limits the download and/or upload speed of all its Connections to given values. The Throttle will adjust the buffersize of the Connection'str read- and write-buffer, according to the given speed limits. When throttling is discontinued the Throttle will reset the buffersizes to its default values: Connection.DefaultReceiveBufferSize and Connection.DefaultReceiveSendSize
Example #1
0
 internal void SetThrottle(Throttle newThrottle)
 {
     if (newThrottle != null)
     {
         if (throttle != null)
             throw new InvalidOperationException("Connection can only be throttled by one Throttle at a time.");
         throttle = newThrottle;
     }
     else
         throttle = null;
 }
Example #2
0
 /// <summary>
 /// Adds and returns a new SetThrottle which will restrict the total upload speed of all its connections
 /// to the given value.
 /// <param name="cons">Initial connections of the new throttle.</param>
 /// </summary>
 public static Throttle AddUploadThrottle(int maxUpBps, params Connection[] cons)
 {
     var throttle = new Throttle(ThrottleType.Up, cons);
     throttle.MaxUploadSpeed = maxUpBps;
     Add(throttle);
     return throttle;
 }
Example #3
0
 /// <summary>
 /// Removes the given Throttle or does nothing if its not Active.
 /// </summary>
 public static void Remove(Throttle throttle)
 {
     Remove(throttles.IndexOf(throttle));
 }
Example #4
0
 /// <summary>
 /// Adds a new Throttle.
 /// </summary>
 public static void Add(Throttle throttle)
 {
     lock (pollLock)
     {
         throttle.Active = true;
         throttles.Add(throttle);
     }
 }