From eaa8ffaee4f339fdd9ec55d8828fc27d260bb773 Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Tue, 13 Feb 2018 11:13:30 +0000 Subject: [PATCH] remove redundant labels Motivation: Lots of our most important operations had redundant labels like func write(data: NIOAny) the `data: ` label doesn't add anything meaningful and therefore it should be removed. Modifications: removed lots of redundant labels Result: less redundant labels --- Sources/NIO/Bootstrap.swift | 10 +- Sources/NIO/Channel.swift | 26 ++-- Sources/NIO/ChannelHandler.swift | 10 +- Sources/NIO/ChannelHandlers.swift | 12 +- Sources/NIO/ChannelInvoker.swift | 30 ++--- Sources/NIO/ChannelPipeline.swift | 126 +++++++++--------- Sources/NIO/Codec.swift | 4 +- Sources/NIO/DeadChannel.swift | 6 +- Sources/NIO/Embedded.swift | 14 +- Sources/NIO/NIOAny.swift | 2 +- Sources/NIO/SocketChannel.swift | 16 +-- Sources/NIOEchoClient/main.swift | 2 +- Sources/NIOEchoServer/main.swift | 2 +- Sources/NIOHTTP1/HTTPDecoder.swift | 16 +-- Sources/NIOHTTP1/HTTPEncoder.swift | 14 +- Sources/NIOHTTP1/HTTPResponseCompressor.swift | 14 +- Sources/NIOHTTP1/HTTPUpgradeHandler.swift | 12 +- Sources/NIOHTTP1Server/main.swift | 74 +++++----- ...pplicationProtocolNegotiationHandler.swift | 8 +- .../HTTPRequestEncoderTest.swift | 10 +- .../HTTPResponseCompressorTest.swift | 26 ++-- .../HTTPResponseEncoderTest.swift | 4 +- .../NIOHTTP1Tests/HTTPServerClientTest.swift | 54 ++++---- Tests/NIOHTTP1Tests/HTTPTest.swift | 6 +- Tests/NIOHTTP1Tests/HTTPUpgradeTests.swift | 24 ++-- ...ationProtocolNegotiationHandlerTests.swift | 22 +-- Tests/NIOTLSTests/SNIHandlerTests.swift | 6 +- Tests/NIOTests/ChannelPipelineTest.swift | 22 +-- Tests/NIOTests/ChannelTests.swift | 18 +-- Tests/NIOTests/CodecTest.swift | 12 +- Tests/NIOTests/EchoServerClientTest.swift | 40 +++--- Tests/NIOTests/EmbeddedChannelTest.swift | 10 +- Tests/NIOTests/EventLoopTest.swift | 2 +- Tests/NIOTests/FileRegionTest.swift | 12 +- Tests/NIOTests/IdleStateHandlerTest.swift | 4 +- 35 files changed, 335 insertions(+), 335 deletions(-) diff --git a/Sources/NIO/Bootstrap.swift b/Sources/NIO/Bootstrap.swift index 02c971d49..7e13e3fc7 100644 --- a/Sources/NIO/Bootstrap.swift +++ b/Sources/NIO/Bootstrap.swift @@ -206,16 +206,16 @@ public final class ServerBootstrap { self.closeAndFire(ctx: ctx, accepted: accepted, err: err) case .success(_): if ctx.eventLoop.inEventLoop { - ctx.fireChannelRead(data: data) + ctx.fireChannelRead(data) } else { ctx.eventLoop.execute { - ctx.fireChannelRead(data: data) + ctx.fireChannelRead(data) } } } } } else { - ctx.fireChannelRead(data: data) + ctx.fireChannelRead(data) } } } @@ -225,10 +225,10 @@ public final class ServerBootstrap { private func closeAndFire(ctx: ChannelHandlerContext, accepted: SocketChannel, err: Error) { _ = accepted.close() if ctx.eventLoop.inEventLoop { - ctx.fireErrorCaught(error: err) + ctx.fireErrorCaught(err) } else { ctx.eventLoop.execute { - ctx.fireErrorCaught(error: err) + ctx.fireErrorCaught(err) } } } diff --git a/Sources/NIO/Channel.swift b/Sources/NIO/Channel.swift index 49370aef0..6ac6de36e 100644 --- a/Sources/NIO/Channel.swift +++ b/Sources/NIO/Channel.swift @@ -21,12 +21,12 @@ public protocol ChannelCore : class { func register0(promise: EventLoopPromise?) func bind0(to: SocketAddress, promise: EventLoopPromise?) func connect0(to: SocketAddress, promise: EventLoopPromise?) - func write0(data: NIOAny, promise: EventLoopPromise?) + func write0(_ data: NIOAny, promise: EventLoopPromise?) func flush0(promise: EventLoopPromise?) func read0(promise: EventLoopPromise?) func close0(error: Error, mode: CloseMode, promise: EventLoopPromise?) - func triggerUserOutboundEvent0(event: Any, promise: EventLoopPromise?) - func channelRead0(data: NIOAny) + func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise?) + func channelRead0(_ data: NIOAny) func errorCaught0(error: Error) } @@ -123,16 +123,16 @@ extension Channel { pipeline.connect(to: address, promise: promise) } - public func write(data: NIOAny, promise: EventLoopPromise?) { - pipeline.write(data: data, promise: promise) + public func write(_ data: NIOAny, promise: EventLoopPromise?) { + pipeline.write(data, promise: promise) } public func flush(promise: EventLoopPromise?) { pipeline.flush(promise: promise) } - public func writeAndFlush(data: NIOAny, promise: EventLoopPromise?) { - pipeline.writeAndFlush(data: data, promise: promise) + public func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise?) { + pipeline.writeAndFlush(data, promise: promise) } public func read(promise: EventLoopPromise?) { @@ -147,8 +147,8 @@ extension Channel { pipeline.register(promise: promise) } - public func triggerUserOutboundEvent(event: Any, promise: EventLoopPromise?) { - pipeline.triggerUserOutboundEvent(event: event, promise: promise) + public func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise?) { + pipeline.triggerUserOutboundEvent(event, promise: promise) } } @@ -160,21 +160,21 @@ public extension Channel { /// /// - seealso: `ChannelOutboundInvoker.write`. public func write(_ any: T) -> EventLoopFuture { - return self.write(data: NIOAny(any)) + return self.write(NIOAny(any)) } /// Write data into the `Channel`, automatically wrapping with `NIOAny`. /// /// - seealso: `ChannelOutboundInvoker.write`. public func write(_ any: T, promise: EventLoopPromise?) { - self.write(data: NIOAny(any), promise: promise) + 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 { - return self.writeAndFlush(data: NIOAny(any)) + return self.writeAndFlush(NIOAny(any)) } @@ -182,7 +182,7 @@ public extension Channel { /// /// - seealso: `ChannelOutboundInvoker.writeAndFlush`. public func writeAndFlush(_ any: T, promise: EventLoopPromise?) { - self.writeAndFlush(data: NIOAny(any), promise: promise) + self.writeAndFlush(NIOAny(any), promise: promise) } } diff --git a/Sources/NIO/ChannelHandler.swift b/Sources/NIO/ChannelHandler.swift index ed40e3929..8e4bbc850 100644 --- a/Sources/NIO/ChannelHandler.swift +++ b/Sources/NIO/ChannelHandler.swift @@ -68,7 +68,7 @@ extension _ChannelOutboundHandler { } public func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise?) { - ctx.write(data: data, promise: promise) + ctx.write(data, promise: promise) } public func flush(ctx: ChannelHandlerContext, promise: EventLoopPromise?) { @@ -84,7 +84,7 @@ extension _ChannelOutboundHandler { } public func triggerUserOutboundEvent(ctx: ChannelHandlerContext, event: Any, promise: EventLoopPromise?) { - ctx.triggerUserOutboundEvent(event: event, promise: promise) + ctx.triggerUserOutboundEvent(event, promise: promise) } } @@ -108,7 +108,7 @@ extension _ChannelInboundHandler { } public func channelRead(ctx: ChannelHandlerContext, data: NIOAny) { - ctx.fireChannelRead(data: data) + ctx.fireChannelRead(data) } public func channelReadComplete(ctx: ChannelHandlerContext) { @@ -120,11 +120,11 @@ extension _ChannelInboundHandler { } public func userInboundEventTriggered(ctx: ChannelHandlerContext, event: Any) { - ctx.fireUserInboundEventTriggered(event: event) + ctx.fireUserInboundEventTriggered(event) } public func errorCaught(ctx: ChannelHandlerContext, error: Error) { - ctx.fireErrorCaught(error: error) + ctx.fireErrorCaught(error) } } diff --git a/Sources/NIO/ChannelHandlers.swift b/Sources/NIO/ChannelHandlers.swift index 217202f69..ae011bfb1 100644 --- a/Sources/NIO/ChannelHandlers.swift +++ b/Sources/NIO/ChannelHandlers.swift @@ -130,7 +130,7 @@ public class IdleStateHandler : ChannelInboundHandler, ChannelOutboundHandler { if readTimeout != nil || allTimeout != nil { reading = true } - ctx.fireChannelRead(data: data) + ctx.fireChannelRead(data) } public func channelReadComplete(ctx: ChannelHandlerContext) { @@ -143,7 +143,7 @@ public class IdleStateHandler : ChannelInboundHandler, ChannelOutboundHandler { public func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise?) { if writeTimeout == nil && allTimeout == nil { - ctx.write(data: data, promise: promise) + ctx.write(data, promise: promise) return } @@ -151,7 +151,7 @@ public class IdleStateHandler : ChannelInboundHandler, ChannelOutboundHandler { writePromise.futureResult.whenComplete { _ in self.lastWriteCompleteTime = DispatchTime.now() } - ctx.write(data: data, promise: writePromise) + ctx.write(data, promise: writePromise) } private func shouldReschedule(_ ctx: ChannelHandlerContext) -> Bool { @@ -177,7 +177,7 @@ public class IdleStateHandler : ChannelInboundHandler, ChannelOutboundHandler { // Reader is idle - set a new timeout and trigger an event through the pipeline self.scheduledReaderTask = ctx.eventLoop.scheduleTask(in: timeout, self.newReadTimeoutTask(ctx, timeout)) - ctx.fireUserInboundEventTriggered(event: IdleStateEvent.read) + ctx.fireUserInboundEventTriggered(IdleStateEvent.read) } else { // Read occurred before the timeout - set a new timeout with shorter delay. self.scheduledReaderTask = ctx.eventLoop.scheduleTask(in: .nanoseconds(timeout.nanoseconds - diff), self.newReadTimeoutTask(ctx, timeout)) @@ -198,7 +198,7 @@ public class IdleStateHandler : ChannelInboundHandler, ChannelOutboundHandler { // Writer is idle - set a new timeout and notify the callback. self.scheduledWriterTask = ctx.eventLoop.scheduleTask(in: timeout, self.newWriteTimeoutTask(ctx, timeout)) - ctx.fireUserInboundEventTriggered(event: IdleStateEvent.write) + ctx.fireUserInboundEventTriggered(IdleStateEvent.write) } else { // Write occurred before the timeout - set a new timeout with shorter delay. self.scheduledWriterTask = ctx.eventLoop.scheduleTask(in: .nanoseconds(Int(timeout.nanoseconds) - Int(diff)), self.newWriteTimeoutTask(ctx, timeout)) @@ -224,7 +224,7 @@ public class IdleStateHandler : ChannelInboundHandler, ChannelOutboundHandler { // Reader is idle - set a new timeout and trigger an event through the pipeline self.scheduledReaderTask = ctx.eventLoop.scheduleTask(in: timeout, self.newAllTimeoutTask(ctx, timeout)) - ctx.fireUserInboundEventTriggered(event: IdleStateEvent.all) + ctx.fireUserInboundEventTriggered(IdleStateEvent.all) } else { // Read occurred before the timeout - set a new timeout with shorter delay. self.scheduledReaderTask = ctx.eventLoop.scheduleTask(in: .nanoseconds(Int(timeout.nanoseconds) - diff), self.newAllTimeoutTask(ctx, timeout)) diff --git a/Sources/NIO/ChannelInvoker.swift b/Sources/NIO/ChannelInvoker.swift index f13fc0603..fa27fc047 100644 --- a/Sources/NIO/ChannelInvoker.swift +++ b/Sources/NIO/ChannelInvoker.swift @@ -61,7 +61,7 @@ public protocol ChannelOutboundInvoker { /// - parameters: /// - data: the data to write /// - returns: the future which will be notified once the operation completes. - func write(data: NIOAny) -> EventLoopFuture + func write(_ data: NIOAny) -> EventLoopFuture /// Write data to the remote peer. /// @@ -72,7 +72,7 @@ public protocol ChannelOutboundInvoker { /// - data: the data to write /// - promise: the `EventLoopPromise` that will be notified once the operation completes, /// or `nil` if not interested in the outcome of the operation. - func write(data: NIOAny, promise: EventLoopPromise?) + func write(_ data: NIOAny, promise: EventLoopPromise?) /// Flush data that was previously written via `write` to the remote peer. /// @@ -91,7 +91,7 @@ public protocol ChannelOutboundInvoker { /// - parameters: /// - data: the data to write /// - returns: the future which will be notified once the operation completes. - func writeAndFlush(data: NIOAny) -> EventLoopFuture + func writeAndFlush(_ data: NIOAny) -> EventLoopFuture /// Shortcut for calling `write` and `flush`. /// @@ -99,7 +99,7 @@ public protocol ChannelOutboundInvoker { /// - data: the data to write /// - promise: the `EventLoopPromise` that will be notified once the operation completes, /// or `nil` if not interested in the outcome of the operation. - func writeAndFlush(data: NIOAny, promise: EventLoopPromise?) + func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise?) /// Signal that we want to read from the `Channel` once there is data ready. /// @@ -139,14 +139,14 @@ public protocol ChannelOutboundInvoker { /// - parameters: /// - event: the event itself. /// - returns: the future which will be notified once the operation completes. - func triggerUserOutboundEvent(event: Any) -> EventLoopFuture + func triggerUserOutboundEvent(_ event: Any) -> EventLoopFuture /// Trigger a custom user outbound event which will flow through the `ChannelPipeline`. /// /// - parameters: /// - promise: the `EventLoopPromise` that will be notified once the operation completes, /// or `nil` if not interested in the outcome of the operation. - func triggerUserOutboundEvent(event: Any, promise: EventLoopPromise?) + func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise?) /// The `EventLoop` which is used by this `ChannelOutboundInvoker` for execution. var eventLoop: EventLoop { get } @@ -171,9 +171,9 @@ extension ChannelOutboundInvoker { return promise.futureResult } - public func write(data: NIOAny) -> EventLoopFuture { + public func write(_ data: NIOAny) -> EventLoopFuture { let promise = newPromise() - write(data: data, promise: promise) + write(data, promise: promise) return promise.futureResult } @@ -189,9 +189,9 @@ extension ChannelOutboundInvoker { return promise.futureResult } - public func writeAndFlush(data: NIOAny) -> EventLoopFuture { + public func writeAndFlush(_ data: NIOAny) -> EventLoopFuture { let promise = newPromise() - writeAndFlush(data: data, promise: promise) + writeAndFlush(data, promise: promise) return promise.futureResult } @@ -201,9 +201,9 @@ extension ChannelOutboundInvoker { return promise.futureResult } - public func triggerUserOutboundEvent(event: Any) -> EventLoopFuture { + public func triggerUserOutboundEvent(_ event: Any) -> EventLoopFuture { let promise = newPromise() - triggerUserOutboundEvent(event: event, promise: promise) + triggerUserOutboundEvent(event, promise: promise) return promise.futureResult } @@ -237,7 +237,7 @@ public protocol ChannelInboundInvoker { /// /// - parameters: /// - data: the data that was read and is ready to be processed. - func fireChannelRead(data: NIOAny) + func fireChannelRead(_ data: NIOAny) /// Called once there is no more data to read immediately on a `Channel`. Any new data received will be handled later. func fireChannelReadComplete() @@ -259,13 +259,13 @@ public protocol ChannelInboundInvoker { /// /// - parameters: /// - error: the error we encountered. - func fireErrorCaught(error: Error) + func fireErrorCaught(_ error: Error) /// Trigger a custom user inbound event which will flow through the `ChannelPipeline`. /// /// - parameters: /// - event: the event itself. - func fireUserInboundEventTriggered(event: Any) + func fireUserInboundEventTriggered(_ event: Any) } /// A protocol that signals that outbound and inbound events are triggered by this invoker. diff --git a/Sources/NIO/ChannelPipeline.swift b/Sources/NIO/ChannelPipeline.swift index 0a2294122..36e1dd22b 100644 --- a/Sources/NIO/ChannelPipeline.swift +++ b/Sources/NIO/ChannelPipeline.swift @@ -386,12 +386,12 @@ public final class ChannelPipeline : ChannelInvoker { } } - public func fireChannelRead(data: NIOAny) { + public func fireChannelRead(_ data: NIOAny) { if eventLoop.inEventLoop { - fireChannelRead0(data: data) + fireChannelRead0(data) } else { eventLoop.execute { - self.fireChannelRead0(data: data) + self.fireChannelRead0(data) } } } @@ -416,17 +416,17 @@ public final class ChannelPipeline : ChannelInvoker { } } - public func fireUserInboundEventTriggered(event: Any) { + public func fireUserInboundEventTriggered(_ event: Any) { if eventLoop.inEventLoop { - fireUserInboundEventTriggered0(event: event) + fireUserInboundEventTriggered0(event) } else { eventLoop.execute { - self.fireUserInboundEventTriggered0(event: event) + self.fireUserInboundEventTriggered0(event) } } } - public func fireErrorCaught(error: Error) { + public func fireErrorCaught(_ error: Error) { if eventLoop.inEventLoop { fireErrorCaught0(error: error) } else { @@ -466,22 +466,22 @@ public final class ChannelPipeline : ChannelInvoker { } } - public func write(data: NIOAny, promise: EventLoopPromise?) { + public func write(_ data: NIOAny, promise: EventLoopPromise?) { if eventLoop.inEventLoop { - write0(data: data, promise: promise) + write0(data, promise: promise) } else { eventLoop.execute { - self.write0(data: data, promise: promise) + self.write0(data, promise: promise) } } } - public func writeAndFlush(data: NIOAny, promise: EventLoopPromise?) { + public func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise?) { if eventLoop.inEventLoop { - writeAndFlush0(data: data, promise: promise) + writeAndFlush0(data, promise: promise) } else { eventLoop.execute { - self.writeAndFlush0(data: data, promise: promise) + self.writeAndFlush0(data, promise: promise) } } } @@ -516,12 +516,12 @@ public final class ChannelPipeline : ChannelInvoker { } } - public func triggerUserOutboundEvent(event: Any, promise: EventLoopPromise?) { + public func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise?) { if eventLoop.inEventLoop { - triggerUserOutboundEvent0(event: event, promise: promise) + triggerUserOutboundEvent0(event, promise: promise) } else { eventLoop.execute { - self.triggerUserOutboundEvent0(event: event, promise: promise) + self.triggerUserOutboundEvent0(event, promise: promise) } } } @@ -560,17 +560,17 @@ public final class ChannelPipeline : ChannelInvoker { } } - func write0(data: NIOAny, promise: EventLoopPromise?) { + func write0(_ data: NIOAny, promise: EventLoopPromise?) { if let firstOutboundCtx = firstOutboundCtx { - firstOutboundCtx.invokeWrite(data: data, promise: promise) + firstOutboundCtx.invokeWrite(data, promise: promise) } else { promise?.fail(error: ChannelError.ioOnClosedChannel) } } - func writeAndFlush0(data: NIOAny, promise: EventLoopPromise?) { + func writeAndFlush0(_ data: NIOAny, promise: EventLoopPromise?) { if let firstOutboundCtx = firstOutboundCtx { - firstOutboundCtx.invokeWriteAndFlush(data: data, promise: promise) + firstOutboundCtx.invokeWriteAndFlush(data, promise: promise) } else { promise?.fail(error: ChannelError.ioOnClosedChannel) } @@ -600,9 +600,9 @@ public final class ChannelPipeline : ChannelInvoker { } } - func triggerUserOutboundEvent0(event: Any, promise: EventLoopPromise?) { + func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise?) { if let firstOutboundCtx = firstOutboundCtx { - firstOutboundCtx.invokeTriggerUserOutboundEvent(event: event, promise: promise) + firstOutboundCtx.invokeTriggerUserOutboundEvent(event, promise: promise) } else { promise?.fail(error: ChannelError.ioOnClosedChannel) } @@ -632,9 +632,9 @@ public final class ChannelPipeline : ChannelInvoker { } } - func fireChannelRead0(data: NIOAny) { + func fireChannelRead0(_ data: NIOAny) { if let firstInboundCtx = firstInboundCtx { - firstInboundCtx.invokeChannelRead(data: data) + firstInboundCtx.invokeChannelRead(data) } } @@ -650,15 +650,15 @@ public final class ChannelPipeline : ChannelInvoker { } } - func fireUserInboundEventTriggered0(event: Any) { + func fireUserInboundEventTriggered0(_ event: Any) { if let firstInboundCtx = firstInboundCtx { - firstInboundCtx.invokeUserInboundEventTriggered(event: event) + firstInboundCtx.invokeUserInboundEventTriggered(event) } } func fireErrorCaught0(error: Error) { if let firstInboundCtx = firstInboundCtx { - firstInboundCtx.invokeErrorCaught(error: error) + firstInboundCtx.invokeErrorCaught(error) } } @@ -700,7 +700,7 @@ private final class HeadChannelHandler : _ChannelOutboundHandler { } func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise?) { - ctx.channel._unsafe.write0(data: data, promise: promise) + ctx.channel._unsafe.write0(data, promise: promise) } func flush(ctx: ChannelHandlerContext, promise: EventLoopPromise?) { @@ -716,7 +716,7 @@ private final class HeadChannelHandler : _ChannelOutboundHandler { } func triggerUserOutboundEvent(ctx: ChannelHandlerContext, event: Any, promise: EventLoopPromise?) { - ctx.channel._unsafe.triggerUserOutboundEvent0(event: event, promise: promise) + ctx.channel._unsafe.triggerUserOutboundEvent0(event, promise: promise) } } @@ -774,7 +774,7 @@ private final class TailChannelHandler : _ChannelInboundHandler, _ChannelOutboun } func channelRead(ctx: ChannelHandlerContext, data: NIOAny) { - ctx.channel._unsafe.channelRead0(data: data) + ctx.channel._unsafe.channelRead0(data) } } @@ -863,8 +863,8 @@ public final class ChannelHandlerContext : ChannelInvoker { } /// Send data to the next inbound `ChannelHandler`. The data should be of type `ChannelInboundHandler.InboundOut`. - public func fireChannelRead(data: NIOAny) { - self.next?.invokeChannelRead(data: data) + public func fireChannelRead(_ data: NIOAny) { + self.next?.invokeChannelRead(data) } /// Signal to the next `ChannelHandler` that a read burst has finished. @@ -880,13 +880,13 @@ public final class ChannelHandlerContext : ChannelInvoker { } /// Send an error to the next inbound `ChannelHandler`. - public func fireErrorCaught(error: Error) { - self.next?.invokeErrorCaught(error: error) + public func fireErrorCaught(_ error: Error) { + self.next?.invokeErrorCaught(error) } /// Send a user event to the next inbound `ChannelHandler`. - public func fireUserInboundEventTriggered(event: Any) { - self.next?.invokeUserInboundEventTriggered(event: event) + public func fireUserInboundEventTriggered(_ event: Any) { + self.next?.invokeUserInboundEventTriggered(event) } /// Send a `register` event to the next (outbound) `ChannelHandler` in the `ChannelPipeline`. @@ -935,9 +935,9 @@ public final class ChannelHandlerContext : ChannelInvoker { /// - parameters: /// - data: The data to write, should be of type `ChannelOutboundHandler.OutboundOut`. /// - promise: The promise fulfilled when the data has been written or failed if it cannot be written. - public func write(data: NIOAny, promise: EventLoopPromise?) { + public func write(_ data: NIOAny, promise: EventLoopPromise?) { if let outboundNext = self.prev { - outboundNext.invokeWrite(data: data, promise: promise) + outboundNext.invokeWrite(data, promise: promise) } else { promise?.fail(error: ChannelError.ioOnClosedChannel) } @@ -964,9 +964,9 @@ public final class ChannelHandlerContext : ChannelInvoker { /// - parameters: /// - data: The data to write, should be of type `ChannelOutboundHandler.OutboundOut`. /// - promise: The promise fulfilled when the previously written data been written and flushed or if that failed. - public func writeAndFlush(data: NIOAny, promise: EventLoopPromise?) { + public func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise?) { if let outboundNext = self.prev { - outboundNext.invokeWriteAndFlush(data: data, promise: promise) + outboundNext.invokeWriteAndFlush(data, promise: promise) } else { promise?.fail(error: ChannelError.ioOnClosedChannel) } @@ -1006,9 +1006,9 @@ public final class ChannelHandlerContext : ChannelInvoker { /// - parameters: /// - event: The user event to send. /// - promise: The promise fulfilled when the user event has been sent or failed if it couldn't be sent. - public func triggerUserOutboundEvent(event: Any, promise: EventLoopPromise?) { + public func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise?) { if let outboundNext = self.prev { - outboundNext.invokeTriggerUserOutboundEvent(event: event, promise: promise) + outboundNext.invokeTriggerUserOutboundEvent(event, promise: promise) } else { promise?.fail(error: ChannelError.ioOnClosedChannel) } @@ -1024,7 +1024,7 @@ public final class ChannelHandlerContext : ChannelInvoker { self.next?.invokeChannelRegistered() } } catch let err { - invokeErrorCaught(error: err) + invokeErrorCaught(err) } } @@ -1038,7 +1038,7 @@ public final class ChannelHandlerContext : ChannelInvoker { self.next?.invokeChannelUnregistered() } } catch let err { - invokeErrorCaught(error: err) + invokeErrorCaught(err) } } @@ -1052,7 +1052,7 @@ public final class ChannelHandlerContext : ChannelInvoker { self.next?.invokeChannelActive() } } catch let err { - invokeErrorCaught(error: err) + invokeErrorCaught(err) } } @@ -1066,21 +1066,21 @@ public final class ChannelHandlerContext : ChannelInvoker { self.next?.invokeChannelInactive() } } catch let err { - invokeErrorCaught(error: err) + invokeErrorCaught(err) } } - fileprivate func invokeChannelRead(data: NIOAny) { + fileprivate func invokeChannelRead(_ data: NIOAny) { assert(inEventLoop) do { if let inboundHandler = self.inboundHandler { try inboundHandler.channelRead(ctx: self, data: data) } else { - self.next?.invokeChannelRead(data: data) + self.next?.invokeChannelRead(data) } } catch let err { - invokeErrorCaught(error: err) + invokeErrorCaught(err) } } @@ -1094,7 +1094,7 @@ public final class ChannelHandlerContext : ChannelInvoker { self.next?.invokeChannelReadComplete() } } catch let err { - invokeErrorCaught(error: err) + invokeErrorCaught(err) } } @@ -1108,36 +1108,36 @@ public final class ChannelHandlerContext : ChannelInvoker { self.next?.invokeChannelWritabilityChanged() } } catch let err { - invokeErrorCaught(error: err) + invokeErrorCaught(err) } } - fileprivate func invokeErrorCaught(error: Error) { + fileprivate func invokeErrorCaught(_ error: Error) { assert(inEventLoop) do { if let inboundHandler = self.inboundHandler { try inboundHandler.errorCaught(ctx: self, error: error) } else { - self.next?.invokeErrorCaught(error: error) + self.next?.invokeErrorCaught(error) } } catch let err { // Forward the error thrown by errorCaught through the pipeline - fireErrorCaught(error: err) + fireErrorCaught(err) } } - fileprivate func invokeUserInboundEventTriggered(event: Any) { + fileprivate func invokeUserInboundEventTriggered(_ event: Any) { assert(inEventLoop) do { if let inboundHandler = self.inboundHandler { try inboundHandler.userInboundEventTriggered(ctx: self, event: event) } else { - self.next?.invokeUserInboundEventTriggered(event: event) + self.next?.invokeUserInboundEventTriggered(event) } } catch let err { - invokeErrorCaught(error: err) + invokeErrorCaught(err) } } @@ -1174,14 +1174,14 @@ public final class ChannelHandlerContext : ChannelInvoker { } } - fileprivate func invokeWrite(data: NIOAny, promise: EventLoopPromise?) { + fileprivate func invokeWrite(_ data: NIOAny, promise: EventLoopPromise?) { assert(inEventLoop) assert(promise.map { !$0.futureResult.fulfilled } ?? true, "Promise \(promise!) already fulfilled") if let outboundHandler = self.outboundHandler { outboundHandler.write(ctx: self, data: data, promise: promise) } else { - self.prev?.invokeWrite(data: data, promise: promise) + self.prev?.invokeWrite(data, promise: promise) } } @@ -1195,7 +1195,7 @@ public final class ChannelHandlerContext : ChannelInvoker { } } - fileprivate func invokeWriteAndFlush(data: NIOAny, promise: EventLoopPromise?) { + fileprivate func invokeWriteAndFlush(_ data: NIOAny, promise: EventLoopPromise?) { assert(inEventLoop) assert(promise.map { !$0.futureResult.fulfilled } ?? true, "Promise \(promise!) already fulfilled") @@ -1228,7 +1228,7 @@ public final class ChannelHandlerContext : ChannelInvoker { outboundHandler.flush(ctx: self, promise: nil) } } else { - self.prev?.invokeWriteAndFlush(data: data, promise: promise) + self.prev?.invokeWriteAndFlush(data, promise: promise) } } @@ -1253,14 +1253,14 @@ public final class ChannelHandlerContext : ChannelInvoker { } } - fileprivate func invokeTriggerUserOutboundEvent(event: Any, promise: EventLoopPromise?) { + fileprivate func invokeTriggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise?) { assert(inEventLoop) assert(promise.map { !$0.futureResult.fulfilled } ?? true, "Promise \(promise!) already fulfilled") if let outboundHandler = self.outboundHandler { outboundHandler.triggerUserOutboundEvent(ctx: self, event: event, promise: promise) } else { - self.prev?.invokeTriggerUserOutboundEvent(event: event, promise: promise) + self.prev?.invokeTriggerUserOutboundEvent(event, promise: promise) } } diff --git a/Sources/NIO/Codec.swift b/Sources/NIO/Codec.swift index b0a7b1da0..1d410fe5d 100644 --- a/Sources/NIO/Codec.swift +++ b/Sources/NIO/Codec.swift @@ -68,7 +68,7 @@ extension ByteToMessageDecoder { public func handlerRemoved(ctx: ChannelHandlerContext) throws { if let buffer = cumulationBuffer as? InboundOut { - ctx.fireChannelRead(data: self.wrapInboundOut(buffer)) + ctx.fireChannelRead(self.wrapInboundOut(buffer)) } else { /* please note that we're dropping the partially received bytes (if any) on the floor here as we can't send a full message to the next handler. */ @@ -99,7 +99,7 @@ extension MessageToByteEncoder { let data = self.unwrapOutboundIn(data) var buffer: ByteBuffer = try allocateOutBuffer(ctx: ctx, data: data) try encode(ctx: ctx, data: data, out: &buffer) - ctx.write(data: self.wrapOutboundOut(buffer), promise: promise) + ctx.write(self.wrapOutboundOut(buffer), promise: promise) } catch let err { promise?.fail(error: err) } diff --git a/Sources/NIO/DeadChannel.swift b/Sources/NIO/DeadChannel.swift index de7a46efc..36940afcf 100644 --- a/Sources/NIO/DeadChannel.swift +++ b/Sources/NIO/DeadChannel.swift @@ -28,7 +28,7 @@ private final class DeadChannelCore: ChannelCore { promise?.fail(error: ChannelError.ioOnClosedChannel) } - func write0(data: NIOAny, promise: EventLoopPromise?) { + func write0(_ data: NIOAny, promise: EventLoopPromise?) { promise?.fail(error: ChannelError.ioOnClosedChannel) } @@ -44,11 +44,11 @@ private final class DeadChannelCore: ChannelCore { promise?.fail(error: ChannelError.alreadyClosed) } - func triggerUserOutboundEvent0(event: Any, promise: EventLoopPromise?) { + func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise?) { promise?.fail(error: ChannelError.ioOnClosedChannel) } - func channelRead0(data: NIOAny) { + func channelRead0(_ data: NIOAny) { // a `DeadChannel` should never be in any running `ChannelPipeline` and therefore the `TailChannelHandler` // should never invoke this. fatalError("\(#function) called on DeadChannelCore") diff --git a/Sources/NIO/Embedded.swift b/Sources/NIO/Embedded.swift index 9766b51b5..c56a05951 100644 --- a/Sources/NIO/Embedded.swift +++ b/Sources/NIO/Embedded.swift @@ -198,7 +198,7 @@ class EmbeddedChannelCore : ChannelCore { promise?.succeed(result: ()) } - func write0(data: NIOAny, promise: EventLoopPromise?) { + func write0(_ data: NIOAny, promise: EventLoopPromise?) { guard let data = data.tryAsIOData() else { promise?.fail(error: ChannelError.writeDataUnsupported) return @@ -224,11 +224,11 @@ class EmbeddedChannelCore : ChannelCore { promise?.succeed(result: ()) } - public final func triggerUserOutboundEvent0(event: Any, promise: EventLoopPromise?) { + public final func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise?) { promise?.succeed(result: ()) } - func channelRead0(data: NIOAny) { + func channelRead0(_ data: NIOAny) { addToBuffer(buffer: &inboundBuffer, data: data) } @@ -287,15 +287,15 @@ public class EmbeddedChannel : Channel { return readFromBuffer(buffer: &channelcore.inboundBuffer) } - @discardableResult public func writeInbound(data: T) throws -> Bool { - pipeline.fireChannelRead(data: NIOAny(data)) + @discardableResult public func writeInbound(_ data: T) throws -> Bool { + pipeline.fireChannelRead(NIOAny(data)) pipeline.fireChannelReadComplete() try throwIfErrorCaught() return !channelcore.inboundBuffer.isEmpty } - @discardableResult public func writeOutbound(data: T) throws -> Bool { - try writeAndFlush(data: NIOAny(data)).wait() + @discardableResult public func writeOutbound(_ data: T) throws -> Bool { + try writeAndFlush(NIOAny(data)).wait() return !channelcore.outboundBuffer.isEmpty } diff --git a/Sources/NIO/NIOAny.swift b/Sources/NIO/NIOAny.swift index e2845a2c5..e0816ab11 100644 --- a/Sources/NIO/NIOAny.swift +++ b/Sources/NIO/NIOAny.swift @@ -39,7 +39,7 @@ /// */ /// let bacon = self.unwrapInboundIn(data) /* `Bacon` or crash */ /// let sandwich = makeSandwich(bacon) -/// ctx.fireChannelRead(data: self.wrapInboundOut(sandwich)) /* as promised we deliver a wrapped `Sandwich` */ +/// ctx.fireChannelRead(self.wrapInboundOut(sandwich)) /* as promised we deliver a wrapped `Sandwich` */ /// } /// } public struct NIOAny { diff --git a/Sources/NIO/SocketChannel.swift b/Sources/NIO/SocketChannel.swift index b972ba048..a0d84b852 100644 --- a/Sources/NIO/SocketChannel.swift +++ b/Sources/NIO/SocketChannel.swift @@ -269,7 +269,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { } } - public final func write0(data: NIOAny, promise: EventLoopPromise?) { + public final func write0(_ data: NIOAny, promise: EventLoopPromise?) { assert(eventLoop.inEventLoop) if closed { @@ -437,7 +437,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { } } - public final func triggerUserOutboundEvent0(event: Any, promise: EventLoopPromise?) { + public final func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise?) { promise?.succeed(result: ()) } @@ -538,7 +538,7 @@ class BaseSocketChannel : SelectableChannel, ChannelCore { } } - public func channelRead0(data: NIOAny) { + public func channelRead0(_ data: NIOAny) { // Do nothing by default } @@ -718,7 +718,7 @@ final class SocketChannel: BaseSocketChannel { readPending = false assert(!closed) - pipeline.fireChannelRead0(data: NIOAny(buffer)) + pipeline.fireChannelRead0(NIOAny(buffer)) if mayGrow && i < maxMessagesPerRead { // if the ByteBuffer may grow on the next allocation due we used all the writable bytes we should allocate a new `ByteBuffer` to allow ramping up how much data // we are able to read on the next read operation. @@ -824,7 +824,7 @@ final class SocketChannel: BaseSocketChannel { unregisterForWritable() promise?.succeed(result: ()) - pipeline.fireUserInboundEventTriggered(event: ChannelEvent.outputClosed) + pipeline.fireUserInboundEventTriggered(ChannelEvent.outputClosed) case .input: if inputShutdown { @@ -843,7 +843,7 @@ final class SocketChannel: BaseSocketChannel { unregisterForReadable() promise?.succeed(result: ()) - pipeline.fireUserInboundEventTriggered(event: ChannelEvent.inputClosed) + pipeline.fireUserInboundEventTriggered(ChannelEvent.inputClosed) case .all: if let timeout = connectTimeoutScheduled { connectTimeoutScheduled = nil @@ -1038,7 +1038,7 @@ final class ServerSocketChannel : BaseSocketChannel { result = .some do { let chan = try SocketChannel(socket: accepted, eventLoop: group.next() as! SelectableEventLoop, parent: self) - pipeline.fireChannelRead0(data: NIOAny(chan)) + pipeline.fireChannelRead0(NIOAny(chan)) } catch let err { let _ = try? accepted.close() throw err @@ -1055,7 +1055,7 @@ final class ServerSocketChannel : BaseSocketChannel { return } - override public func channelRead0(data: NIOAny) { + override public func channelRead0(_ data: NIOAny) { assert(eventLoop.inEventLoop) let ch = data.forceAsOther() as SocketChannel diff --git a/Sources/NIOEchoClient/main.swift b/Sources/NIOEchoClient/main.swift index c53b94de5..69a71f643 100644 --- a/Sources/NIOEchoClient/main.swift +++ b/Sources/NIOEchoClient/main.swift @@ -48,7 +48,7 @@ private final class EchoHandler: ChannelInboundHandler { var buffer = ctx.channel.allocator.buffer(capacity: line.lengthOfBytes(using: String.Encoding.utf8)) buffer.write(string: line) self.numBytes = buffer.readableBytes - ctx.writeAndFlush(data: self.wrapOutboundOut(buffer), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(buffer), promise: nil) } } diff --git a/Sources/NIOEchoServer/main.swift b/Sources/NIOEchoServer/main.swift index 42987f512..50274253b 100644 --- a/Sources/NIOEchoServer/main.swift +++ b/Sources/NIOEchoServer/main.swift @@ -21,7 +21,7 @@ private final class EchoHandler: ChannelInboundHandler { public func channelRead(ctx: ChannelHandlerContext, data: NIOAny) { // As we are not really interested getting notified on success or failure we just pass nil as promise to // reduce allocations. - ctx.write(data: data, promise: nil) + ctx.write(data, promise: nil) } // Flush it out. This can make use of gathering writes if multiple buffers are pending diff --git a/Sources/NIOHTTP1/HTTPDecoder.swift b/Sources/NIOHTTP1/HTTPDecoder.swift index 0dee0f1ed..19067860c 100644 --- a/Sources/NIOHTTP1/HTTPDecoder.swift +++ b/Sources/NIOHTTP1/HTTPDecoder.swift @@ -195,7 +195,7 @@ public final class HTTPResponseDecoder: HTTPDecoder, Cha break } - ctx.write(data: data, promise: promise) + ctx.write(data, promise: promise) } } @@ -273,13 +273,13 @@ public class HTTPDecoder: ByteToMessageDecoder, AnyHTTPDecoder { case let handler as HTTPRequestDecoder: let head = handler.newRequestHead(parser) handler.pendingCallouts.append { - ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPServerRequestPart.head(head))) + ctx.fireChannelRead(handler.wrapInboundOut(HTTPServerRequestPart.head(head))) } return 0 case let handler as HTTPResponseDecoder: let head = handler.newResponseHead(parser) handler.pendingCallouts.append { - ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPClientResponsePart.head(head))) + ctx.fireChannelRead(handler.wrapInboundOut(HTTPClientResponsePart.head(head))) } // http_parser doesn't correctly handle responses to HEAD requests. We have to do something @@ -311,9 +311,9 @@ public class HTTPDecoder: ByteToMessageDecoder, AnyHTTPDecoder { handler.pendingCallouts.append { switch handler { case let handler as HTTPRequestDecoder: - ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPServerRequestPart.body(slice))) + ctx.fireChannelRead(handler.wrapInboundOut(HTTPServerRequestPart.body(slice))) case let handler as HTTPResponseDecoder: - ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPClientResponsePart.body(slice))) + ctx.fireChannelRead(handler.wrapInboundOut(HTTPClientResponsePart.body(slice))) default: fatalError("the impossible happened: handler neither a HTTPRequestDecoder nor a HTTPResponseDecoder which should be impossible") } @@ -373,9 +373,9 @@ public class HTTPDecoder: ByteToMessageDecoder, AnyHTTPDecoder { handler.pendingCallouts.append { switch handler { case let handler as HTTPRequestDecoder: - ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPServerRequestPart.end(trailers))) + ctx.fireChannelRead(handler.wrapInboundOut(HTTPServerRequestPart.end(trailers))) case let handler as HTTPResponseDecoder: - ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPClientResponsePart.end(trailers))) + ctx.fireChannelRead(handler.wrapInboundOut(HTTPClientResponsePart.end(trailers))) default: fatalError("the impossible happened: handler neither a HTTPRequestDecoder nor a HTTPResponseDecoder which should be impossible") } @@ -444,7 +444,7 @@ public class HTTPDecoder: ByteToMessageDecoder, AnyHTTPDecoder { } public func errorCaught(ctx: ChannelHandlerContext, error: Error) { - ctx.fireErrorCaught(error: error) + ctx.fireErrorCaught(error) if error is HTTPParserError { ctx.close(promise: nil) } diff --git a/Sources/NIOHTTP1/HTTPEncoder.swift b/Sources/NIOHTTP1/HTTPEncoder.swift index af37c66e4..2ac22a2f1 100644 --- a/Sources/NIOHTTP1/HTTPEncoder.swift +++ b/Sources/NIOHTTP1/HTTPEncoder.swift @@ -40,15 +40,15 @@ private func writeChunk(wrapOutboundOut: (IOData) -> NIOAny, ctx: ChannelHandler let len = String(readableBytes, radix: 16) buffer.write(string: len) buffer.write(staticString: "\r\n") - ctx.write(data: wrapOutboundOut(.byteBuffer(buffer)), promise: mW1) + ctx.write(wrapOutboundOut(.byteBuffer(buffer)), promise: mW1) - ctx.write(data: wrapOutboundOut(chunk), promise: mW2) + ctx.write(wrapOutboundOut(chunk), promise: mW2) // Just move the buffers readerIndex to only make the \r\n readable and depend on COW semantics. buffer.moveReaderIndex(forwardBy: buffer.readableBytes - 2) - ctx.write(data: wrapOutboundOut(.byteBuffer(buffer)), promise: mW3) + ctx.write(wrapOutboundOut(.byteBuffer(buffer)), promise: mW3) } else { - ctx.write(data: wrapOutboundOut(chunk), promise: mW2) + ctx.write(wrapOutboundOut(chunk), promise: mW2) } } @@ -64,12 +64,12 @@ private func writeTrailers(wrapOutboundOut: (IOData) -> NIOAny, ctx: ChannelHand buffer = ctx.channel.allocator.buffer(capacity: 8) buffer.write(staticString: "0\r\n\r\n") } - ctx.write(data: wrapOutboundOut(.byteBuffer(buffer)), promise: p) + ctx.write(wrapOutboundOut(.byteBuffer(buffer)), promise: p) case (false, .some(let p)): // Not chunked so we have nothing to write. However, we don't want to satisfy this promise out-of-order // so we issue a zero-length write down the chain. let buf = ctx.channel.allocator.buffer(capacity: 0) - ctx.write(data: wrapOutboundOut(.byteBuffer(buf)), promise: p) + ctx.write(wrapOutboundOut(.byteBuffer(buf)), promise: p) case (false, .none): break } @@ -80,7 +80,7 @@ private func writeHead(wrapOutboundOut: (IOData) -> NIOAny, writeStartLine: (ino var buffer = ctx.channel.allocator.buffer(capacity: 256) writeStartLine(&buffer) headers.write(buffer: &buffer) - ctx.write(data: wrapOutboundOut(.byteBuffer(buffer)), promise: promise) + ctx.write(wrapOutboundOut(.byteBuffer(buffer)), promise: promise) } private func isChunkedPart(_ headers: HTTPHeaders) -> Bool { diff --git a/Sources/NIOHTTP1/HTTPResponseCompressor.swift b/Sources/NIOHTTP1/HTTPResponseCompressor.swift index 290c04a31..19723af73 100644 --- a/Sources/NIOHTTP1/HTTPResponseCompressor.swift +++ b/Sources/NIOHTTP1/HTTPResponseCompressor.swift @@ -97,7 +97,7 @@ public final class HTTPResponseCompressor: ChannelInboundHandler, ChannelOutboun default: break } - ctx.fireChannelRead(data: data) + ctx.fireChannelRead(data) } public func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise?) { @@ -106,7 +106,7 @@ public final class HTTPResponseCompressor: ChannelInboundHandler, ChannelOutboun case .head(var responseHead): algorithm = compressionAlgorithm() guard algorithm != nil else { - ctx.write(data: wrapOutboundOut(.head(responseHead)), promise: promise) + ctx.write(wrapOutboundOut(.head(responseHead)), promise: promise) return } @@ -119,13 +119,13 @@ public final class HTTPResponseCompressor: ChannelInboundHandler, ChannelOutboun pendingResponse.bufferBodyPart(body) chainPromise(promise) } else { - ctx.write(data: data, promise: promise) + ctx.write(data, promise: promise) } case .end: // This compress is not done in flush because we need to be done with the // compressor now. guard algorithm != nil else { - ctx.write(data: data, promise: promise) + ctx.write(data, promise: promise) return } @@ -216,17 +216,17 @@ public final class HTTPResponseCompressor: ChannelInboundHandler, ChannelOutboun var pendingPromise = pendingWritePromise if let writeHead = writesToEmit.0 { - ctx.write(data: wrapOutboundOut(.head(writeHead)), promise: pendingPromise) + ctx.write(wrapOutboundOut(.head(writeHead)), promise: pendingPromise) pendingPromise = nil } if let writeBody = writesToEmit.1 { - ctx.write(data: wrapOutboundOut(.body(.byteBuffer(writeBody))), promise: pendingPromise) + ctx.write(wrapOutboundOut(.body(.byteBuffer(writeBody))), promise: pendingPromise) pendingPromise = nil } if let writeEnd = writesToEmit.2 { - ctx.write(data: wrapOutboundOut(writeEnd), promise: pendingPromise) + ctx.write(wrapOutboundOut(writeEnd), promise: pendingPromise) pendingPromise = nil } diff --git a/Sources/NIOHTTP1/HTTPUpgradeHandler.swift b/Sources/NIOHTTP1/HTTPUpgradeHandler.swift index 274f10a5b..d4d20cdd2 100644 --- a/Sources/NIOHTTP1/HTTPUpgradeHandler.swift +++ b/Sources/NIOHTTP1/HTTPUpgradeHandler.swift @@ -86,7 +86,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler { public func channelRead(ctx: ChannelHandlerContext, data: NIOAny) { // We're trying to remove ourselves from the pipeline, so just pass this on. if seenFirstRequest { - ctx.fireChannelRead(data: data) + ctx.fireChannelRead(data) return } @@ -96,7 +96,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler { // We should only ever see a request header: by the time the body comes in we should // be out of the pipeline. Anything else is an error. guard case .head(let request) = requestPart else { - ctx.fireErrorCaught(error: HTTPUpgradeErrors.invalidHTTPOrdering) + ctx.fireErrorCaught(HTTPUpgradeErrors.invalidHTTPOrdering) notUpgrading(ctx: ctx, data: data) return } @@ -135,14 +135,14 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler { responseHeaders = try upgrader.buildUpgradeResponse(upgradeRequest: request, initialResponseHeaders: responseHeaders) } catch { // We should fire this error so the user can log it, but keep going. - ctx.fireErrorCaught(error: error) + ctx.fireErrorCaught(error) continue } sendUpgradeResponse(ctx: ctx, upgradeRequest: request, responseHeaders: responseHeaders).whenSuccess { self.upgradeCompletionHandler(ctx) upgrader.upgrade(ctx: ctx, upgradeRequest: request) - ctx.fireUserInboundEventTriggered(event: HTTPUpgradeEvents.upgradeComplete(toProtocol: proto, upgradeRequest: request)) + ctx.fireUserInboundEventTriggered(HTTPUpgradeEvents.upgradeComplete(toProtocol: proto, upgradeRequest: request)) let _ = ctx.pipeline.remove(ctx: ctx) } @@ -156,12 +156,12 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler { private func sendUpgradeResponse(ctx: ChannelHandlerContext, upgradeRequest: HTTPRequestHead, responseHeaders: HTTPHeaders) -> EventLoopFuture { var response = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .switchingProtocols) response.headers = responseHeaders - return ctx.writeAndFlush(data: wrapOutboundOut(HTTPServerResponsePart.head(response))) + return ctx.writeAndFlush(wrapOutboundOut(HTTPServerResponsePart.head(response))) } /// Called when we know we're not upgrading. Passes the data on and then removes this object from the pipeline. private func notUpgrading(ctx: ChannelHandlerContext, data: NIOAny) { - ctx.fireChannelRead(data: data) + ctx.fireChannelRead(data) let _ = ctx.pipeline.remove(ctx: ctx) } diff --git a/Sources/NIOHTTP1Server/main.swift b/Sources/NIOHTTP1Server/main.swift index 39b6238bf..f908c3732 100644 --- a/Sources/NIOHTTP1Server/main.swift +++ b/Sources/NIOHTTP1Server/main.swift @@ -71,9 +71,9 @@ private final class HTTPHandler: ChannelInboundHandler { self.buffer.write(string: response) var headers = HTTPHeaders() headers.add(name: "Content-Length", value: "\(response.utf8.count)") - ctx.write(data: self.wrapOutboundOut(.head(HTTPResponseHead(version: self.infoSavedRequestHead!.version, status: .ok, headers: headers))), promise: nil) - ctx.write(data: self.wrapOutboundOut(.body(.byteBuffer(self.buffer))), promise: nil) - ctx.writeAndFlush(data: self.wrapOutboundOut(.end(nil)), promise: nil) + ctx.write(self.wrapOutboundOut(.head(HTTPResponseHead(version: self.infoSavedRequestHead!.version, status: .ok, headers: headers))), promise: nil) + ctx.write(self.wrapOutboundOut(.body(.byteBuffer(self.buffer))), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil) } } @@ -87,23 +87,23 @@ private final class HTTPHandler: ChannelInboundHandler { if balloonInMemory { self.buffer.clear() } else { - ctx.writeAndFlush(data: self.wrapOutboundOut(.head(.init(version: request.version, status: .ok))), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.head(.init(version: request.version, status: .ok))), promise: nil) } case .body(buffer: var buf): if balloonInMemory { self.buffer.write(buffer: &buf) } else { - ctx.writeAndFlush(data: self.wrapOutboundOut(.body(.byteBuffer(buf))), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.body(.byteBuffer(buf))), promise: nil) } case .end(_): if balloonInMemory { var headers = HTTPHeaders() headers.add(name: "Content-Length", value: "\(self.buffer.readableBytes)") - ctx.write(data: self.wrapOutboundOut(.head(HTTPResponseHead(version: HTTPVersion(major: 1, minor: 0), status: .ok, headers: headers))), promise: nil) - ctx.write(data: self.wrapOutboundOut(.body(.byteBuffer(self.buffer))), promise: nil) - ctx.write(data: self.wrapOutboundOut(.end(nil)), promise: nil) + ctx.write(self.wrapOutboundOut(.head(HTTPResponseHead(version: HTTPVersion(major: 1, minor: 0), status: .ok, headers: headers))), promise: nil) + ctx.write(self.wrapOutboundOut(.body(.byteBuffer(self.buffer))), promise: nil) + ctx.write(self.wrapOutboundOut(.end(nil)), promise: nil) } else { - ctx.writeAndFlush(data: self.wrapOutboundOut(.end(nil)), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil) } } } @@ -111,20 +111,20 @@ private final class HTTPHandler: ChannelInboundHandler { func handleJustWrite(ctx: ChannelHandlerContext, request: HTTPServerRequestPart, statusCode: HTTPResponseStatus = .ok, string: String, trailer: (String, String)? = nil, delay: TimeAmount = .nanoseconds(0)) { switch request { case .head(let request): - ctx.writeAndFlush(data: self.wrapOutboundOut(.head(.init(version: request.version, status: .ok))), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.head(.init(version: request.version, status: .ok))), promise: nil) case .body(buffer: _): () case .end(_): let _ = ctx.eventLoop.scheduleTask(in: delay) { () -> Void in var buf = ctx.channel.allocator.buffer(capacity: string.utf8.count) buf.write(string: string) - ctx.writeAndFlush(data: self.wrapOutboundOut(.body(.byteBuffer(buf))), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.body(.byteBuffer(buf))), promise: nil) var trailers: HTTPHeaders? = nil if let trailer = trailer { trailers = HTTPHeaders() trailers?.add(name: trailer.0, value: trailer.1) } - ctx.writeAndFlush(data: self.wrapOutboundOut(.end(trailers)), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.end(trailers)), promise: nil) } } } @@ -137,16 +137,16 @@ private final class HTTPHandler: ChannelInboundHandler { self.buffer.clear() self.continuousCount += 1 self.buffer.write(string: "line \(self.continuousCount)\n") - ctx.writeAndFlush(data: self.wrapOutboundOut(.body(.byteBuffer(self.buffer)))).whenComplete { res in + ctx.writeAndFlush(self.wrapOutboundOut(.body(.byteBuffer(self.buffer)))).whenComplete { res in switch res { case .success(()): _ = ctx.eventLoop.scheduleTask(in: .milliseconds(400), doNext) case .failure(_): - ctx.writeAndFlush(data: self.wrapOutboundOut(.end(nil)), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil) } } } - ctx.writeAndFlush(data: self.wrapOutboundOut(.head(HTTPResponseHead(version: request.version, status: .ok))), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.head(HTTPResponseHead(version: request.version, status: .ok))), promise: nil) doNext() default: () @@ -160,13 +160,13 @@ private final class HTTPHandler: ChannelInboundHandler { func doNext() { self.buffer.clear() self.buffer.write(string: strings[self.continuousCount]) - ctx.writeAndFlush(data: self.wrapOutboundOut(.body(.byteBuffer(self.buffer)))).whenComplete { res in + ctx.writeAndFlush(self.wrapOutboundOut(.body(.byteBuffer(self.buffer)))).whenComplete { res in switch res { case .success(()): if self.continuousCount < strings.count - 1 { _ = ctx.eventLoop.scheduleTask(in: delay, doNext) } else { - ctx.writeAndFlush(data: self.wrapOutboundOut(.end(nil)), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil) } case .failure(_): () @@ -174,7 +174,7 @@ private final class HTTPHandler: ChannelInboundHandler { } self.continuousCount += 1 } - ctx.writeAndFlush(data: self.wrapOutboundOut(.head(HTTPResponseHead(version: request.version, status: .ok))), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.head(HTTPResponseHead(version: request.version, status: .ok))), promise: nil) doNext() default: () @@ -213,8 +213,8 @@ private final class HTTPHandler: ChannelInboundHandler { case .head(let request): guard !request.uri.contains("..") else { let response = HTTPResponseHead(version: request.version, status: .forbidden) - ctx.write(data: self.wrapOutboundOut(.head(response)), promise: nil) - ctx.writeAndFlush(data: self.wrapOutboundOut(.end(nil)), promise: nil) + ctx.write(self.wrapOutboundOut(.head(response)), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil) return } let path = self.htdocsPath + "/" + path @@ -234,19 +234,19 @@ private final class HTTPHandler: ChannelInboundHandler { eventLoop: ctx.eventLoop) { buffer in if !responseStarted { responseStarted = true - ctx.write(data: self.wrapOutboundOut(.head(response)), promise: nil) + ctx.write(self.wrapOutboundOut(.head(response)), promise: nil) } - return ctx.writeAndFlush(data: self.wrapOutboundOut(.body(.byteBuffer(buffer)))) + return ctx.writeAndFlush(self.wrapOutboundOut(.body(.byteBuffer(buffer)))) }.then { _ in - ctx.writeAndFlush(data: self.wrapOutboundOut(.end(nil))) + ctx.writeAndFlush(self.wrapOutboundOut(.end(nil))) }.thenIfError { error in if !responseStarted { let response = HTTPResponseHead(version: request.version, status: .ok) - ctx.write(data: self.wrapOutboundOut(.head(response)), promise: nil) + ctx.write(self.wrapOutboundOut(.head(response)), promise: nil) var buffer = ctx.channel.allocator.buffer(capacity: 100) buffer.write(string: "fail: \(error.localizedDescription)") - ctx.write(data: self.wrapOutboundOut(.body(.byteBuffer(buffer))), promise: nil) - return ctx.writeAndFlush(data: self.wrapOutboundOut(.end(nil))) + ctx.write(self.wrapOutboundOut(.body(.byteBuffer(buffer))), promise: nil) + return ctx.writeAndFlush(self.wrapOutboundOut(.end(nil))) } else { return ctx.close() } @@ -254,10 +254,10 @@ private final class HTTPHandler: ChannelInboundHandler { _ = try? region.close() } case .sendfile: - ctx.write(data: self.wrapOutboundOut(.head(response))).then { _ in - ctx.writeAndFlush(data: self.wrapOutboundOut(.body(.fileRegion(region)))) - } .then { _ in - ctx.writeAndFlush(data: self.wrapOutboundOut(.end(nil))) + ctx.write(self.wrapOutboundOut(.head(response))).then { _ in + ctx.writeAndFlush(self.wrapOutboundOut(.body(.fileRegion(region)))) + }.then { _ in + ctx.writeAndFlush(self.wrapOutboundOut(.end(nil))) }.thenIfError { _ in ctx.close() }.whenComplete { _ in @@ -283,9 +283,9 @@ private final class HTTPHandler: ChannelInboundHandler { }() body.write(string: error.localizedDescription) body.write(staticString: "\r\n") - ctx.write(data: self.wrapOutboundOut(.head(response)), promise: nil) - ctx.write(data: self.wrapOutboundOut(.body(.byteBuffer(body))), promise: nil) - ctx.writeAndFlush(data: self.wrapOutboundOut(.end(nil)), promise: nil) + ctx.write(self.wrapOutboundOut(.head(response)), promise: nil) + ctx.write(self.wrapOutboundOut(.body(.byteBuffer(body))), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil) ctx.channel.close(promise: nil) } case .end(_): @@ -323,17 +323,17 @@ private final class HTTPHandler: ChannelInboundHandler { var responseHead = HTTPResponseHead(version: request.version, status: HTTPResponseStatus.ok) responseHead.headers.add(name: "content-length", value: "12") let response = HTTPServerResponsePart.head(responseHead) - ctx.write(data: self.wrapOutboundOut(response), promise: nil) + ctx.write(self.wrapOutboundOut(response), promise: nil) case .body: break case .end: let content = HTTPServerResponsePart.body(.byteBuffer(buffer!.slice())) - ctx.write(data: self.wrapOutboundOut(content), promise: nil) + ctx.write(self.wrapOutboundOut(content), promise: nil) if keepAlive { - ctx.write(data: self.wrapOutboundOut(HTTPServerResponsePart.end(nil)), promise: nil) + ctx.write(self.wrapOutboundOut(HTTPServerResponsePart.end(nil)), promise: nil) } else { - ctx.write(data: self.wrapOutboundOut(HTTPServerResponsePart.end(nil))).whenComplete { _ in + ctx.write(self.wrapOutboundOut(HTTPServerResponsePart.end(nil))).whenComplete { _ in ctx.close(promise: nil) } } diff --git a/Sources/NIOTLS/ApplicationProtocolNegotiationHandler.swift b/Sources/NIOTLS/ApplicationProtocolNegotiationHandler.swift index 4777b8080..cc484738a 100644 --- a/Sources/NIOTLS/ApplicationProtocolNegotiationHandler.swift +++ b/Sources/NIOTLS/ApplicationProtocolNegotiationHandler.swift @@ -88,7 +88,7 @@ public class ApplicationProtocolNegotiationHandler: ChannelInboundHandler { public func userInboundEventTriggered(ctx: ChannelHandlerContext, event: Any) { guard let tlsEvent = event as? TLSUserEvent else { - ctx.fireUserInboundEventTriggered(event: event) + ctx.fireUserInboundEventTriggered(event) return } @@ -96,7 +96,7 @@ public class ApplicationProtocolNegotiationHandler: ChannelInboundHandler { case .handshakeCompleted(let p): handshakeCompleted(context: ctx, negotiatedProtocol: p) default: - ctx.fireUserInboundEventTriggered(event: event) + ctx.fireUserInboundEventTriggered(event) } } @@ -104,7 +104,7 @@ public class ApplicationProtocolNegotiationHandler: ChannelInboundHandler { if waitingForUser { eventBuffer.append(data) } else { - ctx.fireChannelRead(data: data) + ctx.fireChannelRead(data) } } @@ -127,7 +127,7 @@ public class ApplicationProtocolNegotiationHandler: ChannelInboundHandler { private func unbuffer(context: ChannelHandlerContext) { for datum in eventBuffer { - context.fireChannelRead(data: datum) + context.fireChannelRead(datum) } let buffer = eventBuffer eventBuffer = [] diff --git a/Tests/NIOHTTP1Tests/HTTPRequestEncoderTest.swift b/Tests/NIOHTTP1Tests/HTTPRequestEncoderTest.swift index ce9756a76..cb1bb05c3 100644 --- a/Tests/NIOHTTP1Tests/HTTPRequestEncoderTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPRequestEncoderTest.swift @@ -32,7 +32,7 @@ class HTTPRequestEncoderTests: XCTestCase { try channel.pipeline.add(handler: HTTPRequestEncoder()).wait() var request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:1), method: method, uri: "/uri") request.headers = headers - try channel.writeOutbound(data: HTTPClientRequestPart.head(request)) + try channel.writeOutbound(HTTPClientRequestPart.head(request)) if case .some(.byteBuffer(let buffer)) = channel.readOutbound() { return buffer } else { @@ -82,7 +82,7 @@ class HTTPRequestEncoderTests: XCTestCase { // This request contains neither Transfer-Encoding: chunked or Content-Length. let request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:0), method: .GET, uri: "/uri") - XCTAssertNoThrow(try channel.writeOutbound(data: HTTPClientRequestPart.head(request))) + XCTAssertNoThrow(try channel.writeOutbound(HTTPClientRequestPart.head(request))) let writtenData: IOData = channel.readOutbound()! switch writtenData { @@ -107,9 +107,9 @@ class HTTPRequestEncoderTests: XCTestCase { var buf = channel.allocator.buffer(capacity: 4) buf.write(staticString: "test") - XCTAssertNoThrow(try channel.writeOutbound(data: HTTPClientRequestPart.head(request))) - XCTAssertNoThrow(try channel.writeOutbound(data: HTTPClientRequestPart.body(.byteBuffer(buf)))) - XCTAssertNoThrow(try channel.writeOutbound(data: HTTPClientRequestPart.end(nil))) + XCTAssertNoThrow(try channel.writeOutbound(HTTPClientRequestPart.head(request))) + XCTAssertNoThrow(try channel.writeOutbound(HTTPClientRequestPart.body(.byteBuffer(buf)))) + XCTAssertNoThrow(try channel.writeOutbound(HTTPClientRequestPart.end(nil))) assertOutboundContainsOnly(channel, "POST /uri HTTP/1.1\r\ncontent-length: 4\r\n\r\n") assertOutboundContainsOnly(channel, "test") diff --git a/Tests/NIOHTTP1Tests/HTTPResponseCompressorTest.swift b/Tests/NIOHTTP1Tests/HTTPResponseCompressorTest.swift index 787186e33..22078bedd 100644 --- a/Tests/NIOHTTP1Tests/HTTPResponseCompressorTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPResponseCompressorTest.swift @@ -130,8 +130,8 @@ class HTTPResponseCompressorTest: XCTestCase { if let acceptEncoding = acceptEncoding { requestHead.headers.add(name: "Accept-Encoding", value: acceptEncoding) } - try channel.writeInbound(data: HTTPServerRequestPart.head(requestHead)) - try channel.writeInbound(data: HTTPServerRequestPart.end(nil)) + try channel.writeInbound(HTTPServerRequestPart.head(requestHead)) + try channel.writeInbound(HTTPServerRequestPart.end(nil)) } private func clientParsingChannel() -> EmbeddedChannel { @@ -142,14 +142,14 @@ class HTTPResponseCompressorTest: XCTestCase { private func writeOneChunk(head: HTTPResponseHead, body: [ByteBuffer], channel: EmbeddedChannel) throws { let promiseOrderer = PromiseOrderer(eventLoop: channel.eventLoop) - channel.pipeline.write(data: NIOAny(HTTPServerResponsePart.head(head)), promise: promiseOrderer.newPromise()) + channel.pipeline.write(NIOAny(HTTPServerResponsePart.head(head)), promise: promiseOrderer.newPromise()) for bodyChunk in body { - channel.pipeline.write(data: NIOAny(HTTPServerResponsePart.body(.byteBuffer(bodyChunk))), + channel.pipeline.write(NIOAny(HTTPServerResponsePart.body(.byteBuffer(bodyChunk))), promise: promiseOrderer.newPromise()) } - channel.pipeline.write(data: NIOAny(HTTPServerResponsePart.end(nil)), + channel.pipeline.write(NIOAny(HTTPServerResponsePart.end(nil)), promise: promiseOrderer.newPromise()) channel.pipeline.flush(promise: promiseOrderer.newPromise()) @@ -160,16 +160,16 @@ class HTTPResponseCompressorTest: XCTestCase { private func writeIntermittentFlushes(head: HTTPResponseHead, body: [ByteBuffer], channel: EmbeddedChannel) throws { let promiseOrderer = PromiseOrderer(eventLoop: channel.eventLoop) var writeCount = 0 - channel.pipeline.write(data: NIOAny(HTTPServerResponsePart.head(head)), promise: promiseOrderer.newPromise()) + channel.pipeline.write(NIOAny(HTTPServerResponsePart.head(head)), promise: promiseOrderer.newPromise()) for bodyChunk in body { - channel.pipeline.write(data: NIOAny(HTTPServerResponsePart.body(.byteBuffer(bodyChunk))), + channel.pipeline.write(NIOAny(HTTPServerResponsePart.body(.byteBuffer(bodyChunk))), promise: promiseOrderer.newPromise()) writeCount += 1 if writeCount % 3 == 0 { channel.pipeline.flush(promise: promiseOrderer.newPromise()) } } - channel.pipeline.write(data: NIOAny(HTTPServerResponsePart.end(nil)), + channel.pipeline.write(NIOAny(HTTPServerResponsePart.end(nil)), promise: promiseOrderer.newPromise()) channel.pipeline.flush(promise: promiseOrderer.newPromise()) @@ -196,12 +196,12 @@ class HTTPResponseCompressorTest: XCTestCase { } var requestHead = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/") requestHead.headers.add(name: "host", value: "apple.com") - clientChannel.write(data: NIOAny(HTTPClientRequestPart.head(requestHead)), promise: nil) - clientChannel.write(data: NIOAny(HTTPClientRequestPart.end(nil)), promise: nil) + clientChannel.write(NIOAny(HTTPClientRequestPart.head(requestHead)), promise: nil) + clientChannel.write(NIOAny(HTTPClientRequestPart.end(nil)), promise: nil) while let nextPart = channel.readOutbound() { if case .byteBuffer(let b) = nextPart { - try clientChannel.writeInbound(data: b) + try clientChannel.writeInbound(b) } else { fatalError("We always write bytes") } @@ -502,7 +502,7 @@ class HTTPResponseCompressorTest: XCTestCase { try sendRequest(acceptEncoding: "gzip", channel: channel) let head = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .ok) let writePromise: EventLoopPromise = channel.eventLoop.newPromise() - channel.write(data: NIOAny(HTTPServerResponsePart.head(head)), promise: writePromise) + channel.write(NIOAny(HTTPServerResponsePart.head(head)), promise: writePromise) writePromise.futureResult.whenComplete { result in switch result { case .success: @@ -528,7 +528,7 @@ class HTTPResponseCompressorTest: XCTestCase { try sendRequest(acceptEncoding: nil, channel: channel) let head = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .ok) let writePromise: EventLoopPromise = channel.eventLoop.newPromise() - channel.write(data: NIOAny(HTTPServerResponsePart.head(head)), promise: writePromise) + channel.write(NIOAny(HTTPServerResponsePart.head(head)), promise: writePromise) channel.pipeline.removeHandlers() try writePromise.futureResult.wait() } diff --git a/Tests/NIOHTTP1Tests/HTTPResponseEncoderTest.swift b/Tests/NIOHTTP1Tests/HTTPResponseEncoderTest.swift index 8c0cecf3e..6e8728244 100644 --- a/Tests/NIOHTTP1Tests/HTTPResponseEncoderTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPResponseEncoderTest.swift @@ -32,7 +32,7 @@ class HTTPResponseEncoderTests: XCTestCase { XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseEncoder()).wait()) var switchingResponse = HTTPResponseHead(version: HTTPVersion(major: 1, minor:1), status: status) switchingResponse.headers = headers - XCTAssertNoThrow(try channel.writeOutbound(data: HTTPServerResponsePart.head(switchingResponse))) + XCTAssertNoThrow(try channel.writeOutbound(HTTPServerResponsePart.head(switchingResponse))) if case .some(.byteBuffer(let buffer)) = channel.readOutbound() { return buffer } else { @@ -102,7 +102,7 @@ class HTTPResponseEncoderTests: XCTestCase { // This response contains neither Transfer-Encoding: chunked or Content-Length. let response = HTTPResponseHead(version: HTTPVersion(major: 1, minor:0), status: .ok) - XCTAssertNoThrow(try channel.writeOutbound(data: HTTPServerResponsePart.head(response))) + XCTAssertNoThrow(try channel.writeOutbound(HTTPServerResponsePart.head(response))) let writtenData: IOData = channel.readOutbound()! switch writtenData{ diff --git a/Tests/NIOHTTP1Tests/HTTPServerClientTest.swift b/Tests/NIOHTTP1Tests/HTTPServerClientTest.swift index e06ea31f5..cec9b9f2f 100644 --- a/Tests/NIOHTTP1Tests/HTTPServerClientTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPServerClientTest.swift @@ -151,15 +151,15 @@ class HTTPServerClientTest : XCTestCase { head.headers.add(name: "Content-Length", value: "\(replyString.utf8.count)") head.headers.add(name: "Connection", value: "close") let r = HTTPServerResponsePart.head(head) - ctx.write(data: self.wrapOutboundOut(r), promise: nil) + ctx.write(self.wrapOutboundOut(r), promise: nil) var b = ctx.channel.allocator.buffer(capacity: replyString.count) b.write(string: replyString) let outbound = self.outboundBody(b) - ctx.write(data: self.wrapOutboundOut(outbound.body)).whenComplete { _ in + ctx.write(self.wrapOutboundOut(outbound.body)).whenComplete { _ in outbound.destructor() } - ctx.write(data: self.wrapOutboundOut(.end(nil))).whenComplete { r in + ctx.write(self.wrapOutboundOut(.end(nil))).whenComplete { r in assertSuccess(r) self.sentEnd = true self.maybeClose(ctx: ctx) @@ -168,7 +168,7 @@ class HTTPServerClientTest : XCTestCase { var head = HTTPResponseHead(version: req.version, status: .ok) head.headers.add(name: "Connection", value: "close") let r = HTTPServerResponsePart.head(head) - ctx.write(data: self.wrapOutboundOut(r)).whenComplete { r in + ctx.write(self.wrapOutboundOut(r)).whenComplete { r in assertSuccess(r) } var b = ctx.channel.allocator.buffer(capacity: 1024) @@ -177,12 +177,12 @@ class HTTPServerClientTest : XCTestCase { b.write(string: "\(i)") let outbound = self.outboundBody(b) - ctx.write(data: self.wrapOutboundOut(outbound.body)).whenComplete { r in + ctx.write(self.wrapOutboundOut(outbound.body)).whenComplete { r in outbound.destructor() assertSuccess(r) } } - ctx.write(data: self.wrapOutboundOut(.end(nil))).whenComplete { r in + ctx.write(self.wrapOutboundOut(.end(nil))).whenComplete { r in assertSuccess(r) self.sentEnd = true self.maybeClose(ctx: ctx) @@ -192,7 +192,7 @@ class HTTPServerClientTest : XCTestCase { head.headers.add(name: "Connection", value: "close") head.headers.add(name: "Transfer-Encoding", value: "chunked") let r = HTTPServerResponsePart.head(head) - ctx.write(data: self.wrapOutboundOut(r)).whenComplete { r in + ctx.write(self.wrapOutboundOut(r)).whenComplete { r in assertSuccess(r) } var b = ctx.channel.allocator.buffer(capacity: 1024) @@ -201,7 +201,7 @@ class HTTPServerClientTest : XCTestCase { b.write(string: "\(i)") let outbound = self.outboundBody(b) - ctx.write(data: self.wrapOutboundOut(outbound.body)).whenComplete { r in + ctx.write(self.wrapOutboundOut(outbound.body)).whenComplete { r in outbound.destructor() assertSuccess(r) } @@ -210,7 +210,7 @@ class HTTPServerClientTest : XCTestCase { var trailers = HTTPHeaders() trailers.add(name: "X-URL-Path", value: "/trailers") trailers.add(name: "X-Should-Trail", value: "sure") - ctx.write(data: self.wrapOutboundOut(.end(trailers))).whenComplete { r in + ctx.write(self.wrapOutboundOut(.end(trailers))).whenComplete { r in assertSuccess(r) self.sentEnd = true self.maybeClose(ctx: ctx) @@ -230,15 +230,15 @@ class HTTPServerClientTest : XCTestCase { head.headers.add(name: "Connection", value: "close") head.headers.add(name: "Content-Length", value: "\(HTTPServerClientTest.massiveResponseLength)") let r = HTTPServerResponsePart.head(head) - ctx.write(data: self.wrapOutboundOut(r)).whenComplete { r in + ctx.write(self.wrapOutboundOut(r)).whenComplete { r in assertSuccess(r) } let outbound = self.outboundBody(buf) - ctx.writeAndFlush(data: self.wrapOutboundOut(outbound.body)).whenComplete { r in + ctx.writeAndFlush(self.wrapOutboundOut(outbound.body)).whenComplete { r in outbound.destructor() assertSuccess(r) } - ctx.write(data: self.wrapOutboundOut(.end(nil))).whenComplete { r in + ctx.write(self.wrapOutboundOut(.end(nil))).whenComplete { r in assertSuccess(r) self.sentEnd = true self.maybeClose(ctx: ctx) @@ -247,10 +247,10 @@ class HTTPServerClientTest : XCTestCase { var head = HTTPResponseHead(version: req.version, status: .ok) head.headers.add(name: "Connection", value: "close") head.headers.add(name: "Content-Length", value: "5000") - ctx.write(data: self.wrapOutboundOut(.head(head))).whenComplete { r in + ctx.write(self.wrapOutboundOut(.head(head))).whenComplete { r in assertSuccess(r) } - ctx.write(data: self.wrapOutboundOut(.end(nil))).whenComplete { r in + ctx.write(self.wrapOutboundOut(.end(nil))).whenComplete { r in assertSuccess(r) self.sentEnd = true self.maybeClose(ctx: ctx) @@ -258,10 +258,10 @@ class HTTPServerClientTest : XCTestCase { case "/204": var head = HTTPResponseHead(version: req.version, status: .noContent) head.headers.add(name: "Connection", value: "keep-alive") - ctx.write(data: self.wrapOutboundOut(.head(head))).whenComplete { r in + ctx.write(self.wrapOutboundOut(.head(head))).whenComplete { r in assertSuccess(r) } - ctx.write(data: self.wrapOutboundOut(.end(nil))).whenComplete { r in + ctx.write(self.wrapOutboundOut(.end(nil))).whenComplete { r in assertSuccess(r) self.sentEnd = true self.maybeClose(ctx: ctx) @@ -387,8 +387,8 @@ class HTTPServerClientTest : XCTestCase { var head = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/helloworld") head.headers.add(name: "Host", value: "apple.com") - clientChannel.write(data: NIOAny(HTTPClientRequestPart.head(head)), promise: nil) - try clientChannel.writeAndFlush(data: NIOAny(HTTPClientRequestPart.end(nil))).wait() + clientChannel.write(NIOAny(HTTPClientRequestPart.head(head)), promise: nil) + try clientChannel.writeAndFlush(NIOAny(HTTPClientRequestPart.end(nil))).wait() accumulation.syncWaitForCompletion() } @@ -445,8 +445,8 @@ class HTTPServerClientTest : XCTestCase { var head = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/count-to-ten") head.headers.add(name: "Host", value: "apple.com") - clientChannel.write(data: NIOAny(HTTPClientRequestPart.head(head)), promise: nil) - try clientChannel.writeAndFlush(data: NIOAny(HTTPClientRequestPart.end(nil))).wait() + clientChannel.write(NIOAny(HTTPClientRequestPart.head(head)), promise: nil) + try clientChannel.writeAndFlush(NIOAny(HTTPClientRequestPart.end(nil))).wait() accumulation.syncWaitForCompletion() } @@ -503,8 +503,8 @@ class HTTPServerClientTest : XCTestCase { var head = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/trailers") head.headers.add(name: "Host", value: "apple.com") - clientChannel.write(data: NIOAny(HTTPClientRequestPart.head(head)), promise: nil) - try clientChannel.writeAndFlush(data: NIOAny(HTTPClientRequestPart.end(nil))).wait() + clientChannel.write(NIOAny(HTTPClientRequestPart.head(head)), promise: nil) + try clientChannel.writeAndFlush(NIOAny(HTTPClientRequestPart.end(nil))).wait() accumulation.syncWaitForCompletion() } @@ -560,7 +560,7 @@ class HTTPServerClientTest : XCTestCase { var buffer = clientChannel.allocator.buffer(capacity: numBytes) buffer.write(staticString: "GET /massive-response HTTP/1.1\r\nHost: nio.net\r\n\r\n") - try clientChannel.writeAndFlush(data: NIOAny(buffer)).wait() + try clientChannel.writeAndFlush(NIOAny(buffer)).wait() accumulation.syncWaitForCompletion() } @@ -604,8 +604,8 @@ class HTTPServerClientTest : XCTestCase { var head = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .HEAD, uri: "/head") head.headers.add(name: "Host", value: "apple.com") - clientChannel.write(data: NIOAny(HTTPClientRequestPart.head(head)), promise: nil) - try clientChannel.writeAndFlush(data: NIOAny(HTTPClientRequestPart.end(nil))).wait() + clientChannel.write(NIOAny(HTTPClientRequestPart.head(head)), promise: nil) + try clientChannel.writeAndFlush(NIOAny(HTTPClientRequestPart.end(nil))).wait() accumulation.syncWaitForCompletion() } @@ -649,8 +649,8 @@ class HTTPServerClientTest : XCTestCase { var head = HTTPRequestHead(version: HTTPVersion(major: 1, minor: 1), method: .GET, uri: "/204") head.headers.add(name: "Host", value: "apple.com") - clientChannel.write(data: NIOAny(HTTPClientRequestPart.head(head)), promise: nil) - try clientChannel.writeAndFlush(data: NIOAny(HTTPClientRequestPart.end(nil))).wait() + clientChannel.write(NIOAny(HTTPClientRequestPart.head(head)), promise: nil) + try clientChannel.writeAndFlush(NIOAny(HTTPClientRequestPart.end(nil))).wait() accumulation.syncWaitForCompletion() } diff --git a/Tests/NIOHTTP1Tests/HTTPTest.swift b/Tests/NIOHTTP1Tests/HTTPTest.swift index 509ceb5dd..5c9f3b9c2 100644 --- a/Tests/NIOHTTP1Tests/HTTPTest.swift +++ b/Tests/NIOHTTP1Tests/HTTPTest.swift @@ -27,7 +27,7 @@ private final class TestChannelInboundHandler: ChannelInboundHandler { } public func channelRead(ctx: ChannelHandlerContext, data: NIOAny) { - ctx.fireChannelRead(data: self.wrapInboundOut(self.fn(self.unwrapInboundIn(data)))) + ctx.fireChannelRead(self.wrapInboundOut(self.fn(self.unwrapInboundIn(data)))) } } @@ -131,7 +131,7 @@ class HTTPTest: XCTestCase { let bd1 = try sendAndCheckRequests(expecteds, body: body, trailers: trailers, sendStrategy: { (reqString, chan) in var buf = chan.allocator.buffer(capacity: 1024) buf.write(string: reqString) - try chan.writeInbound(data: buf) + try chan.writeInbound(buf) }) /* send the bytes one by one */ @@ -140,7 +140,7 @@ class HTTPTest: XCTestCase { var buf = chan.allocator.buffer(capacity: 1024) buf.write(string: "\(c)") - try chan.writeInbound(data: buf) + try chan.writeInbound(buf) } }) diff --git a/Tests/NIOHTTP1Tests/HTTPUpgradeTests.swift b/Tests/NIOHTTP1Tests/HTTPUpgradeTests.swift index d56bc795b..287b18bc7 100644 --- a/Tests/NIOHTTP1Tests/HTTPUpgradeTests.swift +++ b/Tests/NIOHTTP1Tests/HTTPUpgradeTests.swift @@ -147,7 +147,7 @@ private class UserEventSaver: ChannelInboundHandler { public func userInboundEventTriggered(ctx: ChannelHandlerContext, event: Any) { events.append(event as! EventType) - ctx.fireUserInboundEventTriggered(event: event) + ctx.fireUserInboundEventTriggered(event) } } @@ -158,7 +158,7 @@ private class ErrorSaver: ChannelInboundHandler { public func errorCaught(ctx: ChannelHandlerContext, error: Error) { errors.append(error) - ctx.fireErrorCaught(error: error) + ctx.fireErrorCaught(error) } } @@ -183,7 +183,7 @@ class HTTPUpgradeTestCase: XCTestCase { } let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\n\r\n" - XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) + XCTAssertNoThrow(try client.writeAndFlush(NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -202,7 +202,7 @@ class HTTPUpgradeTestCase: XCTestCase { // This request fires a subsequent upgrade in immediately. It should also be ignored. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\n\r\nOPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nConnection: upgrade\r\n\r\n" - XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) + XCTAssertNoThrow(try client.writeAndFlush(NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -222,7 +222,7 @@ class HTTPUpgradeTestCase: XCTestCase { XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait()) do { - try channel.writeInbound(data: data) + try channel.writeInbound(data) XCTFail("Writing of bad data did not error") } catch HTTPUpgradeErrors.invalidHTTPOrdering { // Nothing to see here. @@ -271,7 +271,7 @@ class HTTPUpgradeTestCase: XCTestCase { // This request is safe to upgrade. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nKafkaesque: yup\r\nConnection: upgrade\r\nConnection: kafkaesque\r\n\r\n" - XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) + XCTAssertNoThrow(try client.writeAndFlush(NIOAny(ByteBuffer.forString(request))).wait()) // Let the machinery do its thing. XCTAssertNoThrow(try completePromise.futureResult.wait()) @@ -297,7 +297,7 @@ class HTTPUpgradeTestCase: XCTestCase { } let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nConnection: upgrade\r\nUpgrade: myproto\r\n\r\n" - XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) + XCTAssertNoThrow(try client.writeAndFlush(NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -315,7 +315,7 @@ class HTTPUpgradeTestCase: XCTestCase { } let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nConnection: upgrade\r\nUpgrade: myproto\r\nKafkaesque: true\r\n\r\n" - XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) + XCTAssertNoThrow(try client.writeAndFlush(NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -333,7 +333,7 @@ class HTTPUpgradeTestCase: XCTestCase { } let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nConnection: upgrade\r\nUpgrade: something-else\r\n\r\n" - XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) + XCTAssertNoThrow(try client.writeAndFlush(NIOAny(ByteBuffer.forString(request))).wait()) // At this time the channel pipeline should not contain our handler: it should have removed itself. try client.pipeline.assertDoesNotContain(handler: handler) @@ -376,7 +376,7 @@ class HTTPUpgradeTestCase: XCTestCase { // This request is safe to upgrade. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto, exploder\r\nKafkaesque: yup\r\nConnection: upgrade, kafkaesque\r\n\r\n" - XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) + XCTAssertNoThrow(try client.writeAndFlush(NIOAny(ByteBuffer.forString(request))).wait()) // Let the machinery do its thing. XCTAssertNoThrow(try completePromise.futureResult.wait()) @@ -420,7 +420,7 @@ class HTTPUpgradeTestCase: XCTestCase { // This request is safe to upgrade. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: myproto\r\nKafkaesque: yup\r\nConnection: upgrade,kafkaesque\r\n\r\n" - XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) + XCTAssertNoThrow(try client.writeAndFlush(NIOAny(ByteBuffer.forString(request))).wait()) // Let the machinery do its thing. XCTAssertNoThrow(try completePromise.futureResult.wait()) @@ -481,7 +481,7 @@ class HTTPUpgradeTestCase: XCTestCase { // This request is safe to upgrade. let request = "OPTIONS * HTTP/1.1\r\nHost: localhost\r\nUpgrade: noproto,myproto\r\nKafkaesque: yup\r\nConnection: upgrade, kafkaesque\r\n\r\n" - XCTAssertNoThrow(try client.writeAndFlush(data: NIOAny(ByteBuffer.forString(request))).wait()) + XCTAssertNoThrow(try client.writeAndFlush(NIOAny(ByteBuffer.forString(request))).wait()) // Let the machinery do its thing. XCTAssertNoThrow(try completePromise.futureResult.wait()) diff --git a/Tests/NIOTLSTests/ApplicationProtocolNegotiationHandlerTests.swift b/Tests/NIOTLSTests/ApplicationProtocolNegotiationHandlerTests.swift index bed44f939..315a4e8fd 100644 --- a/Tests/NIOTLSTests/ApplicationProtocolNegotiationHandlerTests.swift +++ b/Tests/NIOTLSTests/ApplicationProtocolNegotiationHandlerTests.swift @@ -46,8 +46,8 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase { try channel.pipeline.add(handler: handler).wait() // Fire a pair of events that should be ignored. - channel.pipeline.fireUserInboundEventTriggered(event: EventType.basic) - channel.pipeline.fireUserInboundEventTriggered(event: TLSUserEvent.shutdownCompleted) + channel.pipeline.fireUserInboundEventTriggered(EventType.basic) + channel.pipeline.fireUserInboundEventTriggered(TLSUserEvent.shutdownCompleted) // The channel handler should still be in the pipeline. try channel.pipeline.assertContains(handler: handler) @@ -72,7 +72,7 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase { try channel.pipeline.add(handler: handler).wait() // Fire the handshake complete event. - channel.pipeline.fireUserInboundEventTriggered(event: TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2")) + channel.pipeline.fireUserInboundEventTriggered(TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2")) // At this time the callback should have fired, but the handler should still be in // the pipeline. @@ -108,7 +108,7 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase { try channel.pipeline.add(handler: handler).wait() // The data we write should not be buffered. - try channel.writeInbound(data: "hello") + try channel.writeInbound("hello") XCTAssertEqual(channel.readInbound()!, "hello") XCTAssertFalse(try channel.finish()) @@ -126,12 +126,12 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase { try channel.pipeline.add(handler: handler).wait() // Fire in the event. - channel.pipeline.fireUserInboundEventTriggered(event: TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2")) + channel.pipeline.fireUserInboundEventTriggered(TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2")) // At this point all writes should be buffered. - try channel.writeInbound(data: "writes") - try channel.writeInbound(data: "are") - try channel.writeInbound(data: "buffered") + try channel.writeInbound("writes") + try channel.writeInbound("are") + try channel.writeInbound("buffered") XCTAssertNil(channel.readInbound()) // Complete the pipeline swap. @@ -159,7 +159,7 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase { try channel.pipeline.add(handler: readCompleteHandler).wait() // Fire in the event. - channel.pipeline.fireUserInboundEventTriggered(event: TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2")) + channel.pipeline.fireUserInboundEventTriggered(TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2")) // At this time, readComplete hasn't fired. XCTAssertEqual(readCompleteHandler.readCompleteCount, 0) @@ -186,10 +186,10 @@ class ApplicationProtocolNegotiationHandlerTests: XCTestCase { try channel.pipeline.add(handler: readCompleteHandler).wait() // Fire in the event. - channel.pipeline.fireUserInboundEventTriggered(event: TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2")) + channel.pipeline.fireUserInboundEventTriggered(TLSUserEvent.handshakeCompleted(negotiatedProtocol: "h2")) // Send a write, which is buffered. - try channel.writeInbound(data: "a write") + try channel.writeInbound("a write") // At this time, readComplete hasn't fired. XCTAssertEqual(readCompleteHandler.readCompleteCount, 1) diff --git a/Tests/NIOTLSTests/SNIHandlerTests.swift b/Tests/NIOTLSTests/SNIHandlerTests.swift index f1eb3efde..6ba70b430 100644 --- a/Tests/NIOTLSTests/SNIHandlerTests.swift +++ b/Tests/NIOTLSTests/SNIHandlerTests.swift @@ -277,7 +277,7 @@ class SniHandlerTest: XCTestCase { // forward on any data. while buffer.readableBytes > 0 { let writeableData = buffer.readSlice(length: 1)! - try channel.writeInbound(data: writeableData) + try channel.writeInbound(writeableData) loop.run() XCTAssertNil(channel.readInbound()) @@ -323,7 +323,7 @@ class SniHandlerTest: XCTestCase { try channel.pipeline.add(handler: handler).wait() // Ok, let's go. - try channel.writeInbound(data: buffer) + try channel.writeInbound(buffer) loop.run() // The callback should have fired, but the handler should not have @@ -363,7 +363,7 @@ class SniHandlerTest: XCTestCase { try channel.pipeline.add(handler: handler).wait() // Ok, let's go. - try channel.writeInbound(data: buffer) + try channel.writeInbound(buffer) loop.run() // The callback should not have fired, the handler should still be in the pipeline, diff --git a/Tests/NIOTests/ChannelPipelineTest.swift b/Tests/NIOTests/ChannelPipelineTest.swift index 1047b84a9..20a354bff 100644 --- a/Tests/NIOTests/ChannelPipelineTest.swift +++ b/Tests/NIOTests/ChannelPipelineTest.swift @@ -68,7 +68,7 @@ class ChannelPipelineTest: XCTestCase { return 1 }).wait() - _ = channel.write(data: NIOAny("msg")) + _ = channel.write(NIOAny("msg")) _ = try channel.flush().wait() if let data = channel.readOutbound() { XCTAssertEqual(IOData.byteBuffer(buf), data) @@ -109,7 +109,7 @@ class ChannelPipelineTest: XCTestCase { public func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise?) { do { - ctx.write(data: self.wrapOutboundOut(try fn(self.unwrapOutboundIn(data))), promise: promise) + ctx.write(self.wrapOutboundOut(try fn(self.unwrapOutboundIn(data))), promise: promise) } catch let err { promise!.fail(error: err) } @@ -134,7 +134,7 @@ class ChannelPipelineTest: XCTestCase { typealias InboundOut = Int public func handlerRemoved(ctx: ChannelHandlerContext) { - ctx.fireChannelRead(data: self.wrapInboundOut(1)) + ctx.fireChannelRead(self.wrapInboundOut(1)) } } @@ -152,7 +152,7 @@ class ChannelPipelineTest: XCTestCase { func testEmptyPipelineWorks() throws { let channel = EmbeddedChannel() - try channel.writeInbound(data: 2) + try channel.writeInbound(2) XCTAssertEqual(Optional.some(2), channel.readInbound()) XCTAssertFalse(try channel.finish()) } @@ -166,7 +166,7 @@ class ChannelPipelineTest: XCTestCase { XCTAssertTrue(loop.inEventLoop) do { - try channel.writeOutbound(data: FileRegion(descriptor: -1, readerIndex: 0, endIndex: 0)) + try channel.writeOutbound(FileRegion(descriptor: -1, readerIndex: 0, endIndex: 0)) loop.run() XCTFail("we ran but an error should have been thrown") } catch let err as ChannelError { @@ -188,7 +188,7 @@ class ChannelPipelineTest: XCTestCase { func channelRead(ctx: ChannelHandlerContext, data: NIOAny) { let data = self.unwrapInboundIn(data) - ctx.fireChannelRead(data: self.wrapInboundOut(data + [self.no])) + ctx.fireChannelRead(self.wrapInboundOut(data + [self.no])) } } @@ -205,7 +205,7 @@ class ChannelPipelineTest: XCTestCase { func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise?) { let data = self.unwrapOutboundIn(data) - ctx.write(data: self.wrapOutboundOut(data + [self.no]), promise: promise) + ctx.write(self.wrapOutboundOut(data + [self.no]), promise: promise) } } @@ -217,8 +217,8 @@ class ChannelPipelineTest: XCTestCase { func channelRead(ctx: ChannelHandlerContext, data: NIOAny) { let data = self.unwrapInboundIn(data) - ctx.write(data: self.wrapOutboundOut(data.map { $0 * -1 }), promise: nil) - ctx.fireChannelRead(data: self.wrapInboundOut(data)) + ctx.write(self.wrapOutboundOut(data.map { $0 * -1 }), promise: nil) + ctx.fireChannelRead(self.wrapInboundOut(data)) } } @@ -231,7 +231,7 @@ class ChannelPipelineTest: XCTestCase { let data = self.unwrapOutboundIn(data) var buf = ctx.channel.allocator.buffer(capacity: 123) buf.write(string: String(describing: data)) - ctx.write(data: self.wrapOutboundOut(buf), promise: promise) + ctx.write(self.wrapOutboundOut(buf), promise: promise) } } @@ -247,7 +247,7 @@ class ChannelPipelineTest: XCTestCase { try channel.pipeline.add(handler: MarkingInboundHandler(number: 6)).wait() try channel.pipeline.add(handler: WriteOnReadHandler()).wait() - try channel.writeInbound(data: []) + try channel.writeInbound([]) loop.run() XCTAssertEqual([2, 6], channel.readInbound()!) diff --git a/Tests/NIOTests/ChannelTests.swift b/Tests/NIOTests/ChannelTests.swift index a53664f79..c62ce7317 100644 --- a/Tests/NIOTests/ChannelTests.swift +++ b/Tests/NIOTests/ChannelTests.swift @@ -89,7 +89,7 @@ public class ChannelTests: XCTestCase { var buffer = clientChannel.allocator.buffer(capacity: 1) buffer.write(string: "a") - try clientChannel.writeAndFlush(data: NIOAny(buffer)).wait() + try clientChannel.writeAndFlush(NIOAny(buffer)).wait() // Start shutting stuff down. try clientChannel.close().wait() @@ -121,7 +121,7 @@ public class ChannelTests: XCTestCase { for _ in 0...Socket.writevLimitIOVectors { var buffer = clientChannel.allocator.buffer(capacity: 1) buffer.write(string: "a") - clientChannel.write(data: NIOAny(buffer), promise: nil) + clientChannel.write(NIOAny(buffer), promise: nil) } try clientChannel.flush().wait() @@ -150,7 +150,7 @@ public class ChannelTests: XCTestCase { var written = 0 while written <= Int(INT32_MAX) { - clientChannel.write(data: NIOAny(buffer), promise: nil) + clientChannel.write(NIOAny(buffer), promise: nil) written += bufferSize } @@ -1088,11 +1088,11 @@ public class ChannelTests: XCTestCase { var buffer = channel.allocator.buffer(capacity: 12) buffer.write(string: "1234") - try channel.writeAndFlush(data: NIOAny(buffer)).wait() + try channel.writeAndFlush(NIOAny(buffer)).wait() try channel.close(mode: .output).wait() do { - try channel.writeAndFlush(data: NIOAny(buffer)).wait() + try channel.writeAndFlush(NIOAny(buffer)).wait() XCTFail() } catch let err as ChannelError { XCTAssertEqual(ChannelError.outputClosed, err) @@ -1212,7 +1212,7 @@ public class ChannelTests: XCTestCase { var buffer = channel.allocator.buffer(capacity: 12) buffer.write(string: "1234") - try channel.writeAndFlush(data: NIOAny(buffer)).wait() + try channel.writeAndFlush(NIOAny(buffer)).wait() } private class ShutdownVerificationHandler: ChannelInboundHandler { @@ -1243,7 +1243,7 @@ public class ChannelTests: XCTestCase { fallthrough default: - ctx.fireUserInboundEventTriggered(event: event) + ctx.fireUserInboundEventTriggered(event) } } @@ -1267,7 +1267,7 @@ public class ChannelTests: XCTestCase { .connect(to: serverChannel.localAddress!).wait() do { - try clientChannel.writeAndFlush(data: NIOAny(5)).wait() + try clientChannel.writeAndFlush(NIOAny(5)).wait() XCTFail("Did not throw") } catch ChannelError.writeDataUnsupported { // All good @@ -1328,7 +1328,7 @@ public class ChannelTests: XCTestCase { try pipeline.eventLoop.submit { () -> Channel in XCTAssertTrue(pipeline.channel is DeadChannel) return pipeline.channel - }.wait().write(data: NIOAny(())).wait() + }.wait().write(NIOAny(())).wait() XCTFail("shouldn't have been reached") } catch let e as ChannelError where e == .ioOnClosedChannel { // OK diff --git a/Tests/NIOTests/CodecTest.swift b/Tests/NIOTests/CodecTest.swift index 92c98160c..97d9cb65e 100644 --- a/Tests/NIOTests/CodecTest.swift +++ b/Tests/NIOTests/CodecTest.swift @@ -42,7 +42,7 @@ public class ByteToMessageDecoderTest: XCTestCase { guard buffer.readableBytes >= MemoryLayout.size else { return false } - ctx.fireChannelRead(data: self.wrapInboundOut(buffer.readInteger()!)) + ctx.fireChannelRead(self.wrapInboundOut(buffer.readInteger()!)) return true } } @@ -57,15 +57,15 @@ public class ByteToMessageDecoderTest: XCTestCase { let writerIndex = buffer.writerIndex buffer.moveWriterIndex(to: writerIndex - 1) - channel.pipeline.fireChannelRead(data: NIOAny(buffer)) + channel.pipeline.fireChannelRead(NIOAny(buffer)) XCTAssertNil(channel.readInbound()) - channel.pipeline.fireChannelRead(data: NIOAny(buffer.getSlice(at: writerIndex - 1, length: 1)!)) + channel.pipeline.fireChannelRead(NIOAny(buffer.getSlice(at: writerIndex - 1, length: 1)!)) var buffer2 = channel.allocator.buffer(capacity: 32) buffer2.write(integer: Int32(2)) buffer2.write(integer: Int32(3)) - channel.pipeline.fireChannelRead(data: NIOAny(buffer2)) + channel.pipeline.fireChannelRead(NIOAny(buffer2)) XCTAssertNoThrow(try channel.finish()) @@ -86,7 +86,7 @@ public class ByteToMessageDecoderTest: XCTestCase { var buffer = channel.allocator.buffer(capacity: 32) buffer.write(integer: Int32(1)) - channel.pipeline.fireChannelRead(data: NIOAny(buffer)) + channel.pipeline.fireChannelRead(NIOAny(buffer)) XCTAssertEqual(Int32(1), channel.readInbound()) XCTAssertFalse(inactivePromiser.channelInactivePromise.futureResult.fulfilled) @@ -135,7 +135,7 @@ public class MessageToByteEncoderTest: XCTestCase { _ = try channel.pipeline.add(handler: Int32ToByteEncoder()).wait() - _ = try channel.writeAndFlush(data: NIOAny(Int32(5))).wait() + _ = try channel.writeAndFlush(NIOAny(Int32(5))).wait() if case .some(.byteBuffer(var buffer)) = channel.readOutbound() { XCTAssertEqual(Int32(5), buffer.readInteger()) diff --git a/Tests/NIOTests/EchoServerClientTest.swift b/Tests/NIOTests/EchoServerClientTest.swift index b24dfb656..194998189 100644 --- a/Tests/NIOTests/EchoServerClientTest.swift +++ b/Tests/NIOTests/EchoServerClientTest.swift @@ -67,7 +67,7 @@ class EchoServerClientTest : XCTestCase { buffer.write(integer: UInt8(i % 256)) } - try clientChannel.writeAndFlush(data: NIOAny(buffer)).wait() + try clientChannel.writeAndFlush(NIOAny(buffer)).wait() try countingHandler.assertReceived(buffer: buffer) } @@ -143,7 +143,7 @@ class EchoServerClientTest : XCTestCase { buffer.write(integer: UInt8(i % 256)) } - try clientChannel.writeAndFlush(data: NIOAny(buffer)).wait() + try clientChannel.writeAndFlush(NIOAny(buffer)).wait() try countingHandler.assertReceived(buffer: buffer) } @@ -186,7 +186,7 @@ class EchoServerClientTest : XCTestCase { buffer.write(integer: UInt8(i % 256)) } - try clientChannel.writeAndFlush(data: NIOAny(buffer)).wait() + try clientChannel.writeAndFlush(NIOAny(buffer)).wait() try countingHandler.assertReceived(buffer: buffer) } @@ -247,7 +247,7 @@ class EchoServerClientTest : XCTestCase { for i in 0..] = [] for _ in 0..<10 { - futures.append(clientChannel.write(data: NIOAny(fr))) + futures.append(clientChannel.write(NIOAny(fr))) } - try clientChannel.writeAndFlush(data: NIOAny(fr)).wait() + try clientChannel.writeAndFlush(NIOAny(fr)).wait() try futures.forEach { try $0.wait() } } } @@ -138,11 +138,11 @@ class FileRegionTest : XCTestCase { } try content.write(toFile: filePath, atomically: false, encoding: .ascii) do { - () = try clientChannel.writeAndFlush(data: NIOAny(fr1)).then { - let frFuture = clientChannel.write(data: NIOAny(fr2)) + () = try clientChannel.writeAndFlush(NIOAny(fr1)).then { + let frFuture = clientChannel.write(NIOAny(fr2)) var buffer = clientChannel.allocator.buffer(capacity: bytes.count) buffer.write(bytes: bytes) - let bbFuture = clientChannel.write(data: NIOAny(buffer)) + let bbFuture = clientChannel.write(NIOAny(buffer)) clientChannel.close(promise: nil) clientChannel.flush(promise: nil) return frFuture.then { bbFuture } diff --git a/Tests/NIOTests/IdleStateHandlerTest.swift b/Tests/NIOTests/IdleStateHandlerTest.swift index e27bbecc9..7434d9a3b 100644 --- a/Tests/NIOTests/IdleStateHandlerTest.swift +++ b/Tests/NIOTests/IdleStateHandlerTest.swift @@ -69,7 +69,7 @@ class IdleStateHandlerTest : XCTestCase { if writeToChannel { var buffer = ctx.channel.allocator.buffer(capacity: 4) buffer.write(staticString: "test") - ctx.writeAndFlush(data: self.wrapOutboundOut(buffer), promise: nil) + ctx.writeAndFlush(self.wrapOutboundOut(buffer), promise: nil) } } } @@ -90,7 +90,7 @@ class IdleStateHandlerTest : XCTestCase { if !writeToChannel { var buffer = clientChannel.allocator.buffer(capacity: 4) buffer.write(staticString: "test") - try clientChannel.writeAndFlush(data: NIOAny(buffer)).wait() + try clientChannel.writeAndFlush(NIOAny(buffer)).wait() } try clientChannel.closeFuture.wait() }