private void ReadCallback(IAsyncResult transportResult) {
GlobalLog.Assert(transportResult.AsyncState is InnerAsyncResult, "InnerAsyncResult::ReadCallback|The state expected to be of type InnerAsyncResult, received {0}.", transportResult.GetType().FullName);
if (transportResult.CompletedSynchronously)
{
return;
}
InnerAsyncResult userResult = transportResult.AsyncState as InnerAsyncResult;
try {
// Complete transport IO, in this callback that is always the head stream
int count;
if (!m_HeadEOF) {
count = m_HeadStream.EndRead(transportResult);
m_HeadLength += count;
}
else {
count = m_TailStream.EndRead(transportResult);
}
//check on EOF condition
if (!m_HeadEOF && count == 0 && userResult.Count != 0) {
//Got a first stream EOF
m_HeadEOF = true;
m_HeadStream.Close();
IAsyncResult ar = m_TailStream.BeginRead(userResult.Buffer, userResult.Offset, userResult.Count, m_ReadCallback, userResult);
if (!ar.CompletedSynchronously) {
return;
}
count = m_TailStream.EndRead(ar);
}
// just complete user IO
userResult.Buffer = null;
userResult.InvokeCallback(count);
}
catch (Exception e) {
//ASYNC: try to swallow even serious exceptions (nothing to loose?)
if (userResult.InternalPeekCompleted)
throw;
userResult.InvokeCallback(e);
}
catch {
//ASYNC: try to swallow even serious exceptions (nothing to loose?)
if (userResult.InternalPeekCompleted)
throw;
userResult.InvokeCallback(new Exception(SR.GetString(SR.net_nonClsCompliantException)));
}
}