示例#1
0
        protected virtual void Dispose(bool disposing, CloseExState closeState)
        {
            // All calls below should already be idempotent.

            try
            {
                if (disposing)
                {
                    ICloseEx icloseEx = WrappedStream as ICloseEx;

                    if (icloseEx != null)
                    {
                        icloseEx.CloseEx(closeState);
                    }
                    else
                    {
                        WrappedStream.Close();
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
        void ICloseEx.CloseEx(CloseExState closeState)
        {
            GlobalLog.Enter("FileWebResponse::Close()");
            try {
                if (!m_closed)
                {
                    m_closed = true;

                    Stream chkStream = m_stream;
                    if (chkStream != null)
                    {
                        if (chkStream is ICloseEx)
                        {
                            ((ICloseEx)chkStream).CloseEx(closeState);
                        }
                        else
                        {
                            chkStream.Close();
                        }
                        m_stream = null;
                    }
                }
            }
            finally {
                GlobalLog.Leave("FileWebResponse::Close()");
            }
        }
示例#3
0
        void ICloseEx.CloseEx(CloseExState closeState)
        {
            if (Interlocked.Increment(ref _Disposed) == 1)
            {
                // This would allow us to cache the response stream that user throws away
                // Next time the cached version could save us from an extra roundtrip
                if (closeState == CloseExState.Silent)
                {
                    try {
                        int total = 0;
                        int bytesRead;
                        while (total < ConnectStream.s_DrainingBuffer.Length && (bytesRead = Read(ConnectStream.s_DrainingBuffer, 0, ConnectStream.s_DrainingBuffer.Length)) > 0)
                        {
                            total += bytesRead;
                        }
                    }
                    catch (Exception exception) {
                        //ATTN: this path will swalow errors regardless of m_IsThrowOnWriteError setting
                        //      A "Silent" close is for an intermediate response that is to be ignored anyway
                        if (exception is ThreadAbortException || exception is StackOverflowException || exception is OutOfMemoryException)
                        {
                            throw;
                        }
                    }
                }

                Dispose(true, closeState);
            }
        }
示例#4
0
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     if ((closeState & CloseExState.Abort) != 0)
     {
         SafeFileHandle.Close();
     }
     else
     {
         Close();
     }
 }
        void ICloseEx.CloseEx(CloseExState closeState)
        {
            GlobalLog.Print("FtpDataStream#" + ValidationHelper.HashString(this) + "::CloseEx, state = " + closeState.ToString());

            lock (this)
            {
                if (m_Closing == true)
                {
                    return;
                }
                m_Closing   = true;
                m_Writeable = false;
                m_Readable  = false;
            }

            try {
                try {
                    if ((closeState & CloseExState.Abort) == 0)
                    {
                        m_NetworkStream.Close(Socket.DefaultCloseTimeout);
                    }
                    else
                    {
                        m_NetworkStream.Close(0);
                    }
                } finally {
                    m_Request.DataStreamClosed(closeState);
                }
            }
            catch (Exception exception) {
                bool         doThrow      = true;
                WebException webException = exception as WebException;
                if (webException != null)
                {
                    FtpWebResponse response = webException.Response as FtpWebResponse;
                    if (response != null)
                    {
                        if (!m_IsFullyRead &&
                            response.StatusCode == FtpStatusCode.ConnectionClosed)
                        {
                            doThrow = false;
                        }
                    }
                }

                if (doThrow)
                {
                    if ((closeState & CloseExState.Silent) == 0)
                    {
                        throw;
                    }
                }
            }
        }
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     if ((closeState & CloseExState.Abort) != CloseExState.Normal)
     {
         this.SafeFileHandle.Close();
     }
     else
     {
         this.Close();
     }
 }
示例#7
0
 void ICloseEx.CloseEx(CloseExState closeState) {
     ICloseEx icloseEx = BaseStream as ICloseEx;
     if (icloseEx != null) {
         // since the internal Close() of GZipStream just does Close on our base stream
         // we don't have to call it anymore at this point
         icloseEx.CloseEx(closeState);
     }
     else {
         Close();
     }
 }
        void ICloseEx.CloseEx(CloseExState closeState)
        {
            ICloseEx baseStream = base.BaseStream as ICloseEx;

            if (baseStream != null)
            {
                baseStream.CloseEx(closeState);
            }
            else
            {
                this.Close();
            }
        }
示例#9
0
        void ICloseEx.CloseEx(CloseExState closeState)
        {
            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("FtpDataStream#" + LoggingHash.HashString(this) + "::CloseEx, state = " + closeState.ToString());
            }

            lock (this)
            {
                if (_closing == true)
                    return;
                _closing = true;
                _writeable = false;
                _readable = false;
            }

            try
            {
                try
                {
                    if ((closeState & CloseExState.Abort) == 0)
                        _networkStream.Close(DefaultCloseTimeout);
                    else
                        _networkStream.Close(0);
                }
                finally
                {
                    _request.DataStreamClosed(closeState);
                }
            }
            catch (Exception exception)
            {
                bool doThrow = true;
                WebException webException = exception as WebException;
                if (webException != null)
                {
                    FtpWebResponse response = webException.Response as FtpWebResponse;
                    if (response != null)
                    {
                        if (!_isFullyRead
                            && response.StatusCode == FtpStatusCode.ConnectionClosed)
                            doThrow = false;
                    }
                }

                if (doThrow)
                    if ((closeState & CloseExState.Silent) == 0)
                        throw;
            }
        }
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     lock (this)
     {
         if (this.m_Closing)
         {
             return;
         }
         this.m_Closing   = true;
         this.m_Writeable = false;
         this.m_Readable  = false;
     }
     try
     {
         try
         {
             if ((closeState & CloseExState.Abort) == CloseExState.Normal)
             {
                 this.m_NetworkStream.Close(-1);
             }
             else
             {
                 this.m_NetworkStream.Close(0);
             }
         }
         finally
         {
             this.m_Request.DataStreamClosed(closeState);
         }
     }
     catch (Exception exception)
     {
         bool         flag       = true;
         WebException exception2 = exception as WebException;
         if (exception2 != null)
         {
             FtpWebResponse response = exception2.Response as FtpWebResponse;
             if (((response != null) && !this.m_IsFullyRead) && (response.StatusCode == FtpStatusCode.ConnectionClosed))
             {
                 flag = false;
             }
         }
         if (flag && ((closeState & CloseExState.Silent) == CloseExState.Normal))
         {
             throw;
         }
     }
 }
示例#11
0
        protected virtual void Dispose(bool disposing, CloseExState closeState)
        {
            try {
                if (Interlocked.Increment(ref _Disposed) == 1)
                {
                    if (disposing)
                    {
                        ICloseEx icloseEx = WrappedStream as ICloseEx;

                        if (icloseEx != null)
                        {
                            icloseEx.CloseEx(closeState);
                        }
                        else
                        {
                            WrappedStream.Close();
                        }

                        if (m_CacheDestroy)
                        {
                            if (m_IsStrictCacheErrors)
                            {
                                m_Cache.Remove(m_Key);
                            }
                            else
                            {
                                m_Cache.TryRemove(m_Key);
                            }
                        }
                        else
                        {
                            if (m_IsStrictCacheErrors)
                            {
                                m_Cache.Update(m_Key, m_Expires, m_LastModified, m_LastSynchronized, m_MaxStale, m_EntryMetadata, m_SystemMetadata);
                            }
                            else
                            {
                                m_Cache.TryUpdate(m_Key, m_Expires, m_LastModified, m_LastSynchronized, m_MaxStale, m_EntryMetadata, m_SystemMetadata);
                            }
                        }
                    }
                }
            }
            finally {
                base.Dispose(disposing);
            }
        }
示例#12
0
        void ICloseEx.CloseEx(CloseExState closeState)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"state = {closeState}");

            lock (this)
            {
                if (_closing == true)
                    return;
                _closing = true;
                _writeable = false;
                _readable = false;
            }

            try
            {
                try
                {
                    if ((closeState & CloseExState.Abort) == 0)
                        _networkStream.Close(DefaultCloseTimeout);
                    else
                        _networkStream.Close(0);
                }
                finally
                {
                    _request.DataStreamClosed(closeState);
                }
            }
            catch (Exception exception)
            {
                bool doThrow = true;
                WebException webException = exception as WebException;
                if (webException != null)
                {
                    FtpWebResponse response = webException.Response as FtpWebResponse;
                    if (response != null)
                    {
                        if (!_isFullyRead
                            && response.StatusCode == FtpStatusCode.ConnectionClosed)
                            doThrow = false;
                    }
                }

                if (doThrow)
                    if ((closeState & CloseExState.Silent) == 0)
                        throw;
            }
        }
示例#13
0
        void ICloseEx.CloseEx(CloseExState closeState)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"state = {closeState}");

            lock (this)
            {
                if (_closing == true)
                    return;
                _closing = true;
                _writeable = false;
                _readable = false;
            }

            try
            {
                try
                {
                    if ((closeState & CloseExState.Abort) == 0)
                        _networkStream.Close(DefaultCloseTimeout);
                    else
                        _networkStream.Close(0);
                }
                finally
                {
                    _request.DataStreamClosed(closeState);
                }
            }
            catch (Exception exception)
            {
                bool doThrow = true;
                WebException webException = exception as WebException;
                if (webException != null)
                {
                    FtpWebResponse response = webException.Response as FtpWebResponse;
                    if (response != null)
                    {
                        if (!_isFullyRead
                            && response.StatusCode == FtpStatusCode.ConnectionClosed)
                            doThrow = false;
                    }
                }

                if (doThrow)
                    if ((closeState & CloseExState.Silent) == 0)
                        throw;
            }
        }
示例#14
0
        protected virtual void Dispose(bool disposing, CloseExState closeState)
        {
            // All below calls should already be idempotent

            try {
                if (disposing)
                {
                    try {
                        ICloseEx icloseEx = WrappedStream as ICloseEx;
                        if (icloseEx != null)
                        {
                            icloseEx.CloseEx(closeState);
                        }
                        else
                        {
                            WrappedStream.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();
                        }
                    }
                }
            }
            finally {
                base.Dispose(disposing);
            }
        }
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     if (!this.m_closed)
     {
         this.m_closed = true;
         Stream stream = this.m_stream;
         if (stream != null)
         {
             if (stream is ICloseEx)
             {
                 ((ICloseEx) stream).CloseEx(closeState);
             }
             else
             {
                 stream.Close();
             }
             this.m_stream = null;
         }
     }
 }
示例#16
0
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     if (!this.m_closed)
     {
         this.m_closed = true;
         Stream stream = this.m_stream;
         if (stream != null)
         {
             if (stream is ICloseEx)
             {
                 ((ICloseEx)stream).CloseEx(closeState);
             }
             else
             {
                 stream.Close();
             }
             this.m_stream = null;
         }
     }
 }
 protected virtual void Dispose(bool disposing, CloseExState closeState)
 {
     try
     {
         if ((Interlocked.Increment(ref this._Disposed) == 1) && disposing)
         {
             ICloseEx wrappedStream = base.WrappedStream as ICloseEx;
             if (wrappedStream != null)
             {
                 wrappedStream.CloseEx(closeState);
             }
             else
             {
                 base.WrappedStream.Close();
             }
             if (this.m_CacheDestroy)
             {
                 if (this.m_IsStrictCacheErrors)
                 {
                     this.m_Cache.Remove(this.m_Key);
                 }
                 else
                 {
                     this.m_Cache.TryRemove(this.m_Key);
                 }
             }
             else if (this.m_IsStrictCacheErrors)
             {
                 this.m_Cache.Update(this.m_Key, this.m_Expires, this.m_LastModified, this.m_LastSynchronized, this.m_MaxStale, this.m_EntryMetadata, this.m_SystemMetadata);
             }
             else
             {
                 this.m_Cache.TryUpdate(this.m_Key, this.m_Expires, this.m_LastModified, this.m_LastSynchronized, this.m_MaxStale, this.m_EntryMetadata, this.m_SystemMetadata);
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
 protected virtual void Dispose(bool disposing, CloseExState closeState)
 {
     try
     {
         if ((Interlocked.Increment(ref this._Disposed) == 1) && disposing)
         {
             ICloseEx wrappedStream = base.WrappedStream as ICloseEx;
             if (wrappedStream != null)
             {
                 wrappedStream.CloseEx(closeState);
             }
             else
             {
                 base.WrappedStream.Close();
             }
             if (this.m_CacheDestroy)
             {
                 if (this.m_IsStrictCacheErrors)
                 {
                     this.m_Cache.Remove(this.m_Key);
                 }
                 else
                 {
                     this.m_Cache.TryRemove(this.m_Key);
                 }
             }
             else if (this.m_IsStrictCacheErrors)
             {
                 this.m_Cache.Update(this.m_Key, this.m_Expires, this.m_LastModified, this.m_LastSynchronized, this.m_MaxStale, this.m_EntryMetadata, this.m_SystemMetadata);
             }
             else
             {
                 this.m_Cache.TryUpdate(this.m_Key, this.m_Expires, this.m_LastModified, this.m_LastSynchronized, this.m_MaxStale, this.m_EntryMetadata, this.m_SystemMetadata);
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
 protected virtual void Dispose(bool disposing, CloseExState closeState)
 {
     try
     {
         if (disposing)
         {
             try
             {
                 ICloseEx wrappedStream = base.WrappedStream as ICloseEx;
                 if (wrappedStream != null)
                 {
                     wrappedStream.CloseEx(closeState);
                 }
                 else
                 {
                     base.WrappedStream.Close();
                 }
             }
             finally
             {
                 if (!this.m_SeenReadEOF)
                 {
                     closeState |= CloseExState.Abort;
                 }
                 if (this.m_ShadowStream is ICloseEx)
                 {
                     ((ICloseEx)this.m_ShadowStream).CloseEx(closeState);
                 }
                 else
                 {
                     this.m_ShadowStream.Close();
                 }
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
 protected virtual void Dispose(bool disposing, CloseExState closeState)
 {
     try
     {
         if (disposing)
         {
             try
             {
                 ICloseEx wrappedStream = base.WrappedStream as ICloseEx;
                 if (wrappedStream != null)
                 {
                     wrappedStream.CloseEx(closeState);
                 }
                 else
                 {
                     base.WrappedStream.Close();
                 }
             }
             finally
             {
                 if (!this.m_SeenReadEOF)
                 {
                     closeState |= CloseExState.Abort;
                 }
                 if (this.m_ShadowStream is ICloseEx)
                 {
                     ((ICloseEx) this.m_ShadowStream).CloseEx(closeState);
                 }
                 else
                 {
                     this.m_ShadowStream.Close();
                 }
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
 protected virtual void Dispose(bool disposing, CloseExState closeState)
 {
     try
     {
         if (disposing)
         {
             try
             {
                 if (!this.m_HeadEOF)
                 {
                     ICloseEx headStream = this.m_HeadStream as ICloseEx;
                     if (headStream != null)
                     {
                         headStream.CloseEx(closeState);
                     }
                     else
                     {
                         this.m_HeadStream.Close();
                     }
                 }
             }
             finally
             {
                 ICloseEx wrappedStream = base.WrappedStream as ICloseEx;
                 if (wrappedStream != null)
                 {
                     wrappedStream.CloseEx(closeState);
                 }
                 else
                 {
                     base.WrappedStream.Close();
                 }
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
示例#22
0
 protected virtual void Dispose(bool disposing, CloseExState closeState)
 {
     try
     {
         if (disposing)
         {
             try
             {
                 if (!this.m_HeadEOF)
                 {
                     ICloseEx headStream = this.m_HeadStream as ICloseEx;
                     if (headStream != null)
                     {
                         headStream.CloseEx(closeState);
                     }
                     else
                     {
                         this.m_HeadStream.Close();
                     }
                 }
             }
             finally
             {
                 ICloseEx wrappedStream = base.WrappedStream as ICloseEx;
                 if (wrappedStream != null)
                 {
                     wrappedStream.CloseEx(closeState);
                 }
                 else
                 {
                     base.WrappedStream.Close();
                 }
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
        void ICloseEx.CloseEx(CloseExState closeState) {
            GlobalLog.Print("FtpDataStream#" + ValidationHelper.HashString(this) + "::CloseEx, state = " + closeState.ToString());

            lock (this)
            {
                if (m_Closing == true)
                    return;
                m_Closing = true;
                m_Writeable = false;
                m_Readable = false;
            }

            try {
                try {
                    if ((closeState & CloseExState.Abort) == 0)
                        m_NetworkStream.Close(Socket.DefaultCloseTimeout);
                    else
                        m_NetworkStream.Close(0);
                } finally {
                    m_Request.DataStreamClosed(closeState);
                }
            }
            catch (Exception exception) {
                bool doThrow = true;
                WebException webException = exception as WebException;
                if (webException != null) {
                    FtpWebResponse response = webException.Response as FtpWebResponse;
                    if (response != null)
                    {
                        if (!m_IsFullyRead
                            && response.StatusCode == FtpStatusCode.ConnectionClosed)
                            doThrow = false;
                    }
                }

                if (doThrow)
                    if ((closeState & CloseExState.Silent) == 0)
                        throw;
            }
        }
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     if (Interlocked.Increment(ref this._Disposed) == 1)
     {
         if (closeState == CloseExState.Silent)
         {
             try
             {
                 int num2;
                 for (int i = 0; (i < ConnectStream.s_DrainingBuffer.Length) && ((num2 = this.Read(ConnectStream.s_DrainingBuffer, 0, ConnectStream.s_DrainingBuffer.Length)) > 0); i += num2)
                 {
                 }
             }
             catch (Exception exception)
             {
                 if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                 {
                     throw;
                 }
             }
         }
         this.Dispose(true, closeState);
     }
 }
        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);
        }
示例#26
0
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     this.Dispose(true, closeState);
 }
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     if (Interlocked.Increment(ref this._Disposed) == 1)
     {
         if (closeState == CloseExState.Silent)
         {
             try
             {
                 int num2;
                 for (int i = 0; (i < ConnectStream.s_DrainingBuffer.Length) && ((num2 = this.Read(ConnectStream.s_DrainingBuffer, 0, ConnectStream.s_DrainingBuffer.Length)) > 0); i += num2)
                 {
                 }
             }
             catch (Exception exception)
             {
                 if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                 {
                     throw;
                 }
             }
         }
         this.Dispose(true, closeState);
     }
 }
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     if ((closeState & CloseExState.Abort) != CloseExState.Normal)
     {
         this.SafeFileHandle.Close();
     }
     else
     {
         this.Close();
     }
 }
示例#29
0
        void ICloseEx.CloseEx(CloseExState closeState)
        {
            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("FtpDataStream#" + LoggingHash.HashString(this) + "::CloseEx, state = " + closeState.ToString());
            }

            lock (this)
            {
                if (_closing == true)
                {
                    return;
                }
                _closing   = true;
                _writeable = false;
                _readable  = false;
            }

            try
            {
                try
                {
                    if ((closeState & CloseExState.Abort) == 0)
                    {
                        _networkStream.Close(DefaultCloseTimeout);
                    }
                    else
                    {
                        _networkStream.Close(0);
                    }
                }
                finally
                {
                    _request.DataStreamClosed(closeState);
                }
            }
            catch (Exception exception)
            {
                bool         doThrow      = true;
                WebException webException = exception as WebException;
                if (webException != null)
                {
                    FtpWebResponse response = webException.Response as FtpWebResponse;
                    if (response != null)
                    {
                        if (!_isFullyRead &&
                            response.StatusCode == FtpStatusCode.ConnectionClosed)
                        {
                            doThrow = false;
                        }
                    }
                }

                if (doThrow)
                {
                    if ((closeState & CloseExState.Silent) == 0)
                    {
                        throw;
                    }
                }
            }
        }
            //
            public void CloseEx(CloseExState closeState)
            {
                // For abnormal stream termination we will commit a partial cache entry
                if ((closeState & CloseExState.Abort) != 0)
                    m_Aborted = true;

                try {
                    Close();
                }
                catch {
                    if ((closeState & CloseExState.Silent) == 0)
                        throw;
                }
            }
 void ICloseEx.CloseEx(CloseExState closeState)
 {
     ICloseEx baseStream = base.BaseStream as ICloseEx;
     if (baseStream != null)
     {
         baseStream.CloseEx(closeState);
     }
     else
     {
         this.Close();
     }
 }
示例#32
0
 internal void DataStreamClosed(CloseExState closeState)
 {
     if ((closeState & CloseExState.Abort) == 0)
     {
         if (!_async)
         {
             if (_connection != null)
                 _connection.CheckContinuePipeline();
         }
         else
         {
             _requestCompleteAsyncResult.InternalWaitForCompletion();
             CheckError();
         }
     }
     else
     {
         FtpControlStream connection = _connection;
         if (connection != null)
             connection.Abort(ExceptionHelper.RequestAbortedException);
     }
 }
 internal void DataStreamClosed(CloseExState closeState)
 {
     if ((closeState & CloseExState.Abort) == CloseExState.Normal)
     {
         if (this.m_Async)
         {
             this.m_RequestCompleteAsyncResult.InternalWaitForCompletion();
             this.CheckError();
         }
         else if (this.m_Connection != null)
         {
             this.m_Connection.CheckContinuePipeline();
         }
     }
     else
     {
         FtpControlStream connection = this.m_Connection;
         if (connection != null)
         {
             connection.Abort(ExceptionHelper.RequestAbortedException);
         }
     }
 }
        void ICloseEx.CloseEx(CloseExState closeState) {

            if (Interlocked.Increment(ref _Disposed) == 1) {
                // This would allow us to cache the response stream that user throws away
                // Next time the cached version could save us from an extra roundtrip
                if (closeState == CloseExState.Silent) {
                    try {
                        int total = 0;
                        int bytesRead;
                        while (total < ConnectStream.s_DrainingBuffer.Length && (bytesRead = Read(ConnectStream.s_DrainingBuffer, 0, ConnectStream.s_DrainingBuffer.Length)) > 0) {
                            total += bytesRead;
                        }
                    }
                    catch (Exception exception) {
                        //ATTN: this path will swalow errors regardless of m_IsThrowOnWriteError setting
                        //      A "Silent" close is for an intermediate response that is to be ignored anyway
                        if (exception is ThreadAbortException || exception is StackOverflowException || exception is OutOfMemoryException) {
                            throw;
                        }
                    }
                    catch {
                        //ATTN: this path will swalow errors regardless of m_IsThrowOnWriteError setting
                        //      A "Silent" close is for an intermediate response that is to be ignored anyway
                    }
                }

                Dispose(true, closeState);
                GC.SuppressFinalize(this);
            }
        }
示例#35
0
 void ICloseEx.CloseEx(CloseExState closeState) {
     if ((closeState & CloseExState.Abort) != 0)
         SafeFileHandle.Close();
     else
         Close();
 }
        protected virtual void Dispose(bool disposing, CloseExState closeState) {

            // All below calls should already be idempotent

            try {
                if (!m_HeadEOF) {
                    ICloseEx icloseEx = m_HeadStream as ICloseEx;
                    if (icloseEx != null) {
                        icloseEx.CloseEx(closeState);
                    }
                    else {
                        m_HeadStream.Close();
                    }
                }
            }
            finally {
                ICloseEx icloseEx = m_TailStream as ICloseEx;
                if (icloseEx != null) {
                    icloseEx.CloseEx(closeState);
                }
                else {
                    m_TailStream.Close();
                }
            }

            if (!disposing) {
                m_HeadStream = null;
                m_TailStream = null;
            }
        }
 void ICloseEx.CloseEx(CloseExState closeState) {
     Dispose(true, closeState);
     GC.SuppressFinalize(this);
 }
        protected virtual void Dispose(bool disposing, CloseExState closeState) {

            // All calls below should already be idempotent.

            ICloseEx icloseEx = m_ParentStream as ICloseEx;

            if (icloseEx != null) {
                icloseEx.CloseEx(closeState);
            }
            else {
                m_ParentStream.Close();
            }
            base.Dispose(disposing);
        }
        protected virtual void Dispose(bool disposing, CloseExState closeState) {

            if (Interlocked.Increment(ref _Disposed) == 1) {
                ICloseEx icloseEx = m_ParentStream as ICloseEx;

                if (icloseEx != null) {
                    icloseEx.CloseEx(closeState);
                }
                else {
                    m_ParentStream.Close();
                }

                if (m_CacheDestroy)
                {
                    if (m_IsStrictCacheErrors)
                    {
                        m_Cache.Remove(m_Key);
                    }
                    else
                    {
                        m_Cache.TryRemove(m_Key);
                    }
                }
                else
                {
                    if (m_IsStrictCacheErrors)
                    {
                        m_Cache.Update(m_Key, m_Expires, m_LastModified, m_LastSynchronized, m_MaxStale, m_EntryMetadata, m_SystemMetadata);
                    }
                    else
                    {
                        m_Cache.TryUpdate(m_Key, m_Expires, m_LastModified, m_LastSynchronized, m_MaxStale, m_EntryMetadata, m_SystemMetadata);
                    }

                }

                if (!disposing) {
                    m_Cache             = null;
                    m_Key               = null;
                    m_EntryMetadata     = null;
                    m_SystemMetadata    = null;
                }
            }
            base.Dispose(disposing);
        }
 void ICloseEx.CloseEx(CloseExState closeState) {
     Dispose(true, closeState);
 }
 void ICloseEx.CloseEx(CloseExState closeState) {
     ICloseEx icloseEx = BaseStream as ICloseEx;
     if (icloseEx != null) {
         // since the internal Close() of GZipStream just does Close on our base stream
         // we don't have to call it anymore at this point
         icloseEx.CloseEx(closeState);
     }
     else {
         Close();
     }
 }
            public void CloseEx(CloseExState closeState)
            {
                if ((closeState & CloseExState.Abort) != 0)
                    m_Aborted = true;

                try {
                    Close();
                }
                catch {
                    if ((closeState & CloseExState.Silent) == 0)
                        throw;
                }
            }
示例#43
0
 void ICloseEx.CloseEx(CloseExState closeState) {
     GlobalLog.ThreadContract(ThreadKinds.Unknown, "ConnectStream#" + ValidationHelper.HashString(this) + "::Abort");
     CloseInternal(
                   (closeState & CloseExState.Silent) != 0,
                   (closeState & CloseExState.Abort) != 0
                   );
     GC.SuppressFinalize(this);
 }
        void ICloseEx.CloseEx(CloseExState closeState) {
            GlobalLog.Enter("FileWebResponse::Close()");
            try {
                if (!m_closed) {
                    m_closed = true;

                    Stream chkStream = m_stream;
                    if (chkStream!=null) {
                        if (chkStream is ICloseEx)
                            ((ICloseEx)chkStream).CloseEx(closeState);
                        else
                            chkStream.Close();
                        m_stream = null;
                    }
                }
            }
            finally {
                GlobalLog.Leave("FileWebResponse::Close()");
            }
        }
        protected virtual void Dispose(bool disposing, CloseExState closeState) {

            // All calls below should already be idempotent.

            try
            {
                if (disposing) {

                    ICloseEx icloseEx = WrappedStream as ICloseEx;

                    if (icloseEx != null) {
                        icloseEx.CloseEx(closeState);
                    }
                    else {
                        WrappedStream.Close();
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }

        }
 public void CloseEx(CloseExState closeState)
 {
     if ((closeState & CloseExState.Abort) != CloseExState.Normal)
     {
         this.m_Aborted = true;
     }
     try
     {
         this.Close();
     }
     catch
     {
         if ((closeState & CloseExState.Silent) == CloseExState.Normal)
         {
             throw;
         }
     }
 }