public override IAsyncResult BeginRead(
byte[] buffer,
int offset,
int count,
AsyncCallback asyncCallback,
object asyncState)
{
if (buffer == null)
{
throw new ArgumentNullException("buffer", "buffer can't be null");
}
if (offset < 0)
{
throw new ArgumentOutOfRangeException("offset", "offset less than 0");
}
if (offset > buffer.Length)
{
throw new ArgumentOutOfRangeException("offset", "offset must be less than buffer length");
}
if (count < 0)
{
throw new ArgumentOutOfRangeException("count", "count less than 0");
}
if (count > (buffer.Length - offset))
{
throw new ArgumentOutOfRangeException("count", "count is greater than buffer length - offset");
}
bool proceedAfterHandshake = true;
if (count == 0) proceedAfterHandshake = false;
InternalAsyncResult internalAsyncResult = new InternalAsyncResult(asyncCallback, asyncState, buffer, offset, count, false, proceedAfterHandshake);
if (NeedHandshake)
{
//inHandshakeLoop = true;
BeginHandshake(internalAsyncResult);
}
else
{
InternalBeginRead(internalAsyncResult);
}
return internalAsyncResult;
}