public IAsyncResult BeginReceive(AsyncCallback asyncCallback, Object asyncState)
{
AsyncReceiveDataResult asyncReceiveResult = new AsyncReceiveDataResult(asyncCallback, asyncState);
lock (_handshakeLock) {
if (!_isAuthenticated) {
Exception e = new InvalidOperationException("Trying to receive on an unauthenticated session");
asyncReceiveResult.SetComplete(e);
return asyncReceiveResult;
}
if (_isHandshaking) {
// Queue requests to receive data during renegotiation
// TODO: implement this when renegotiation is implemented
Exception e = new InvalidOperationException("Receiving data during renegotiation not implemented");
asyncReceiveResult.SetComplete(e);
return asyncReceiveResult;
}
}
_recordStream.BeginReceive(new AsyncCallback(ReceiveDataCallback), asyncReceiveResult);
return asyncReceiveResult;
}