Files
swift-nio/Sources/NIOCore/NIOCloseOnErrorHandler.swift
T
Cory Benfield cdf27b6160 Move the first-party ChannelHandlers to NIOCore. (#1929)
Motivation:

NIO supplies a number of first-party ChannelHandlers that cover specific
use-cases. These aren't tied to the POSIX IO layer and so they should
come out.

Modifications:

- Move ChannelHandlers.swift to NIOCore
- Move NIOCloseOnErrorHandler.swift to NIOCore

Result:

Helper handlers in NIOCore
2021-08-05 10:09:08 +01:00

29 lines
921 B
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2019 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/// A `ChannelInboundHandler` that closes the channel when an error is caught
public final class NIOCloseOnErrorHandler: ChannelInboundHandler {
public typealias InboundIn = NIOAny
/// Initialize a `NIOCloseOnErrorHandler`
public init() {}
public func errorCaught(context: ChannelHandlerContext, error: Error) {
context.fireErrorCaught(error)
context.close(promise: nil)
}
}