public override int EndRead(IAsyncResult asyncResult)
{
InternalAsyncResult internalAsyncResult = asyncResult as InternalAsyncResult;
if (internalAsyncResult == null)
{
throw new ArgumentException("AsyncResult was not obtained via BeginRead", "asyncResult");
}
// Check to see if the operation is complete, if not -- let's wait for it
if (!internalAsyncResult.IsCompleted)
{
if (!internalAsyncResult.AsyncWaitHandle.WaitOne(WaitTimeOut, false))
{
throw new IOException("Failed to complete read operation");
}
}
// If we completed with an error, throw the exceptions
if (internalAsyncResult.CompletedWithError)
{
throw internalAsyncResult.AsyncException;
}
// Success, return the bytes read
return internalAsyncResult.BytesRead;
}