private int FillFromBufferedData(byte [] buffer, ref int offset, ref int size ) {
//
// if there's no stuff in our read buffer just return 0
//
if (m_ReadBufferSize == 0) {
return 0;
}
//
// There's stuff in our read buffer. Figure out how much to take,
// which is the minimum of what we have and what we're to read,
// and copy it out.
//
int BytesTransferred = Math.Min(size, m_ReadBufferSize);
GlobalLog.Print("ConnectStream#" + ValidationHelper.HashString(this) + "::FillFromBufferedData() Filling bytes: " + BytesTransferred.ToString());
Buffer.BlockCopy(
m_ReadBuffer,
m_ReadOffset,
buffer,
offset,
BytesTransferred);
// Update our internal read buffer state with what we took.
m_ReadOffset += BytesTransferred;
m_ReadBufferSize -= BytesTransferred;
// If the read buffer size has gone to 0, null out our pointer
// to it so maybe it'll be garbage-collected faster.
if (m_ReadBufferSize == 0) {
m_ReadBuffer = null;
}
// Update what we're to read and the caller's offset.
size -= BytesTransferred;
offset += BytesTransferred;
return BytesTransferred;
}