public override int EndRead(IAsyncResult asyncResult) {
if (Interlocked.Decrement(ref m_ReadNesting) != 0) {
Interlocked.Increment(ref m_ReadNesting);
throw new InvalidOperationException(SR.GetString(SR.net_io_invalidendcall, "EndRead"));
}
if (asyncResult == null) {
throw new ArgumentNullException("asyncResult");
}
InnerAsyncResult myResult = asyncResult as InnerAsyncResult;
if (myResult == null) {
// We are just passing IO down, although m_HeadEOF should be always true here.
GlobalLog.Assert(m_HeadEOF, "CombinedReadStream::EndRead|m_HeadEOF is false and asyncResult is not of InnerAsyncResult type {0).", asyncResult.GetType().FullName);
return m_HeadEOF? m_TailStream.EndRead(asyncResult): m_HeadStream.EndRead(asyncResult);
}
// this is our wrapped AsyncResult
myResult.InternalWaitForCompletion();
// Exception?
if (myResult.Result is Exception) {
throw (Exception)(myResult.Result);
}
// Report the count read
return (int)myResult.Result;
}