protected virtual void Dispose(bool disposing, CloseExState closeState) {
// All below calls should already be idempotent
try {
ICloseEx icloseEx = m_OriginalStream as ICloseEx;
if (icloseEx != null) {
icloseEx.CloseEx(closeState);
}
else {
m_OriginalStream.Close();
}
}
finally {
// Notify the wirte stream on a partial response if did not see EOF on read
if (!m_SeenReadEOF)
closeState |= CloseExState.Abort;
//
// We don't want to touch m_ShadowStreamIsDead because Close() can be called from other thread while IO is in progress.
// We assume that all streams used by this class are thread safe on Close().
// m_ShadowStreamIsDead = true;
if (m_ShadowStream is ICloseEx)
((ICloseEx)m_ShadowStream).CloseEx(closeState);
else
m_ShadowStream.Close();
}
if (!disposing) {
// no IO can be in progress because it a GC thread.
m_OriginalStream = null;
m_ShadowStream = null;
}
base.Dispose(disposing);
}