From d55c582e5cbb2efc6b995285a9e90e6b20cba53a Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Mon, 25 Mar 2019 10:09:16 +0000 Subject: [PATCH] improve documentation (#919) Motivation: Spotted a couple of issues with the documentation and fixed them. Modifications: - explicitly marked all `public class`es as `public final class` to get consistency in the Jazzy documentation. - removed `public` extension methods of the `internal struct PriorityQueue` which Jazzy showed in the docs. - improved the largely missing `EmbeddedChannel` and `EmbeddedEventLoop` documentation. - clear up lies in the B2MD docs - add some other missing docs Result: better docs makes happier users --- Sources/NIO/ChannelHandlers.swift | 4 +- Sources/NIO/CircularBuffer.swift | 7 + Sources/NIO/Codec.swift | 41 ++++-- Sources/NIO/Embedded.swift | 136 +++++++++++++++--- Sources/NIO/PriorityQueue.swift | 2 +- Sources/NIO/ServerSocket.swift | 2 +- Sources/NIOConcurrencyHelpers/atomics.swift | 2 +- Sources/NIOHTTP1/HTTPDecoder.swift | 2 +- Sources/NIOHTTP1/HTTPUpgradeHandler.swift | 2 +- ...pplicationProtocolNegotiationHandler.swift | 2 +- Sources/NIOTLS/SNIHandler.swift | 2 +- Tests/NIOTests/AcceptBackoffHandlerTest.swift | 2 +- Tests/NIOTests/ChannelTests.swift | 2 +- Tests/NIOTests/CodecTest.swift | 4 +- Tests/NIOTests/EmbeddedEventLoopTest.swift | 2 +- Tests/NIOTests/EventLoopTest.swift | 2 +- Tests/NIOTests/HappyEyeballsTest.swift | 2 +- Tests/NIOTests/IntegerTypesTest.swift | 2 +- Tests/NIOTests/RecvByteBufAllocatorTest.swift | 2 +- Tests/NIOTests/SocketChannelTest.swift | 2 +- .../WebSocketFrameDecoderTest.swift | 2 +- .../WebSocketFrameEncoderTest.swift | 2 +- 22 files changed, 176 insertions(+), 50 deletions(-) diff --git a/Sources/NIO/ChannelHandlers.swift b/Sources/NIO/ChannelHandlers.swift index 1d59f282c..cf69a9bc9 100644 --- a/Sources/NIO/ChannelHandlers.swift +++ b/Sources/NIO/ChannelHandlers.swift @@ -107,7 +107,7 @@ public final class AcceptBackoffHandler: ChannelDuplexHandler, RemovableChannelH ChannelHandler implementation which enforces back-pressure by stopping to read from the remote peer when it cannot write back fast enough. It will start reading again once pending data was written. */ -public class BackPressureHandler: ChannelDuplexHandler, RemovableChannelHandler { +public final class BackPressureHandler: ChannelDuplexHandler, RemovableChannelHandler { public typealias OutboundIn = NIOAny public typealias InboundIn = ByteBuffer public typealias InboundOut = ByteBuffer @@ -151,7 +151,7 @@ public class BackPressureHandler: ChannelDuplexHandler, RemovableChannelHandler } /// Triggers an IdleStateEvent when a Channel has not performed read, write, or both operation for a while. -public class IdleStateHandler: ChannelDuplexHandler, RemovableChannelHandler { +public final class IdleStateHandler: ChannelDuplexHandler, RemovableChannelHandler { public typealias InboundIn = NIOAny public typealias InboundOut = NIOAny public typealias OutboundIn = NIOAny diff --git a/Sources/NIO/CircularBuffer.swift b/Sources/NIO/CircularBuffer.swift index 6c50951cf..33ef9c15d 100644 --- a/Sources/NIO/CircularBuffer.swift +++ b/Sources/NIO/CircularBuffer.swift @@ -55,6 +55,13 @@ public struct CircularBuffer: CustomStringConvertible { return (index + by) & self.mask } + /// An opaque `CircularBuffer` index. + /// + /// You may get indices offset from other indices by using `CircularBuffer.index(:offsetBy:)`, + /// `CircularBuffer.index(before:)`, or `CircularBuffer.index(after:)`. + /// + /// - note: Every index is invalidated as soon as you perform a length-changing operating on the `CircularBuffer` + /// but remains valid when you replace one item by another using the subscript. public struct Index: Comparable { @usableFromInline var _backingIndex: UInt32 @usableFromInline var _backingCheck: _UInt24 = .max diff --git a/Sources/NIO/Codec.swift b/Sources/NIO/Codec.swift index dab1a1f5d..057285e26 100644 --- a/Sources/NIO/Codec.swift +++ b/Sources/NIO/Codec.swift @@ -35,8 +35,16 @@ public enum ByteToMessageDecoderError: Error { case leftoverDataWhenDone(ByteBuffer) } -/// `ChannelInboundHandler` which decodes bytes in a stream-like fashion from one `ByteBuffer` to -/// another message type. +/// `ByteToMessageDecoder`s decode bytes in a stream-like fashion from `ByteBuffer` to another message type. +/// +/// To add a `ByteToMessageDecoder` to the `ChannelPipeline` use +/// +/// channel.pipeline.addHandler(ByteToMessageHandler(MyByteToMessageDecoder())) +/// +/// `ByteToMessageHandler` will turn your `ByteToMessageDecoder` into a `ChannelInboundHandler`. `ByteToMessageHandler` +/// also solves a couple of tricky issues for you, most importantly, in a `ByteToMessageDecoder` you do _not_ need to +/// worry about re-entrancy. You own the passed-in `ByteBuffer` for the duration of the `decode`/`decodeLast` call an +/// can modify it at will. /// /// If a custom frame decoder is required, then one needs to be careful when implementing /// one with `ByteToMessageDecoder`. Ensure there are enough bytes in the buffer for a @@ -49,16 +57,22 @@ public enum ByteToMessageDecoderError: Error { /// is not always the case. Use `buffer.getInteger(at: buffer.readerIndex)` instead. /// /// If you move the reader index forward, either manually or by using one of `buffer.read*` methods, you must ensure -/// that you no longer need to see those bytes again as they will not be returned to you the next time `decode` is called. -/// If you still need those bytes to come back, consider taking a local copy of buffer inside the function to perform your read operations on. +/// that you no longer need to see those bytes again as they will not be returned to you the next time `decode` is +/// called. If you still need those bytes to come back, consider taking a local copy of buffer inside the function to +/// perform your read operations on. /// -/// The `ByteBuffer` passed in as `buffer` is a slice of a larger buffer owned by the `ByteToMessageDecoder` implementation. Some aspects of this buffer are preserved across calls to `decode`, meaning that any changes to those properties you make in your `decode` method will be reflected in the next call to decode. In particular, the following operations are have the described effects: - -/// 1. Moving the reader index forward persists across calls. When your method returns, if the reader index has advanced, those bytes are considered "consumed" and will not be available in future calls to `decode`. -/// Please note, however, that the numerical value of the `readerIndex` itself is not preserved, and may not be the same from one call to the next. Please do not rely on this numerical value: if you need -/// to recall where a byte is relative to the `readerIndex`, use an offset rather than an absolute value. -/// 2. Mutating the bytes in the buffer will cause undefined behaviour and likely crash your program +/// The `ByteBuffer` passed in as `buffer` is a slice of a larger buffer owned by the `ByteToMessageDecoder` +/// implementation. Some aspects of this buffer are preserved across calls to `decode`, meaning that any changes to +/// those properties you make in your `decode` method will be reflected in the next call to decode. In particular, +/// the following operations are have the described effects: +/// +/// Moving the reader index forward persists across calls. When your method returns, if the reader index has advanced, +/// those bytes are considered "consumed" and will not be available in future calls to `decode`. +/// Please note, however, that the numerical value of the `readerIndex` itself is not preserved, and may not be the same +/// from one call to the next. Please do not rely on this numerical value: if you need +/// to recall where a byte is relative to the `readerIndex`, use an offset rather than an absolute value. public protocol ByteToMessageDecoder { + /// The type of the messages this `ByteToMessageDecoder` decodes to. associatedtype InboundOut /// Decode from a `ByteBuffer`. This method will be called till either the input @@ -265,7 +279,12 @@ private extension B2MDBuffer { } } -public class ByteToMessageHandler { +/// A handler which turnsĀ a given `ByteToMessageDecoder` into a `ChannelInboundHandler` that can then be added to a +/// `ChannelPipeline`. +/// +/// Most importantly, `ByteToMessageHandler` handles the tricky buffer management for you and flattens out all +/// re-entrancy on `channelRead` that may happen in the `ChannelPipeline`. +public final class ByteToMessageHandler { public typealias InboundIn = ByteBuffer public typealias InboundOut = Decoder.InboundOut diff --git a/Sources/NIO/Embedded.swift b/Sources/NIO/Embedded.swift index 3387a9a0d..1677a2cdd 100644 --- a/Sources/NIO/Embedded.swift +++ b/Sources/NIO/Embedded.swift @@ -46,18 +46,21 @@ extension EmbeddedScheduledTask: Comparable { /// is because it is intended to be run in the thread that instantiated it. Users are /// responsible for ensuring they never call into the `EmbeddedEventLoop` in an /// unsynchronized fashion. -public class EmbeddedEventLoop: EventLoop { +public final class EmbeddedEventLoop: EventLoop { /// The current "time" for this event loop. This is an amount in nanoseconds. private var now: NIODeadline = .uptimeNanoseconds(0) private var scheduledTasks = PriorityQueue(ascending: true) + /// - see: `EventLoop.inEventLoop` public var inEventLoop: Bool { return true } + /// Initialize a new `EmbeddedEventLoop`. public init() { } + /// - see: `EventLoop.scheduleTask(deadline:_:)` @discardableResult public func scheduleTask(deadline: NIODeadline, _ task: @escaping () throws -> T) -> Scheduled { let promise: EventLoopPromise = makePromise() @@ -76,18 +79,23 @@ public class EmbeddedEventLoop: EventLoop { return scheduled } + /// - see: `EventLoop.scheduleTask(in:_:)` @discardableResult public func scheduleTask(in: TimeAmount, _ task: @escaping () throws -> T) -> Scheduled { return scheduleTask(deadline: self.now + `in`, task) } - // We're not really running a loop here. Tasks aren't run until run() is called, - // at which point we run everything that's been submitted. Anything newly submitted - // either gets on that train if it's still moving or waits until the next call to run(). + /// On an `EmbeddedEventLoop`, `execute` will simply use `scheduleTask` with a deadline of _now_. This means that + /// `task` will be run the next time you call `EmbeddedEventLoop.run`. public func execute(_ task: @escaping () -> Void) { self.scheduleTask(deadline: self.now, task) } + /// Run all tasks that have previously been submitted to this `EmbeddedEventLoop`, either by calling `execute` or + /// events that have been enqueued using `scheduleTask`/`scheduleRepeatedTask`/`scheduleRepeatedAsyncTask` and whose + /// deadlines have expired. + /// + /// - seealso: `EmbeddedEventLoop.advanceTime`. public func run() { // Execute all tasks that are currently enqueued to be executed *now*. self.advanceTime(by: .nanoseconds(0)) @@ -124,10 +132,12 @@ public class EmbeddedEventLoop: EventLoop { self.now = newTime } + /// - see: `EventLoop.close` func close() throws { // Nothing to do here } + /// - see: `EventLoop.shutdownGracefully` public func shutdownGracefully(queue: DispatchQueue, _ callback: @escaping (Error?) -> Void) { run() queue.sync { @@ -288,11 +298,22 @@ class EmbeddedChannelCore: ChannelCore { /// responsible for ensuring they never call into an `EmbeddedChannel` in an /// unsynchronized fashion. `EmbeddedEventLoop`s notes also apply as /// `EmbeddedChannel` uses an `EmbeddedEventLoop` as its `EventLoop`. -public class EmbeddedChannel: Channel { +public final class EmbeddedChannel: Channel { + /// `LeftOverState` represents any left-over inbound, outbound, and pending outbound events that hit the + /// `EmbeddedChannel` and were not consumed when `finish` was called on the `EmbeddedChannel`. + /// + /// `EmbeddedChannel` is most useful in testing and usually in unit tests, you want to consume all inbound and + /// outbound data to verify they are what you expect. Therefore, when you `finish` an `EmbeddedChannel` it will + /// return if it's either `.clean` (no left overs) or that it has `.leftOvers`. public enum LeftOverState { + /// The `EmbeddedChannel` is clean, ie. no inbound, outbound, or pending outbound data left on `finish`. case clean + + /// The `EmbeddedChannel` has inbound, outbound, or pending outbound data left on `finish`. case leftOvers(inbound: [NIOAny], outbound: [NIOAny], pendingOutbound: [NIOAny]) + /// `true` if the `EmbeddedChannel` was `clean` on `finish`, ie. there is no unconsumed inbound, outbound, or + /// pending outbound data left on the `Channel`. public var isClean: Bool { if case .clean = self { return true @@ -301,15 +322,28 @@ public class EmbeddedChannel: Channel { } } + /// `true` if the `EmbeddedChannel` if there was unconsumed inbound, outbound, or pending outbound data left + /// on the `Channel` when it was `finish`ed. public var hasLeftOvers: Bool { return !self.isClean } } + /// `BufferState` represents the state of either the inbound, or the outbound `EmbeddedChannel` buffer. These + /// buffers contain data that travelled the `ChannelPipeline` all the way. + /// + /// If the last `ChannelHandler` explicitly (by calling `fireChannelRead`) or implicitly (by not implementing + /// `channelRead`) sends inbound data into the end of the `EmbeddedChannel`, it will be held in the + /// `EmbeddedChannel`'s inbound buffer. Similarly for `write` on the outbound side. The state of the respective + /// buffer will be returned from `writeInbound`/`writeOutbound` as a `BufferState`. public enum BufferState { + /// The buffer is empty. case empty + + /// The buffer is non-empty. case full([NIOAny]) + /// Returns `true` is the buffer was empty. public var isEmpty: Bool { if case .empty = self { return true @@ -318,24 +352,49 @@ public class EmbeddedChannel: Channel { } } + /// Returns `true` if the buffer was non-empty. public var isFull: Bool { return !self.isEmpty } } + /// `WrongTypeError` is throws if you use `readInbound` or `readOutbound` and request a certain type but the first + /// item in the respective buffer is of a different type. + public struct WrongTypeError: Error, Equatable { + /// The type you expected. + public let expected: Any.Type + + /// The type of the actual first element. + public let actual: Any.Type + + public static func == (lhs: WrongTypeError, rhs: WrongTypeError) -> Bool { + return lhs.expected == rhs.expected && lhs.actual == rhs.actual + } + } + + /// Returns `true` if the `EmbeddedChannel` is 'active'. + /// + /// An active `EmbeddedChannel` can be closed by calling `close` or `finish` on the `EmbeddedChannel`. + /// + /// - note: An `EmbeddedChannel` starts _inactive_ and can be activated, for example by calling `connect`. public var isActive: Bool { return channelcore.isActive } + + /// - see: `Channel.closeFuture` public var closeFuture: EventLoopFuture { return channelcore.closePromise.futureResult } private lazy var channelcore: EmbeddedChannelCore = EmbeddedChannelCore(pipeline: self._pipeline, eventLoop: self.eventLoop) + /// - see: `Channel._channelCore` public var _channelCore: ChannelCore { return channelcore } + /// - see: `Channel.pipeline` public var pipeline: ChannelPipeline { return _pipeline } + /// - see: `Channel.isWritable` public var isWritable: Bool { return true } @@ -346,9 +405,9 @@ public class EmbeddedChannel: Channel { /// `EmbeddedChannel` can be consumed using `throwIfErrorCaught`. /// /// - returns: The `LeftOverState` of the `EmbeddedChannel`. If all the inbound and outbound events have been - // consumed (using `readInbound` / `readOutbound`) and there are no pending outbound events (unflushed - // writes) this will be `.clean`. If there are any unconsumed inbound, outbound, or pending outbound - // events, the `EmbeddedChannel` will returns those as `.leftOvers(inbound:outbound:pendingOutbound:)`. + /// consumed (using `readInbound` / `readOutbound`) and there are no pending outbound events (unflushed + /// writes) this will be `.clean`. If there are any unconsumed inbound, outbound, or pending outbound + /// events, the `EmbeddedChannel` will returns those as `.leftOvers(inbound:outbound:pendingOutbound:)`. public func finish() throws -> LeftOverState { try close().wait() self.embeddedEventLoop.run() @@ -364,32 +423,54 @@ public class EmbeddedChannel: Channel { } private var _pipeline: ChannelPipeline! + + /// - see: `Channel.allocator` public var allocator: ByteBufferAllocator = ByteBufferAllocator() + + /// - see: `Channel.eventLoop` public var eventLoop: EventLoop { return self.embeddedEventLoop } + /// Returns the `EmbeddedEventLoop` that this `EmbeddedChannel` uses. This will return the same instance as + /// `EmbeddedChannel.eventLoop` but as the concrete `EmbeddedEventLoop` rather than as `EventLoop` existential. public var embeddedEventLoop: EmbeddedEventLoop = EmbeddedEventLoop() + /// - see: `Channel.localAddress` public var localAddress: SocketAddress? = nil + + /// - see: `Channel.remoteAddress` public var remoteAddress: SocketAddress? = nil - // Embedded channels never have parents. + /// `nil` because `EmbeddedChannel`s don't have parents. public let parent: Channel? = nil - public struct WrongTypeError: Error, Equatable { - public let expected: Any.Type - public let actual: Any.Type - - public static func == (lhs: WrongTypeError, rhs: WrongTypeError) -> Bool { - return lhs.expected == rhs.expected && lhs.actual == rhs.actual - } - } - + /// If available, this method reads one element of type `T` out of the `EmbeddedChannel`'s outbound buffer. If the + /// first element was of a different type than requested, `EmbeddedChannel.WrongTypeError` will be thrown, if there + /// are no elements in the outbound buffer, `nil` will be returned. + /// + /// Data hits the `EmbeddedChannel`'s outbound buffer when data was written using `write`, then `flush`ed, and + /// then travelled the `ChannelPipeline` all the way too the front. For data to hit the outbound buffer, the very + /// first `ChannelHandler` must have written and flushed it either explicitly (by calling + /// `ChannelHandlerContext.write` and `flush`) or implicitly by not implementing `write`/`flush`. + /// + /// - note: Outbound events travel the `ChannelPipeline` _back to front_. + /// - note: `EmbeddedChannel.writeOutbound` will `write` data through the `ChannelPipeline`, starting with last + /// `ChannelHandler`. public func readOutbound(as type: T.Type = T.self) throws -> T? { return try readFromBuffer(buffer: &channelcore.outboundBuffer) } + /// If available, this method reads one element of type `T` out of the `EmbeddedChannel`'s inbound buffer. If the + /// first element was of a different type than requested, `EmbeddedChannel.WrongTypeError` will be thrown, if there + /// are no elements in the outbound buffer, `nil` will be returned. + /// + /// Data hits the `EmbeddedChannel`'s inbound buffer when data was send through the pipeline using `fireChannelRead` + /// and then travelled the `ChannelPipeline` all the way too the back. For data to hit the inbound buffer, the + /// last `ChannelHandler` must have send the event either explicitly (by calling + /// `ChannelHandlerContext.fireChannelRead`) or implicitly by not implementing `channelRead`. + /// + /// - note: `EmbeddedChannel.writeInbound` will fire data through the `ChannelPipeline` using `fireChannelRead`. public func readInbound(as type: T.Type = T.self) throws -> T? { return try readFromBuffer(buffer: &channelcore.inboundBuffer) } @@ -425,6 +506,9 @@ public class EmbeddedChannel: Channel { return self.channelcore.outboundBuffer.isEmpty ? .empty : .full(self.channelcore.outboundBuffer) } + /// This method will throw the error that is stored in the `EmbeddedChannel` if any. + /// + /// The `EmbeddedChannel` will store an error some error travels the `ChannelPipeline` all the way past its end. public func throwIfErrorCaught() throws { if let error = channelcore.error { channelcore.error = nil @@ -463,11 +547,13 @@ public class EmbeddedChannel: Channel { try! register().wait() } + /// - see: `Channel.setOption` public func setOption(_ option: Option, value: Option.Value) -> EventLoopFuture { // No options supported fatalError("no options supported") } + /// - see: `Channel.getOption` public func getOption(_ option: Option) -> EventLoopFuture { if option is AutoReadOption { return self.eventLoop.makeSucceededFuture(true as! Option.Value) @@ -475,6 +561,13 @@ public class EmbeddedChannel: Channel { fatalError("option \(option) not supported") } + /// Fires the (outbound) `bind` event through the `ChannelPipeline`. If the event hits the `EmbeddedChannel` which + /// happens when it travels the `ChannelPipeline` all the way to the front, this will also set the + /// `EmbeddedChannel`'s `localAddress`. + /// + /// - parameters: + /// - address: The address to fake-bind to. + /// - promise: The `EventLoopPromise` which will be fulfilled when the fake-bind operation has been done. public func bind(to address: SocketAddress, promise: EventLoopPromise?) { promise?.futureResult.whenSuccess { self.localAddress = address @@ -482,6 +575,13 @@ public class EmbeddedChannel: Channel { pipeline.bind(to: address, promise: promise) } + /// Fires the (outbound) `connect` event through the `ChannelPipeline`. If the event hits the `EmbeddedChannel` + /// which happens when it travels the `ChannelPipeline` all the way to the front, this will also set the + /// `EmbeddedChannel`'s `remoteAddress`. + /// + /// - parameters: + /// - address: The address to fake-bind to. + /// - promise: The `EventLoopPromise` which will be fulfilled when the fake-bind operation has been done. public func connect(to address: SocketAddress, promise: EventLoopPromise?) { promise?.futureResult.whenSuccess { self.remoteAddress = address diff --git a/Sources/NIO/PriorityQueue.swift b/Sources/NIO/PriorityQueue.swift index 1ea87fcaa..7c410434f 100644 --- a/Sources/NIO/PriorityQueue.swift +++ b/Sources/NIO/PriorityQueue.swift @@ -53,7 +53,7 @@ internal struct PriorityQueue { } extension PriorityQueue: Equatable { - public static func ==(lhs: PriorityQueue, rhs: PriorityQueue) -> Bool { + internal static func ==(lhs: PriorityQueue, rhs: PriorityQueue) -> Bool { return lhs.count == rhs.count && lhs.elementsEqual(rhs) } } diff --git a/Sources/NIO/ServerSocket.swift b/Sources/NIO/ServerSocket.swift index 0380a69a3..79ae9f8e0 100644 --- a/Sources/NIO/ServerSocket.swift +++ b/Sources/NIO/ServerSocket.swift @@ -14,7 +14,7 @@ /// A server socket that can accept new connections. /* final but tests */ class ServerSocket: BaseSocket { - public class func bootstrap(protocolFamily: Int32, host: String, port: Int) throws -> ServerSocket { + public final class func bootstrap(protocolFamily: Int32, host: String, port: Int) throws -> ServerSocket { let socket = try ServerSocket(protocolFamily: protocolFamily) try socket.bind(to: SocketAddress.makeAddressResolvingHost(host, port: port)) try socket.listen() diff --git a/Sources/NIOConcurrencyHelpers/atomics.swift b/Sources/NIOConcurrencyHelpers/atomics.swift index 8dd5fab62..38dd180f6 100644 --- a/Sources/NIOConcurrencyHelpers/atomics.swift +++ b/Sources/NIOConcurrencyHelpers/atomics.swift @@ -391,7 +391,7 @@ extension UInt: AtomicPrimitive { /// `AtomicBox` is a heap-allocated box which allows atomic access to an instance of a Swift class. /// /// It behaves very much like `Atomic` but for objects, maintaining the correct retain counts. -public class AtomicBox { +public final class AtomicBox { private let storage: Atomic public init(value: T) { diff --git a/Sources/NIOHTTP1/HTTPDecoder.swift b/Sources/NIOHTTP1/HTTPDecoder.swift index a51a5a35f..fe76cbf0f 100644 --- a/Sources/NIOHTTP1/HTTPDecoder.swift +++ b/Sources/NIOHTTP1/HTTPDecoder.swift @@ -430,7 +430,7 @@ extension HTTPDecoder: WriteObservingByteToMessageDecoder where In == HTTPClient /// either the form of `HTTPClientResponsePart` or `HTTPServerRequestPart`: that is, /// it produces messages that correspond to the semantic units of HTTP produced by /// the remote peer. -public class HTTPDecoder: ByteToMessageDecoder, HTTPDecoderDelegate { +public final class HTTPDecoder: ByteToMessageDecoder, HTTPDecoderDelegate { public typealias InboundOut = In // things we build incrementally diff --git a/Sources/NIOHTTP1/HTTPUpgradeHandler.swift b/Sources/NIOHTTP1/HTTPUpgradeHandler.swift index 4baade48f..8d99e62dd 100644 --- a/Sources/NIOHTTP1/HTTPUpgradeHandler.swift +++ b/Sources/NIOHTTP1/HTTPUpgradeHandler.swift @@ -59,7 +59,7 @@ public protocol HTTPServerProtocolUpgrader { /// sufficiently difficult to ensure that the upgrade happens at a safe time while dealing with pipelined /// requests that we choose to punt on it entirely and not allow it. As it happens this is mostly fine: /// the odds of someone needing to upgrade midway through the lifetime of a connection are very low. -public class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHandler { +public final class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHandler { public typealias InboundIn = HTTPServerRequestPart public typealias InboundOut = HTTPServerRequestPart public typealias OutboundOut = HTTPServerResponsePart diff --git a/Sources/NIOTLS/ApplicationProtocolNegotiationHandler.swift b/Sources/NIOTLS/ApplicationProtocolNegotiationHandler.swift index 22afd6ffc..2df7ce806 100644 --- a/Sources/NIOTLS/ApplicationProtocolNegotiationHandler.swift +++ b/Sources/NIOTLS/ApplicationProtocolNegotiationHandler.swift @@ -56,7 +56,7 @@ public enum ALPNResult: Equatable { /// down the channel. Then, finally, this channel handler will automatically remove /// itself from the channel pipeline, leaving the pipeline in its final /// configuration. -public class ApplicationProtocolNegotiationHandler: ChannelInboundHandler, RemovableChannelHandler { +public final class ApplicationProtocolNegotiationHandler: ChannelInboundHandler, RemovableChannelHandler { public typealias InboundIn = Any public typealias InboundOut = Any diff --git a/Sources/NIOTLS/SNIHandler.swift b/Sources/NIOTLS/SNIHandler.swift index 82e67d279..85be49ad7 100644 --- a/Sources/NIOTLS/SNIHandler.swift +++ b/Sources/NIOTLS/SNIHandler.swift @@ -94,7 +94,7 @@ private extension Sequence where Element == UInt8 { /// TLS backends that can be used with NIO. It also allows for the pipeline change to /// be done asynchronously, providing more flexibility about how the user configures the /// pipeline. -public class SNIHandler: ByteToMessageDecoder { +public final class SNIHandler: ByteToMessageDecoder { public var cumulationBuffer: ByteBuffer? public typealias InboundIn = ByteBuffer public typealias InboundOut = ByteBuffer diff --git a/Tests/NIOTests/AcceptBackoffHandlerTest.swift b/Tests/NIOTests/AcceptBackoffHandlerTest.swift index e041077a3..b1615d8aa 100644 --- a/Tests/NIOTests/AcceptBackoffHandlerTest.swift +++ b/Tests/NIOTests/AcceptBackoffHandlerTest.swift @@ -17,7 +17,7 @@ import XCTest import NIOConcurrencyHelpers -public class AcceptBackoffHandlerTest: XCTestCase { +public final class AcceptBackoffHandlerTest: XCTestCase { private let acceptHandlerName = "AcceptBackoffHandler" diff --git a/Tests/NIOTests/ChannelTests.swift b/Tests/NIOTests/ChannelTests.swift index 0bb3f6958..8320b5675 100644 --- a/Tests/NIOTests/ChannelTests.swift +++ b/Tests/NIOTests/ChannelTests.swift @@ -69,7 +69,7 @@ class ChannelLifecycleHandler: ChannelInboundHandler { } } -public class ChannelTests: XCTestCase { +public final class ChannelTests: XCTestCase { func testBasicLifecycle() throws { let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { diff --git a/Tests/NIOTests/CodecTest.swift b/Tests/NIOTests/CodecTest.swift index b30c923ee..492176c7d 100644 --- a/Tests/NIOTests/CodecTest.swift +++ b/Tests/NIOTests/CodecTest.swift @@ -50,7 +50,7 @@ private final class ChannelInactivePromiser: ChannelInboundHandler { } } -public class ByteToMessageDecoderTest: XCTestCase { +public final class ByteToMessageDecoderTest: XCTestCase { private final class ByteToInt32Decoder : ByteToMessageDecoder { typealias InboundIn = ByteBuffer typealias InboundOut = Int32 @@ -1306,7 +1306,7 @@ public class ByteToMessageDecoderTest: XCTestCase { } } -public class MessageToByteEncoderTest: XCTestCase { +public final class MessageToByteEncoderTest: XCTestCase { private struct Int32ToByteEncoder: MessageToByteEncoder { typealias OutboundIn = Int32 diff --git a/Tests/NIOTests/EmbeddedEventLoopTest.swift b/Tests/NIOTests/EmbeddedEventLoopTest.swift index 9ec0ebb69..8ef0e1d3b 100644 --- a/Tests/NIOTests/EmbeddedEventLoopTest.swift +++ b/Tests/NIOTests/EmbeddedEventLoopTest.swift @@ -17,7 +17,7 @@ import XCTest private class EmbeddedTestError: Error { } -public class EmbeddedEventLoopTest: XCTestCase { +public final class EmbeddedEventLoopTest: XCTestCase { func testExecuteDoesNotImmediatelyRunTasks() throws { var callbackRan = false let loop = EmbeddedEventLoop() diff --git a/Tests/NIOTests/EventLoopTest.swift b/Tests/NIOTests/EventLoopTest.swift index 53bbb6332..a913a1c5e 100644 --- a/Tests/NIOTests/EventLoopTest.swift +++ b/Tests/NIOTests/EventLoopTest.swift @@ -16,7 +16,7 @@ import XCTest import Dispatch import NIOConcurrencyHelpers -public class EventLoopTest : XCTestCase { +public final class EventLoopTest : XCTestCase { public func testSchedule() throws { let nanos: NIODeadline = .now() diff --git a/Tests/NIOTests/HappyEyeballsTest.swift b/Tests/NIOTests/HappyEyeballsTest.swift index 7373d9e95..257dda051 100644 --- a/Tests/NIOTests/HappyEyeballsTest.swift +++ b/Tests/NIOTests/HappyEyeballsTest.swift @@ -233,7 +233,7 @@ private func buildEyeballer(host: String, return (eyeballer: eyeballer, resolver: resolver, loop: loop) } -public class HappyEyeballsTest : XCTestCase { +public final class HappyEyeballsTest : XCTestCase { func testIPv4OnlyResolution() throws { let (eyeballer, resolver, loop) = buildEyeballer(host: "example.com", port: 80) let targetFuture = eyeballer.resolveAndConnect().flatMapThrowing { (channel) -> String? in diff --git a/Tests/NIOTests/IntegerTypesTest.swift b/Tests/NIOTests/IntegerTypesTest.swift index d0731b61c..3c33505c1 100644 --- a/Tests/NIOTests/IntegerTypesTest.swift +++ b/Tests/NIOTests/IntegerTypesTest.swift @@ -15,7 +15,7 @@ import XCTest @testable import NIO -public class IntegerTypesTest: XCTestCase { +public final class IntegerTypesTest: XCTestCase { func testNextPowerOfOfTwoZero() { XCTAssertEqual(1, (0 as UInt).nextPowerOf2()) XCTAssertEqual(1, (0 as UInt16).nextPowerOf2()) diff --git a/Tests/NIOTests/RecvByteBufAllocatorTest.swift b/Tests/NIOTests/RecvByteBufAllocatorTest.swift index 922696419..39a7991bf 100644 --- a/Tests/NIOTests/RecvByteBufAllocatorTest.swift +++ b/Tests/NIOTests/RecvByteBufAllocatorTest.swift @@ -15,7 +15,7 @@ import XCTest import NIO -public class AdaptiveRecvByteBufferAllocatorTest : XCTestCase { +public final class AdaptiveRecvByteBufferAllocatorTest : XCTestCase { private let allocator = ByteBufferAllocator() private var adaptive = AdaptiveRecvByteBufferAllocator(minimum: 64, initial: 1024, maximum: 16 * 1024) private var fixed = FixedSizeRecvByteBufferAllocator(capacity: 1024) diff --git a/Tests/NIOTests/SocketChannelTest.swift b/Tests/NIOTests/SocketChannelTest.swift index 5323ec4d0..d91828b6d 100644 --- a/Tests/NIOTests/SocketChannelTest.swift +++ b/Tests/NIOTests/SocketChannelTest.swift @@ -26,7 +26,7 @@ private extension Array { } } -public class SocketChannelTest : XCTestCase { +public final class SocketChannelTest : XCTestCase { /// Validate that channel options are applied asynchronously. public func testAsyncSetOption() throws { let group = MultiThreadedEventLoopGroup(numberOfThreads: 2) diff --git a/Tests/NIOWebSocketTests/WebSocketFrameDecoderTest.swift b/Tests/NIOWebSocketTests/WebSocketFrameDecoderTest.swift index 80a8afc61..9b8e26b37 100644 --- a/Tests/NIOWebSocketTests/WebSocketFrameDecoderTest.swift +++ b/Tests/NIOWebSocketTests/WebSocketFrameDecoderTest.swift @@ -56,7 +56,7 @@ private final class SynchronousCloser: ChannelInboundHandler { } } -public class WebSocketFrameDecoderTest: XCTestCase { +public final class WebSocketFrameDecoderTest: XCTestCase { public var decoderChannel: EmbeddedChannel! public var encoderChannel: EmbeddedChannel! public var buffer: ByteBuffer! diff --git a/Tests/NIOWebSocketTests/WebSocketFrameEncoderTest.swift b/Tests/NIOWebSocketTests/WebSocketFrameEncoderTest.swift index c15178209..220607aec 100644 --- a/Tests/NIOWebSocketTests/WebSocketFrameEncoderTest.swift +++ b/Tests/NIOWebSocketTests/WebSocketFrameEncoderTest.swift @@ -32,7 +32,7 @@ extension EmbeddedChannel { } } -public class WebSocketFrameEncoderTest: XCTestCase { +public final class WebSocketFrameEncoderTest: XCTestCase { public var channel: EmbeddedChannel! public var buffer: ByteBuffer!