public override int Read(byte[] buffer, int offset, int count)
{
int read = 0;
while (read < count)
{
// Ensure a buffer is available
if (TakeBuffer())
{
// Get as much as we can from the current buffer
read += _current.Read(buffer, offset + read, count - read);
if (_current.Count == 0)
{
// Used up this buffer, return to the pool if it's a pool buffer
if (_current.FromPool)
{
_pool.Add(_current);
}
_current = null;
}
}
else
{
break;
}
}
return(read);
}