diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-09-02 22:30:24 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-09-02 22:30:24 -0400 |
| commit | 60d1d5cdee642ee9d5be7e91be5caeb9a1a756df (patch) | |
| tree | 67dcd2270977afafc596a1c4568cdaa4cf9d26dc /MediaBrowser.Server.Implementations/HttpServer/ThrottledStream.cs | |
| parent | a3d553a7fbe93fe416c940e80d5e511a2d753f25 (diff) | |
restore nuget targets for mono build
Diffstat (limited to 'MediaBrowser.Server.Implementations/HttpServer/ThrottledStream.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/HttpServer/ThrottledStream.cs | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/MediaBrowser.Server.Implementations/HttpServer/ThrottledStream.cs b/MediaBrowser.Server.Implementations/HttpServer/ThrottledStream.cs index 067e53571..4bde30dac 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/ThrottledStream.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/ThrottledStream.cs @@ -15,6 +15,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// </summary> public const long Infinite = 0; + public Func<long, long, long> ThrottleCallback { get; set; } + #region Private members /// <summary> /// The base stream. @@ -278,22 +280,42 @@ namespace MediaBrowser.Server.Implementations.HttpServer } #endregion - #region Protected methods - /// <summary> - /// Throttles for the specified buffer size in bytes. - /// </summary> - /// <param name="bufferSizeInBytes">The buffer size in bytes.</param> - protected void Throttle(int bufferSizeInBytes) + private bool ThrottleCheck(int bufferSizeInBytes) { if (_bytesWritten < MinThrottlePosition) { - return; + return false; } // Make sure the buffer isn't empty. if (_maximumBytesPerSecond <= 0 || bufferSizeInBytes <= 0) { - return; + return false; + } + + if (ThrottleCallback != null) + { + var val = ThrottleCallback(_maximumBytesPerSecond, _bytesWritten); + + if (val == 0) + { + return false; + } + } + + return true; + } + + #region Protected methods + /// <summary> + /// Throttles for the specified buffer size in bytes. + /// </summary> + /// <param name="bufferSizeInBytes">The buffer size in bytes.</param> + protected void Throttle(int bufferSizeInBytes) + { + if (!ThrottleCheck(bufferSizeInBytes)) + { + return ; } _byteCount += bufferSizeInBytes; @@ -332,13 +354,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer protected async Task ThrottleAsync(int bufferSizeInBytes, CancellationToken cancellationToken) { - if (_bytesWritten < MinThrottlePosition) - { - return; - } - - // Make sure the buffer isn't empty. - if (_maximumBytesPerSecond <= 0 || bufferSizeInBytes <= 0) + if (!ThrottleCheck(bufferSizeInBytes)) { return; } |
