Fix bug in ThrottledStream.Write method.

Prior to revision 0190a9994e ("Rewrote the throttling implementation to
be more effecient"), the DelayIfRequired method would increment the
offset variable to advance through the buffer.  When we modified the
implementation in revision 0190a9994e, we may have forgotten to modify
the offset accordingly.
This commit is contained in:
Kenneth Hsu
2019-07-07 17:16:58 -07:00
parent c721d16151
commit 5d087791d0
+4 -3
View File
@@ -153,7 +153,8 @@ namespace Duplicati.Library.Utility
/// <param name="offset">The offset into the buffer.</param>
/// <param name="count">The number of bytes to write.</param>
public override void Write(byte[] buffer, int offset, int count)
{
{
int bytesWritten = 0;
while (count > 0)
{
// To avoid excessive waiting, the delay will wait at most 2 seconds,
@@ -161,10 +162,10 @@ namespace Duplicati.Library.Utility
UpdateLimits();
var chunksize = (int)Math.Min(count, m_writespeed <= 0 ? count : m_writespeed * 2);
DelayIfRequired(ref m_writespeed, chunksize, ref m_last_write_sample, ref m_current_write_counter, ref m_current_write_speed);
m_basestream.Write(buffer, offset, chunksize);
m_basestream.Write(buffer, offset + bytesWritten, chunksize);
m_current_write_counter += chunksize;
bytesWritten += chunksize;
count -= chunksize;
}
}