Files
swift-nio-ssl/Sources/NIOSSL/NIOSSLServerHandler.swift
T
George Barnett 4f9d64ddd0 Add a timeout for TLS shutdown. (#100)
Motivation:

The remote peer may not always respond to a close notify. This would
leave the SSL handler waiting to shutdown. The shutdown should timeout
in these cases to ensure shutdown completes.

Modifications:

- Added a shutdown timeout to the NIOSSLHandler, and a configurable
  timeout amount to TLSConfiguration.
- Added a test to validate timing out a shutdown.

Result:

TLS shutdown will complete even if the remote peer does not respond to a
close notify.
2019-04-15 09:56:01 +01:00

35 lines
1.3 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2018 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
//
//===----------------------------------------------------------------------===//
import NIO
/// A channel handler that wraps a channel in TLS using NIOSSL. This
/// handler can be used in channels that are acting as the server in
/// the TLS dialog. For client connections, use the `NIOSSLClientHandler`.
public final class NIOSSLServerHandler: NIOSSLHandler {
public init(context: NIOSSLContext, verificationCallback: NIOSSLVerificationCallback? = nil) throws {
guard let connection = context.createConnection() else {
throw NIOSSLError.unableToAllocateBoringSSLObject
}
connection.setAcceptState()
if let verificationCallback = verificationCallback {
connection.setVerificationCallback(verificationCallback)
}
super.init(connection: connection, shutdownTimeout: context.configuration.shutdownTimeout)
}
}