diff --git a/Sources/NIO/BlockingIOThreadPool.swift b/Sources/NIO/BlockingIOThreadPool.swift index 9a33d0abb7..94c1f8f54e 100644 --- a/Sources/NIO/BlockingIOThreadPool.swift +++ b/Sources/NIO/BlockingIOThreadPool.swift @@ -188,7 +188,7 @@ public extension BlockingIOThreadPool { /// - eventLoop: The `EventLoop` the returned `EventLoopFuture` will fire on. /// - body: The closure which performs some blocking work to be done on the thread pool. /// - returns: The `EventLoopFuture` of `promise` fulfilled with the result (or error) of the passed closure. - public func runIfActive(eventLoop: EventLoop, _ body: @escaping () throws -> T) -> EventLoopFuture { + func runIfActive(eventLoop: EventLoop, _ body: @escaping () throws -> T) -> EventLoopFuture { let promise: EventLoopPromise = eventLoop.newPromise() self.submit { shouldRun in guard case shouldRun = BlockingIOThreadPool.WorkItemState.active else { diff --git a/Sources/NIO/ByteBuffer-views.swift b/Sources/NIO/ByteBuffer-views.swift index c90002bf11..e395c03169 100644 --- a/Sources/NIO/ByteBuffer-views.swift +++ b/Sources/NIO/ByteBuffer-views.swift @@ -63,7 +63,7 @@ public struct ByteBufferView: ContiguousCollection, RandomAccessCollection { public extension ByteBuffer { /// A view into the readable bytes of the `ByteBuffer`. - public var readableBytesView: ByteBufferView { + var readableBytesView: ByteBufferView { return ByteBufferView(buffer: self, range: self.readerIndex ..< self.readerIndex + self.readableBytes) } @@ -73,7 +73,7 @@ public extension ByteBuffer { /// - index: The index the view should start at /// - length: The length of the view (in bytes) /// - returns A view into a portion of a `ByteBuffer`. - public func viewBytes(at index: Int, length: Int) -> ByteBufferView { + func viewBytes(at index: Int, length: Int) -> ByteBufferView { return ByteBufferView(buffer: self, range: index ..< index+length) } } diff --git a/Sources/NIO/Channel.swift b/Sources/NIO/Channel.swift index 48efd44310..b1a68a44ef 100644 --- a/Sources/NIO/Channel.swift +++ b/Sources/NIO/Channel.swift @@ -226,21 +226,21 @@ public extension Channel { /// Write data into the `Channel`, automatically wrapping with `NIOAny`. /// /// - seealso: `ChannelOutboundInvoker.write`. - public func write(_ any: T) -> EventLoopFuture { + func write(_ any: T) -> EventLoopFuture { return self.write(NIOAny(any)) } /// Write data into the `Channel`, automatically wrapping with `NIOAny`. /// /// - seealso: `ChannelOutboundInvoker.write`. - public func write(_ any: T, promise: EventLoopPromise?) { + func write(_ any: T, promise: EventLoopPromise?) { self.write(NIOAny(any), promise: promise) } /// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`. /// /// - seealso: `ChannelOutboundInvoker.writeAndFlush`. - public func writeAndFlush(_ any: T) -> EventLoopFuture { + func writeAndFlush(_ any: T) -> EventLoopFuture { return self.writeAndFlush(NIOAny(any)) } @@ -248,7 +248,7 @@ public extension Channel { /// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`. /// /// - seealso: `ChannelOutboundInvoker.writeAndFlush`. - public func writeAndFlush(_ any: T, promise: EventLoopPromise?) { + func writeAndFlush(_ any: T, promise: EventLoopPromise?) { self.writeAndFlush(NIOAny(any), promise: promise) } } @@ -270,7 +270,7 @@ public extension ChannelCore { /// - as: The type to extract from the `NIOAny`. /// - returns: The content of the `NIOAny`. @_inlineable - public func unwrapData(_ data: NIOAny, as: T.Type = T.self) -> T { + func unwrapData(_ data: NIOAny, as: T.Type = T.self) -> T { return data.forceAs() } @@ -283,7 +283,7 @@ public extension ChannelCore { /// /// - parameters: /// - channel: The `Channel` whose `ChannelPipeline` will be closed. - public func removeHandlers(channel: Channel) { + func removeHandlers(channel: Channel) { channel.pipeline.removeHandlers() } } diff --git a/Sources/NIO/EventLoopFuture.swift b/Sources/NIO/EventLoopFuture.swift index 46c837694a..acad176ad5 100644 --- a/Sources/NIO/EventLoopFuture.swift +++ b/Sources/NIO/EventLoopFuture.swift @@ -962,7 +962,7 @@ public extension EventLoopFuture { /// - parameters: /// - target: The `EventLoop` that the returned `EventLoopFuture` will run on. /// - returns: An `EventLoopFuture` whose callbacks run on `target` instead of the original loop. - public func hopTo(eventLoop target: EventLoop) -> EventLoopFuture { + func hopTo(eventLoop target: EventLoop) -> EventLoopFuture { if target === self.eventLoop { // We're already on that event loop, nothing to do here. Save an allocation. return self diff --git a/Sources/NIO/PendingDatagramWritesManager.swift b/Sources/NIO/PendingDatagramWritesManager.swift index b4af649836..0be39242e1 100644 --- a/Sources/NIO/PendingDatagramWritesManager.swift +++ b/Sources/NIO/PendingDatagramWritesManager.swift @@ -48,7 +48,7 @@ fileprivate extension Error { /// Returns whether the error is "recoverable" from the perspective of datagram sending. /// /// - returns: `true` if the error is recoverable, `false` otherwise. - fileprivate var isRecoverable: Bool { + var isRecoverable: Bool { switch self { case let e as IOError where e.errnoCode == EMSGSIZE, let e as IOError where e.errnoCode == EHOSTUNREACH: diff --git a/Sources/NIO/Selector.swift b/Sources/NIO/Selector.swift index 48b42db351..13e3c7ed5a 100644 --- a/Sources/NIO/Selector.swift +++ b/Sources/NIO/Selector.swift @@ -661,7 +661,7 @@ struct SelectorEvent { internal extension Selector where R == NIORegistration { /// Gently close the `Selector` after all registered `Channel`s are closed. - internal func closeGently(eventLoop: EventLoop) -> EventLoopFuture { + func closeGently(eventLoop: EventLoop) -> EventLoopFuture { guard self.lifecycleState == .open else { return eventLoop.newFailedFuture(error: IOError(errnoCode: EBADF, reason: "can't close selector gently as it's \(self.lifecycleState).")) } diff --git a/Sources/NIO/SocketOptionProvider.swift b/Sources/NIO/SocketOptionProvider.swift index a7a439c899..6fa2e1de44 100644 --- a/Sources/NIO/SocketOptionProvider.swift +++ b/Sources/NIO/SocketOptionProvider.swift @@ -88,7 +88,7 @@ public extension SocketOptionProvider { /// - value: The value to set SO_LINGER to. /// - returns: An `EventLoopFuture` that fires when the option has been set, /// or if an error has occurred. - public func setSoLinger(_ value: linger) -> EventLoopFuture { + func setSoLinger(_ value: linger) -> EventLoopFuture { return self.unsafeSetSocketOption(level: SocketOptionLevel(SOL_SOCKET), name: SO_LINGER, value: value) } @@ -96,7 +96,7 @@ public extension SocketOptionProvider { /// /// - returns: An `EventLoopFuture` containing the value of the socket option, or /// any error that occurred while retrieving the socket option. - public func getSoLinger() -> EventLoopFuture { + func getSoLinger() -> EventLoopFuture { return self.unsafeGetSocketOption(level: SocketOptionLevel(SOL_SOCKET), name: SO_LINGER) } @@ -106,7 +106,7 @@ public extension SocketOptionProvider { /// - value: The value to set IP_MULTICAST_IF to. /// - returns: An `EventLoopFuture` that fires when the option has been set, /// or if an error has occurred. - public func setIPMulticastIF(_ value: in_addr) -> EventLoopFuture { + func setIPMulticastIF(_ value: in_addr) -> EventLoopFuture { return self.unsafeSetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_IF, value: value) } @@ -114,7 +114,7 @@ public extension SocketOptionProvider { /// /// - returns: An `EventLoopFuture` containing the value of the socket option, or /// any error that occurred while retrieving the socket option. - public func getIPMulticastIF() -> EventLoopFuture { + func getIPMulticastIF() -> EventLoopFuture { return self.unsafeGetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_IF) } @@ -124,7 +124,7 @@ public extension SocketOptionProvider { /// - value: The value to set IP_MULTICAST_TTL to. /// - returns: An `EventLoopFuture` that fires when the option has been set, /// or if an error has occurred. - public func setIPMulticastTTL(_ value: CUnsignedChar) -> EventLoopFuture { + func setIPMulticastTTL(_ value: CUnsignedChar) -> EventLoopFuture { return self.unsafeSetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_TTL, value: value) } @@ -132,7 +132,7 @@ public extension SocketOptionProvider { /// /// - returns: An `EventLoopFuture` containing the value of the socket option, or /// any error that occurred while retrieving the socket option. - public func getIPMulticastTTL() -> EventLoopFuture { + func getIPMulticastTTL() -> EventLoopFuture { return self.unsafeGetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_TTL) } @@ -142,7 +142,7 @@ public extension SocketOptionProvider { /// - value: The value to set IP_MULTICAST_LOOP to. /// - returns: An `EventLoopFuture` that fires when the option has been set, /// or if an error has occurred. - public func setIPMulticastLoop(_ value: CUnsignedChar) -> EventLoopFuture { + func setIPMulticastLoop(_ value: CUnsignedChar) -> EventLoopFuture { return self.unsafeSetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_LOOP, value: value) } @@ -150,7 +150,7 @@ public extension SocketOptionProvider { /// /// - returns: An `EventLoopFuture` containing the value of the socket option, or /// any error that occurred while retrieving the socket option. - public func getIPMulticastLoop() -> EventLoopFuture { + func getIPMulticastLoop() -> EventLoopFuture { return self.unsafeGetSocketOption(level: IPPROTO_IP, name: IP_MULTICAST_LOOP) } @@ -160,7 +160,7 @@ public extension SocketOptionProvider { /// - value: The value to set IPV6_MULTICAST_IF to. /// - returns: An `EventLoopFuture` that fires when the option has been set, /// or if an error has occurred. - public func setIPv6MulticastIF(_ value: CUnsignedInt) -> EventLoopFuture { + func setIPv6MulticastIF(_ value: CUnsignedInt) -> EventLoopFuture { return self.unsafeSetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_IF, value: value) } @@ -168,7 +168,7 @@ public extension SocketOptionProvider { /// /// - returns: An `EventLoopFuture` containing the value of the socket option, or /// any error that occurred while retrieving the socket option. - public func getIPv6MulticastIF() -> EventLoopFuture { + func getIPv6MulticastIF() -> EventLoopFuture { return self.unsafeGetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_IF) } @@ -178,7 +178,7 @@ public extension SocketOptionProvider { /// - value: The value to set IPV6_MULTICAST_HOPS to. /// - returns: An `EventLoopFuture` that fires when the option has been set, /// or if an error has occurred. - public func setIPv6MulticastHops(_ value: CInt) -> EventLoopFuture { + func setIPv6MulticastHops(_ value: CInt) -> EventLoopFuture { return self.unsafeSetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_HOPS, value: value) } @@ -186,7 +186,7 @@ public extension SocketOptionProvider { /// /// - returns: An `EventLoopFuture` containing the value of the socket option, or /// any error that occurred while retrieving the socket option. - public func getIPv6MulticastHops() -> EventLoopFuture { + func getIPv6MulticastHops() -> EventLoopFuture { return self.unsafeGetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_HOPS) } @@ -196,7 +196,7 @@ public extension SocketOptionProvider { /// - value: The value to set IPV6_MULTICAST_LOOP to. /// - returns: An `EventLoopFuture` that fires when the option has been set, /// or if an error has occurred. - public func setIPv6MulticastLoop(_ value: CUnsignedInt) -> EventLoopFuture { + func setIPv6MulticastLoop(_ value: CUnsignedInt) -> EventLoopFuture { return self.unsafeSetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_LOOP, value: value) } @@ -204,7 +204,7 @@ public extension SocketOptionProvider { /// /// - returns: An `EventLoopFuture` containing the value of the socket option, or /// any error that occurred while retrieving the socket option. - public func getIPv6MulticastLoop() -> EventLoopFuture { + func getIPv6MulticastLoop() -> EventLoopFuture { return self.unsafeGetSocketOption(level: IPPROTO_IPV6, name: IPV6_MULTICAST_LOOP) } } diff --git a/Sources/NIOHTTP1/HTTPPipelineSetup.swift b/Sources/NIOHTTP1/HTTPPipelineSetup.swift index 78b64911fb..5e0d1903f0 100644 --- a/Sources/NIOHTTP1/HTTPPipelineSetup.swift +++ b/Sources/NIOHTTP1/HTTPPipelineSetup.swift @@ -28,7 +28,7 @@ public extension ChannelPipeline { /// or at the tail. /// - returns: An `EventLoopFuture` that will fire when the pipeline is configured. @available(*, deprecated, message: "Please use configureHTTPServerPipeline") - public func addHTTPServerHandlers(first: Bool = false) -> EventLoopFuture { + func addHTTPServerHandlers(first: Bool = false) -> EventLoopFuture { return addHandlers(HTTPResponseEncoder(), HTTPRequestDecoder(), first: first) } @@ -38,7 +38,7 @@ public extension ChannelPipeline { /// - first: Whether to add the HTTP client at the head of the channel pipeline, /// or at the tail. /// - returns: An `EventLoopFuture` that will fire when the pipeline is configured. - public func addHTTPClientHandlers(first: Bool = false) -> EventLoopFuture { + func addHTTPClientHandlers(first: Bool = false) -> EventLoopFuture { return addHandlers(HTTPRequestEncoder(), HTTPResponseDecoder(), first: first) } @@ -54,9 +54,9 @@ public extension ChannelPipeline { /// complete. /// - returns: An `EventLoopFuture` that will fire when the pipeline is configured. @available(*, deprecated, message: "Please use configureHTTPServerPipeline") - public func addHTTPServerHandlersWithUpgrader(first: Bool = false, - upgraders: [HTTPProtocolUpgrader], - _ upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void) -> EventLoopFuture { + func addHTTPServerHandlersWithUpgrader(first: Bool = false, + upgraders: [HTTPProtocolUpgrader], + _ upgradeCompletionHandler: @escaping (ChannelHandlerContext) -> Void) -> EventLoopFuture { let responseEncoder = HTTPResponseEncoder() let requestDecoder = HTTPRequestDecoder(leftOverBytesStrategy: .forwardBytes) let upgrader = HTTPServerUpgradeHandler(upgraders: upgraders, @@ -93,10 +93,10 @@ public extension ChannelPipeline { /// failure to parse the HTTP request) by sending 400 errors. Defaults to `false` for /// backward-compatibility reasons. /// - returns: An `EventLoopFuture` that will fire when the pipeline is configured. - public func configureHTTPServerPipeline(first: Bool = false, - withPipeliningAssistance pipelining: Bool = true, - withServerUpgrade upgrade: HTTPUpgradeConfiguration? = nil, - withErrorHandling errorHandling: Bool = false) -> EventLoopFuture { + func configureHTTPServerPipeline(first: Bool = false, + withPipeliningAssistance pipelining: Bool = true, + withServerUpgrade upgrade: HTTPUpgradeConfiguration? = nil, + withErrorHandling errorHandling: Bool = false) -> EventLoopFuture { let responseEncoder = HTTPResponseEncoder() let requestDecoder = HTTPRequestDecoder(leftOverBytesStrategy: upgrade == nil ? .dropBytes : .forwardBytes) diff --git a/Sources/NIOHTTP1/HTTPTypes.swift b/Sources/NIOHTTP1/HTTPTypes.swift index b8ea2407e4..95550b7a34 100644 --- a/Sources/NIOHTTP1/HTTPTypes.swift +++ b/Sources/NIOHTTP1/HTTPTypes.swift @@ -786,7 +786,7 @@ public protocol _DeprecateHTTPHeaderIterator: Sequence { } extension HTTPHeaders: _DeprecateHTTPHeaderIterator { } public extension _DeprecateHTTPHeaderIterator { @available(*, deprecated, message: "Please use the HTTPHeaders.Iterator type") - public func makeIterator() -> AnyIterator { + func makeIterator() -> AnyIterator { return AnyIterator(makeIterator() as Iterator) } } diff --git a/Sources/NIOPriorityQueue/PriorityQueue.swift b/Sources/NIOPriorityQueue/PriorityQueue.swift index 3333d4a73d..4ce0051f76 100644 --- a/Sources/NIOPriorityQueue/PriorityQueue.swift +++ b/Sources/NIOPriorityQueue/PriorityQueue.swift @@ -87,7 +87,7 @@ extension PriorityQueue: Sequence { @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") public extension PriorityQueue { @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") - public var count: Int { + var count: Int { return self.heap.count } } diff --git a/Sources/NIOWebSocket/WebSocketErrorCodes.swift b/Sources/NIOWebSocket/WebSocketErrorCodes.swift index 8461eb13af..576a279864 100644 --- a/Sources/NIOWebSocket/WebSocketErrorCodes.swift +++ b/Sources/NIOWebSocket/WebSocketErrorCodes.swift @@ -150,7 +150,7 @@ public extension ByteBuffer { /// This method increments the reader index. /// /// - returns: The error code, or `nil` if there were not enough readable bytes. - public mutating func readWebSocketErrorCode() -> WebSocketErrorCode? { + mutating func readWebSocketErrorCode() -> WebSocketErrorCode? { return self.readInteger(as: UInt16.self).map { WebSocketErrorCode(networkInteger: $0) } } @@ -162,7 +162,7 @@ public extension ByteBuffer { /// - parameters: /// - index: The index into the buffer to read the error code from. /// - returns: The error code, or `nil` if there were not enough bytes at that index. - public func getWebSocketErrorCode(at index: Int) -> WebSocketErrorCode? { + func getWebSocketErrorCode(at index: Int) -> WebSocketErrorCode? { return self.getInteger(at: index, as: UInt16.self).map { WebSocketErrorCode(networkInteger: $0) } } @@ -170,7 +170,7 @@ public extension ByteBuffer { /// /// - parameters: /// - code: The code to write into the buffer. - public mutating func write(webSocketErrorCode code: WebSocketErrorCode) { + mutating func write(webSocketErrorCode code: WebSocketErrorCode) { self.write(integer: UInt16(webSocketErrorCode: code)) } } @@ -180,7 +180,7 @@ public extension UInt16 { /// /// - parameters: /// - code: The `WebSocketErrorCode`. - public init(webSocketErrorCode code: WebSocketErrorCode) { + init(webSocketErrorCode code: WebSocketErrorCode) { switch code { case .normalClosure: self = 1000 diff --git a/Sources/NIOWebSocket/WebSocketFrameDecoder.swift b/Sources/NIOWebSocket/WebSocketFrameDecoder.swift index a055d38d20..8b9e160631 100644 --- a/Sources/NIOWebSocket/WebSocketFrameDecoder.swift +++ b/Sources/NIOWebSocket/WebSocketFrameDecoder.swift @@ -28,7 +28,7 @@ public enum NIOWebSocketError: Error { } internal extension WebSocketErrorCode { - internal init(_ error: NIOWebSocketError) { + init(_ error: NIOWebSocketError) { switch error { case .invalidFrameLength: self = .messageTooLarge @@ -44,7 +44,7 @@ public extension ByteBuffer { /// /// - parameters: /// - maskingKey: The masking key. - public mutating func webSocketUnmask(_ maskingKey: WebSocketMaskingKey, indexOffset: Int = 0) { + mutating func webSocketUnmask(_ maskingKey: WebSocketMaskingKey, indexOffset: Int = 0) { /// Shhhh: secretly unmasking and masking are the same operation! webSocketMask(maskingKey, indexOffset: indexOffset) } @@ -57,7 +57,7 @@ public extension ByteBuffer { /// This is used when masking multiple "contiguous" byte buffers, to ensure that /// the masking key is applied uniformly to the collection rather than from the /// start each time. - public mutating func webSocketMask(_ maskingKey: WebSocketMaskingKey, indexOffset: Int = 0) { + mutating func webSocketMask(_ maskingKey: WebSocketMaskingKey, indexOffset: Int = 0) { self.withUnsafeMutableReadableBytes { for (index, byte) in $0.enumerated() { $0[index] = byte ^ maskingKey[(index + indexOffset) % 4] diff --git a/Sources/NIOWebSocket/WebSocketOpcode.swift b/Sources/NIOWebSocket/WebSocketOpcode.swift index 2f32e6171e..e288e7aae3 100644 --- a/Sources/NIOWebSocket/WebSocketOpcode.swift +++ b/Sources/NIOWebSocket/WebSocketOpcode.swift @@ -96,7 +96,7 @@ public extension UInt8 { /// /// - parameters: /// - opcode: The `WebSocketOpcode`. - public init?(webSocketOpcode opcode: WebSocketOpcode) { + init?(webSocketOpcode opcode: WebSocketOpcode) { switch opcode { case .continuation: self = 0x0 diff --git a/Sources/NIOWebSocket/WebSocketUpgrader.swift b/Sources/NIOWebSocket/WebSocketUpgrader.swift index dd5decc0da..35aec8cf92 100644 --- a/Sources/NIOWebSocket/WebSocketUpgrader.swift +++ b/Sources/NIOWebSocket/WebSocketUpgrader.swift @@ -29,7 +29,7 @@ public enum NIOWebSocketUpgradeError: Error { } fileprivate extension HTTPHeaders { - fileprivate func nonListHeader(_ name: String) throws -> String { + func nonListHeader(_ name: String) throws -> String { let fields = self[canonicalForm: name] guard fields.count == 1 else { throw NIOWebSocketUpgradeError.invalidUpgradeHeader diff --git a/Tests/NIOTests/FileRegionTest.swift b/Tests/NIOTests/FileRegionTest.swift index ff78f9382c..73a37e6a18 100644 --- a/Tests/NIOTests/FileRegionTest.swift +++ b/Tests/NIOTests/FileRegionTest.swift @@ -216,13 +216,13 @@ class FileRegionTest : XCTestCase { let r = try Posix.read(descriptor: fd, pointer: &fr2Bytes, size: 5) XCTAssertEqual(r, IOResult.processed(5)) } - XCTAssertEqual(Array("01234".utf8), fr1Bytes) - XCTAssertEqual(Array("56789".utf8), fr2Bytes) - defer { // fr2's underlying fd must be closed by us. XCTAssertNoThrow(try fh2.close()) } + + XCTAssertEqual(Array("01234".utf8), fr1Bytes) + XCTAssertEqual(Array("56789".utf8), fr2Bytes) } }