Beispiel #1
0
        /// <summary>
        /// Checks if a <see cref="Exception"/> is due to various low-level errors indicating the connection has been terminated.
        /// </summary>
        /// <param name="ex">The exception.</param>
        /// <returns><c>true</c> if the exception indicates the closed has been terminated; <c>false</c> otherwise.</returns>
        public static bool ExceptionMeansConnectionTerminated(this Exception ex)
        {
            var terminated = false;

            // Errors indicating problems with connections
            terminated = terminated || ex.WebSocketExceptionMeansConnectionTerminated();
            terminated = terminated || ex.SocketExceptionMeansConnectionTerminated();

            // Errors indicating the connection has already been closed when attempting to do something
            terminated = terminated || ex.HttpListenerExceptionMeansConnectionTerminated();
            terminated = terminated || ex.ApplicationExceptionMeansConnectionTerminated();
            terminated = terminated || ex.InvalidOperationExceptionMeansConnectionTerminated();

            return(terminated);
        }