private int InternalRead(byte[] buffer, int offset, int size) {
GlobalLog.ThreadContract(ThreadKinds.Sync, "ConnectStream#" + ValidationHelper.HashString(this) + "::InternalRead");
// Read anything first out of the buffer
int bytesToRead = FillFromBufferedData(buffer, ref offset, ref size);
if (bytesToRead>0) {
return bytesToRead;
}
// otherwise, we need to read more data from the connection.
if (ErrorInStream) {
GlobalLog.LeaveException("ConnectStream::InternalBeginRead", m_ErrorException);
throw m_ErrorException;
}
bytesToRead = m_Connection.Read(
buffer,
offset,
size);
return bytesToRead;
}