Because the activity on this project is very low I gathered the soruces and figured some bugs out, especially this one (which was not easy at all to fix...)
I was not really able to track this one down but I know what I changed to resove the issue:
I did change the CircularBufferStream in the following ways:
public override long Length
{
get
{
var length = this.writePosition - this.readPosition; return length < 0 ? this.buffer.Length + length : length;
}
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
// Write block of bytes from given buffer into circular buffer, wrapping around when necessary.
int writeCount;
while ((writeCount = Math.Min(count, (int)(this.buffer.Length - this.writePosition))) > 0)
{
var oldWritePosition = this.writePosition;
var newWritePosition = (this.writePosition + writeCount) % this.buffer.Length;
if (newWritePosition > readPosition && oldWritePosition < readPosition)
{ throw new InternalBufferOverflowException("Der CircularBuffer wurde überlaufen!");
} System.Buffer.BlockCopy(buffer, offset, this.buffer, (int)this.writePosition, writeCount); this.writePosition = newWritePosition;
offset += writeCount; count -= writeCount; //writeCount <= count => now is count >=0
}
}
public override int Read(byte[] buffer, int offset, int count)
{
// Read block of bytes from circular buffer, wrapping around when necessary.
int totalReadCount = 0;
int readCount;
count = Math.Min(buffer.Length - offset, count);
while ((readCount = Math.Min(count, (int)(Length))) > 0)
{
if (readCount > this.buffer.Length - readPosition)
{ readCount = (int)(this.buffer.Length - readPosition);
} System.Buffer.BlockCopy(this.buffer, (int)this.readPosition, buffer, offset, readCount); this.readPosition = (this.readPosition + readCount) % this.buffer.Length; offset += readCount; count = Math.Min(buffer.Length - offset, count); totalReadCount += readCount;
}
return totalReadCount;
}
I think the problem occured on some special cases at the end of the CircularBuffer which were not handled correctly.
( but I'm not 100% sure )
Added the patched file as Attachment (not sure if it will compile in the current version on this site)
It's not possible for me to reupload my complete implementation as i changed lots of Logging to be able to track this down...
Because the activity on this project is very low I gathered the soruces and figured some bugs out, especially this one (which was not easy at all to fix...)
I was not really able to track this one down but I know what I changed to resove the issue: tream in the following ways:
return length < 0 ? this.buffer.Length + length : length;
I did change the CircularBufferS
public override long Length
{
get
{
var length = this.writePosition - this.readPosition;
}
}
public override long Seek(long offset, SeekOrigin origin) eption( );
{
throw new NotSupportedExc
}
public override void Write(byte[] buffer, int offset, int count) buffer. Length - this.writePosit ion))) > 0)
throw new InternalBufferO verflowExceptio n("Der CircularBuffer wurde überlaufen!");
System. Buffer. BlockCopy( buffer, offset, this.buffer, (int)this. writePosition, writeCount);
this. writePosition = newWritePosition;
{
// Write block of bytes from given buffer into circular buffer, wrapping around when necessary.
int writeCount;
while ((writeCount = Math.Min(count, (int)(this.
{
var oldWritePosition = this.writePosition;
var newWritePosition = (this.writePosition + writeCount) % this.buffer.Length;
if (newWritePosition > readPosition && oldWritePosition < readPosition)
{
}
}
}
public override int Read(byte[] buffer, int offset, int count) buffer. Length - offset, count);
readCount = (int)(this. buffer. Length - readPosition);
System. Buffer. BlockCopy( this.buffer, (int)this. readPosition, buffer, offset, readCount);
this. readPosition = (this.readPosition + readCount) % this.buffer.Length;
offset += readCount;
count = Math.Min( buffer. Length - offset, count);
totalReadCoun t += readCount;
{
// Read block of bytes from circular buffer, wrapping around when necessary.
int totalReadCount = 0;
int readCount;
count = Math.Min(
while ((readCount = Math.Min(count, (int)(Length))) > 0)
{
if (readCount > this.buffer.Length - readPosition)
{
}
}
return totalReadCount;
}
I think the problem occured on some special cases at the end of the CircularBuffer which were not handled correctly.
( but I'm not 100% sure )
Added the patched file as Attachment (not sure if it will compile in the current version on this site)
It's not possible for me to reupload my complete implementation as i changed lots of Logging to be able to track this down...
Hope this helps!
reddragon