internal virtual IAsyncResult UnsafeBeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, Object state)
{
bool canRead = CanRead; // Prevent race with Dispose.
if (_cleanedUp)
{
throw new ObjectDisposedException(GetType().FullName);
}
if (!canRead)
{
throw new InvalidOperationException(SR.net_writeonlystream);
}
Socket chkStreamSocket = _streamSocket;
if (chkStreamSocket == null)
{
throw new IOException(SR.Format(SR.net_io_readfailure, SR.net_io_connectionclosed));
}
try
{
IAsyncResult asyncResult = chkStreamSocket.UnsafeBeginReceive(
buffer,
offset,
size,
SocketFlags.None,
callback,
state);
return asyncResult;
}
catch (Exception exception)
{
if (ExceptionCheck.IsFatal(exception)) throw;
// Some sort of error occurred on the socket call,
// set the SocketException as InnerException and throw.
throw new IOException(SR.Format(SR.net_io_readfailure, exception.Message), exception);
}
}