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; }
/// <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; }
/// <summary> /// Removes the given Throttle or does nothing if its not Active. /// </summary> public static void Remove(Throttle throttle) { Remove(throttles.IndexOf(throttle)); }
/// <summary> /// Adds a new Throttle. /// </summary> public static void Add(Throttle throttle) { lock (pollLock) { throttle.Active = true; throttles.Add(throttle); } }