diff --git a/Sources/NIO/Bootstrap.swift b/Sources/NIO/Bootstrap.swift index fa6cfdc7c..38e7860b5 100644 --- a/Sources/NIO/Bootstrap.swift +++ b/Sources/NIO/Bootstrap.swift @@ -16,7 +16,7 @@ import Foundation import Sockets import Future -public class ServerBootstrap { +public final class ServerBootstrap { private let group: EventLoopGroup private let childGroup: EventLoopGroup @@ -163,7 +163,7 @@ public class ServerBootstrap { } } -public class ClientBootstrap { +public final class ClientBootstrap { private let group: EventLoopGroup private var handler: ChannelHandler? diff --git a/Sources/NIO/Channel.swift b/Sources/NIO/Channel.swift index 845473ad9..466a42ab0 100644 --- a/Sources/NIO/Channel.swift +++ b/Sources/NIO/Channel.swift @@ -115,7 +115,7 @@ func makeNonThrowing(errorBuffer: inout Error?, input: I, _ fn: (I) throws -> } } -fileprivate class PendingWrites { +final fileprivate class PendingWrites { private var head: PendingWrite? private var tail: PendingWrite? @@ -581,15 +581,15 @@ extension Channel { class BaseSocketChannel : SelectableChannel, ChannelCore { - public var selectable: Selectable { return socket } + public final var selectable: Selectable { return socket } - public var _unsafe: ChannelCore { return self } + public final var _unsafe: ChannelCore { return self } // Visible to access from EventLoop directly let socket: BaseSocket public var interestedEvent: InterestedEvent = .none - public var closed: Bool { + public final var closed: Bool { return pendingWrites.closed } @@ -599,17 +599,17 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { private var pendingConnect: Promise? private let closePromise: Promise - public var closeFuture: Future { + public final var closeFuture: Future { return closePromise.futureResult } private let selectableEventLoop: SelectableEventLoop - public var eventLoop: EventLoop { + public final var eventLoop: EventLoop { return selectableEventLoop } - public var allocator: ByteBufferAllocator { + public final var allocator: ByteBufferAllocator { if eventLoop.inEventLoop { return bufferAllocator } else { @@ -623,13 +623,13 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { fileprivate var maxMessagesPerRead: UInt = 1 // We don't use lazy var here as this is more expensive then doing this :/ - public var pipeline: ChannelPipeline { + public final var pipeline: ChannelPipeline { return _pipeline } private var _pipeline: ChannelPipeline! - public func setOption(option: T, value: T.OptionType) throws { + public final func setOption(option: T, value: T.OptionType) throws { if eventLoop.inEventLoop { try setOption0(option: option, value: value) } else { @@ -666,7 +666,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { } } - public func getOption(option: T) throws -> T.OptionType { + public final func getOption(option: T) throws -> T.OptionType { if eventLoop.inEventLoop { return try getOption0(option: option) } else { @@ -699,53 +699,53 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { fatalError("option \(option) not supported") } - public var localAddress: SocketAddress? { + public final var localAddress: SocketAddress? { get { return socket.localAddress } } - public var remoteAddress: SocketAddress? { + public final var remoteAddress: SocketAddress? { get { return socket.remoteAddress } } - public func readIfNeeded0() { + public final func readIfNeeded0() { if autoRead { pipeline.read0() } } - @discardableResult public func register(promise: Promise) -> Future { + @discardableResult public final func register(promise: Promise) -> Future { return pipeline.register(promise: promise) } - @discardableResult public func bind(local: SocketAddress, promise: Promise) -> Future { + @discardableResult public final func bind(local: SocketAddress, promise: Promise) -> Future { return pipeline.bind(local: local, promise: promise) } - @discardableResult public func connect(remote: SocketAddress, promise: Promise) -> Future { + @discardableResult public final func connect(remote: SocketAddress, promise: Promise) -> Future { return pipeline.connect(remote: remote, promise: promise) } - @discardableResult public func write(data: Any, promise: Promise) -> Future { + @discardableResult public final func write(data: Any, promise: Promise) -> Future { return pipeline.write(data: data, promise: promise) } - public func flush() { + public final func flush() { pipeline.flush() } - public func read() { + public final func read() { pipeline.read() } - @discardableResult public func writeAndFlush(data: Any, promise: Promise) -> Future { + @discardableResult public final func writeAndFlush(data: Any, promise: Promise) -> Future { return pipeline.writeAndFlush(data: data, promise: promise) } - @discardableResult public func close(promise: Promise) -> Future { + @discardableResult public final func close(promise: Promise) -> Future { return pipeline.close(promise: promise) } @@ -788,7 +788,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { } } - public func flush0() { + public final func flush0() { assert(eventLoop.inEventLoop) guard !isWritePending() else { @@ -806,7 +806,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { } } - public func startReading0() { + public final func startReading0() { assert(eventLoop.inEventLoop) guard !closed else { @@ -817,7 +817,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { registerForReadable() } - public func stopReading0() { + public final func stopReading0() { assert(eventLoop.inEventLoop) guard !closed else { @@ -848,7 +848,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { } } - public func close0(promise: Promise = Promise(), error: Error = ChannelError.closed) { + public final func close0(promise: Promise = Promise(), error: Error = ChannelError.closed) { assert(eventLoop.inEventLoop) guard !closed else { @@ -885,7 +885,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { } - public func register0(promise: Promise) { + public final func register0(promise: Promise) { assert(eventLoop.inEventLoop) // Was not registered yet so do it now. @@ -900,7 +900,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { // Methods invoked from the EventLoop itself - public func writable() { + public final func writable() { assert(eventLoop.inEventLoop) assert(!closed) @@ -948,7 +948,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { } } - public func readable() { + public final func readable() { assert(eventLoop.inEventLoop) assert(!closed) @@ -999,7 +999,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { fatalError("this must be overridden by sub class") } - public func connect0(remote: SocketAddress, promise: Promise) { + public final func connect0(remote: SocketAddress, promise: Promise) { assert(eventLoop.inEventLoop) guard pendingConnect == nil else { @@ -1124,7 +1124,7 @@ public protocol RecvByteBufferAllocator { func buffer(allocator: ByteBufferAllocator) throws -> ByteBuffer } -public class FixedSizeRecvByteBufferAllocator : RecvByteBufferAllocator { +public final class FixedSizeRecvByteBufferAllocator : RecvByteBufferAllocator { let capacity: Int public init(capacity: Int) { diff --git a/Sources/NIO/ChannelPipeline.swift b/Sources/NIO/ChannelPipeline.swift index 80dd17f86..163158c34 100644 --- a/Sources/NIO/ChannelPipeline.swift +++ b/Sources/NIO/ChannelPipeline.swift @@ -20,7 +20,7 @@ import Sockets /* All operations on ChannelPipeline are thread-safe */ -public class ChannelPipeline : ChannelInboundInvoker { +public final class ChannelPipeline : ChannelInboundInvoker { private var head: ChannelHandlerContext? private var tail: ChannelHandlerContext? @@ -429,7 +429,7 @@ public class ChannelPipeline : ChannelInboundInvoker { } } -private class HeadChannelHandler : ChannelHandler { +private final class HeadChannelHandler : ChannelHandler { static let sharedInstance = HeadChannelHandler() @@ -486,7 +486,7 @@ private class HeadChannelHandler : ChannelHandler { } } -private class TailChannelHandler : ChannelHandler { +private final class TailChannelHandler : ChannelHandler { static let sharedInstance = TailChannelHandler() @@ -534,7 +534,7 @@ public enum ChannelPipelineException : Error { } -public class ChannelHandlerContext : ChannelInboundInvoker, ChannelOutboundInvoker { +public final class ChannelHandlerContext : ChannelInboundInvoker, ChannelOutboundInvoker { // visible for ChannelPipeline to modify and also marked as weak to ensure we not create a // reference-cycle for the doubly-linked-list diff --git a/Sources/Sockets/BaseSocket.swift b/Sources/Sockets/BaseSocket.swift index 8daa33cb6..75bdf7b74 100644 --- a/Sources/Sockets/BaseSocket.swift +++ b/Sources/Sockets/BaseSocket.swift @@ -33,12 +33,12 @@ public class BaseSocket : Selectable { public let descriptor: Int32 public private(set) var open: Bool - public var localAddress: SocketAddress? { + public final var localAddress: SocketAddress? { get { return nil } } - public var remoteAddress: SocketAddress? { + public final var remoteAddress: SocketAddress? { get { return nil } @@ -57,7 +57,7 @@ public class BaseSocket : Selectable { self.open = true } - public func setNonBlocking() throws { + public final func setNonBlocking() throws { guard self.open else { throw IOError(errno: EBADF, reason: "can't control file descriptor as it's not open anymore.") } @@ -67,7 +67,7 @@ public class BaseSocket : Selectable { } } - public func setOption(level: Int32, name: Int32, value: T) throws { + public final func setOption(level: Int32, name: Int32, value: T) throws { guard self.open else { throw IOError(errno: EBADF, reason: "can't set socket options as it's not open anymore.") } @@ -84,7 +84,7 @@ public class BaseSocket : Selectable { } } - public func getOption(level: Int32, name: Int32) throws -> T { + public final func getOption(level: Int32, name: Int32) throws -> T { guard self.open else { throw IOError(errno: EBADF, reason: "can't get socket options as it's not open anymore.") } @@ -102,7 +102,7 @@ public class BaseSocket : Selectable { return val.pointee } - public func bind(local: SocketAddress) throws { + public final func bind(local: SocketAddress) throws { switch local { case .v4(address: let addr): try bindSocket(addr: addr) @@ -126,7 +126,7 @@ public class BaseSocket : Selectable { } } - public func close() throws { + public final func close() throws { guard self.open else { throw IOError(errno: EBADF, reason: "can't close socket (as it's not open anymore.") } diff --git a/Sources/Sockets/Selector.swift b/Sources/Sockets/Selector.swift index e40eb9783..b85987eaf 100644 --- a/Sources/Sockets/Selector.swift +++ b/Sources/Sockets/Selector.swift @@ -22,7 +22,7 @@ import Foundation import Darwin #endif -public class Selector { +public final class Selector { #if os(Linux) private typealias EventType = epoll_event private let eventsCapacity = 2048