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
This commit is contained in:
Johannes Weiss committed 2018-02-13 11:13:30 +00:00
1 parent dba0a5379c
commit eaa8ffaee4
35 files changed
+335 -335

No files matched your search

+5 -5
View File
@@ -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)
}
}
}
+13 -13
View File
@@ -21,12 +21,12 @@ public protocol ChannelCore : class {
func register0(promise: EventLoopPromise<Void>?)
func bind0(to: SocketAddress, promise: EventLoopPromise<Void>?)
func connect0(to: SocketAddress, promise: EventLoopPromise<Void>?)
func write0(data: NIOAny, promise: EventLoopPromise<Void>?)
func write0(_ data: NIOAny, promise: EventLoopPromise<Void>?)
func flush0(promise: EventLoopPromise<Void>?)
func read0(promise: EventLoopPromise<Void>?)
func close0(error: Error, mode: CloseMode, promise: EventLoopPromise<Void>?)
func triggerUserOutboundEvent0(event: Any, promise: EventLoopPromise<Void>?)
func channelRead0(data: NIOAny)
func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise<Void>?)
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<Void>?) {
pipeline.write(data: data, promise: promise)
public func write(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
pipeline.write(data, promise: promise)
}
public func flush(promise: EventLoopPromise<Void>?) {
pipeline.flush(promise: promise)
}
public func writeAndFlush(data: NIOAny, promise: EventLoopPromise<Void>?) {
pipeline.writeAndFlush(data: data, promise: promise)
public func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
pipeline.writeAndFlush(data, promise: promise)
}
public func read(promise: EventLoopPromise<Void>?) {
@@ -147,8 +147,8 @@ extension Channel {
pipeline.register(promise: promise)
}
public func triggerUserOutboundEvent(event: Any, promise: EventLoopPromise<Void>?) {
pipeline.triggerUserOutboundEvent(event: event, promise: promise)
public func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise<Void>?) {
pipeline.triggerUserOutboundEvent(event, promise: promise)
}
}
@@ -160,21 +160,21 @@ public extension Channel {
///
/// - seealso: `ChannelOutboundInvoker.write`.
public func write<T>(_ any: T) -> EventLoopFuture<Void> {
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<T>(_ any: T, promise: EventLoopPromise<Void>?) {
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<T>(_ any: T) -> EventLoopFuture<Void> {
return self.writeAndFlush(data: NIOAny(any))
return self.writeAndFlush(NIOAny(any))
}
@@ -182,7 +182,7 @@ public extension Channel {
///
/// - seealso: `ChannelOutboundInvoker.writeAndFlush`.
public func writeAndFlush<T>(_ any: T, promise: EventLoopPromise<Void>?) {
self.writeAndFlush(data: NIOAny(any), promise: promise)
self.writeAndFlush(NIOAny(any), promise: promise)
}
}
+5 -5
View File
@@ -68,7 +68,7 @@ extension _ChannelOutboundHandler {
}
public func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
ctx.write(data: data, promise: promise)
ctx.write(data, promise: promise)
}
public func flush(ctx: ChannelHandlerContext, promise: EventLoopPromise<Void>?) {
@@ -84,7 +84,7 @@ extension _ChannelOutboundHandler {
}
public func triggerUserOutboundEvent(ctx: ChannelHandlerContext, event: Any, promise: EventLoopPromise<Void>?) {
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)
}
}
+6 -6
View File
@@ -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<Void>?) {
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))
+15 -15
View File
@@ -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<Void>
func write(_ data: NIOAny) -> EventLoopFuture<Void>
/// 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<Void>?)
func write(_ data: NIOAny, promise: EventLoopPromise<Void>?)
/// 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<Void>
func writeAndFlush(_ data: NIOAny) -> EventLoopFuture<Void>
/// 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<Void>?)
func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?)
/// 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<Void>
func triggerUserOutboundEvent(_ event: Any) -> EventLoopFuture<Void>
/// 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<Void>?)
func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise<Void>?)
/// 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<Void> {
public func write(_ data: NIOAny) -> EventLoopFuture<Void> {
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<Void> {
public func writeAndFlush(_ data: NIOAny) -> EventLoopFuture<Void> {
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<Void> {
public func triggerUserOutboundEvent(_ event: Any) -> EventLoopFuture<Void> {
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.
+63 -63
View File
@@ -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<Void>?) {
public func write(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
public func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
public func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise<Void>?) {
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<Void>?) {
func write0(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
func writeAndFlush0(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise<Void>?) {
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<Void>?) {
ctx.channel._unsafe.write0(data: data, promise: promise)
ctx.channel._unsafe.write0(data, promise: promise)
}
func flush(ctx: ChannelHandlerContext, promise: EventLoopPromise<Void>?) {
@@ -716,7 +716,7 @@ private final class HeadChannelHandler : _ChannelOutboundHandler {
}
func triggerUserOutboundEvent(ctx: ChannelHandlerContext, event: Any, promise: EventLoopPromise<Void>?) {
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<Void>?) {
public func write(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
public func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
public func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise<Void>?) {
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<Void>?) {
fileprivate func invokeWrite(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
fileprivate func invokeWriteAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
fileprivate func invokeTriggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise<Void>?) {
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)
}
}
+2 -2
View File
@@ -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)
}
+3 -3
View File
@@ -28,7 +28,7 @@ private final class DeadChannelCore: ChannelCore {
promise?.fail(error: ChannelError.ioOnClosedChannel)
}
func write0(data: NIOAny, promise: EventLoopPromise<Void>?) {
func write0(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise<Void>?) {
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")
+7 -7
View File
@@ -198,7 +198,7 @@ class EmbeddedChannelCore : ChannelCore {
promise?.succeed(result: ())
}
func write0(data: NIOAny, promise: EventLoopPromise<Void>?) {
func write0(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
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<Void>?) {
public final func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise<Void>?) {
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<T>(data: T) throws -> Bool {
pipeline.fireChannelRead(data: NIOAny(data))
@discardableResult public func writeInbound<T>(_ data: T) throws -> Bool {
pipeline.fireChannelRead(NIOAny(data))
pipeline.fireChannelReadComplete()
try throwIfErrorCaught()
return !channelcore.inboundBuffer.isEmpty
}
@discardableResult public func writeOutbound<T>(data: T) throws -> Bool {
try writeAndFlush(data: NIOAny(data)).wait()
@discardableResult public func writeOutbound<T>(_ data: T) throws -> Bool {
try writeAndFlush(NIOAny(data)).wait()
return !channelcore.outboundBuffer.isEmpty
}
+1 -1
View File
@@ -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 {
+8 -8
View File
@@ -269,7 +269,7 @@ class BaseSocketChannel<T : BaseSocket> : SelectableChannel, ChannelCore {
}
}
public final func write0(data: NIOAny, promise: EventLoopPromise<Void>?) {
public final func write0(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
assert(eventLoop.inEventLoop)
if closed {
@@ -437,7 +437,7 @@ class BaseSocketChannel<T : BaseSocket> : SelectableChannel, ChannelCore {
}
}
public final func triggerUserOutboundEvent0(event: Any, promise: EventLoopPromise<Void>?) {
public final func triggerUserOutboundEvent0(_ event: Any, promise: EventLoopPromise<Void>?) {
promise?.succeed(result: ())
}
@@ -538,7 +538,7 @@ class BaseSocketChannel<T : BaseSocket> : SelectableChannel, ChannelCore {
}
}
public func channelRead0(data: NIOAny) {
public func channelRead0(_ data: NIOAny) {
// Do nothing by default
}
@@ -718,7 +718,7 @@ final class SocketChannel: BaseSocketChannel<Socket> {
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<Socket> {
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<Socket> {
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<ServerSocket> {
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<ServerSocket> {
return
}
override public func channelRead0(data: NIOAny) {
override public func channelRead0(_ data: NIOAny) {
assert(eventLoop.inEventLoop)
let ch = data.forceAsOther() as SocketChannel
+1 -1
View File
@@ -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)
}
}
+1 -1
View File
@@ -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
+8 -8
View File
@@ -195,7 +195,7 @@ public final class HTTPResponseDecoder: HTTPDecoder<HTTPClientResponsePart>, Cha
break
}
ctx.write(data: data, promise: promise)
ctx.write(data, promise: promise)
}
}
@@ -273,13 +273,13 @@ public class HTTPDecoder<HTTPMessageT>: 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<HTTPMessageT>: 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<HTTPMessageT>: 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<HTTPMessageT>: ByteToMessageDecoder, AnyHTTPDecoder {
}
public func errorCaught(ctx: ChannelHandlerContext, error: Error) {
ctx.fireErrorCaught(error: error)
ctx.fireErrorCaught(error)
if error is HTTPParserError {
ctx.close(promise: nil)
}
+7 -7
View File
@@ -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 {
@@ -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<Void>?) {
@@ -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
}
+6 -6
View File
@@ -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<Void> {
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)
}
+37 -37
View File
@@ -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)
}
}
@@ -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 = []
@@ -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")
@@ -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<Void> = 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<Void> = 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()
}
@@ -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{
+27 -27
View File
@@ -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()
}
+3 -3
View File
@@ -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)
}
})
+12 -12
View File
@@ -147,7 +147,7 @@ private class UserEventSaver<EventType>: 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())
@@ -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)
+3 -3
View File
@@ -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,
+11 -11
View File
@@ -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<Void>?) {
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<Int>.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<Void>?) {
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()!)
+9 -9
View File
@@ -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
+6 -6
View File
@@ -42,7 +42,7 @@ public class ByteToMessageDecoderTest: XCTestCase {
guard buffer.readableBytes >= MemoryLayout<Int32>.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())
+20 -20
View File
@@ -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..<numBytes {
buffer.write(integer: UInt8(i % 256))
}
try clientChannel.writeAndFlush(data: NIOAny(buffer)).wait()
try clientChannel.writeAndFlush(NIOAny(buffer)).wait()
try countingHandler.assertReceived(buffer: buffer)
}
@@ -276,7 +276,7 @@ class EchoServerClientTest : XCTestCase {
typealias OutboundOut = ByteBuffer
func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {
ctx.write(data: data, promise: nil)
ctx.write(data, promise: nil)
}
func channelReadComplete(ctx: ChannelHandlerContext) {
@@ -305,7 +305,7 @@ class EchoServerClientTest : XCTestCase {
self.numberOfReads += 1
precondition(self.numberOfReads == 1, "\(self) is only ever allowed to read once")
_ = ctx.eventLoop.scheduleTask(in: self.timeAmount) {
ctx.writeAndFlush(data: data, promise: nil)
ctx.writeAndFlush(data, promise: nil)
self.group.leave()
}.futureResult.whenComplete { res in
switch res {
@@ -316,7 +316,7 @@ class EchoServerClientTest : XCTestCase {
()
}
}
ctx.writeAndFlush(data: data, promise: nil)
ctx.writeAndFlush(data, promise: nil)
}
}
@@ -326,7 +326,7 @@ class EchoServerClientTest : XCTestCase {
func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {
for _ in 0..<10000 {
ctx.write(data: data, promise: nil)
ctx.write(data, promise: nil)
}
}
@@ -409,7 +409,7 @@ class EchoServerClientTest : XCTestCase {
func channelActive(ctx: ChannelHandlerContext) {
var dataToWrite = ctx.channel.allocator.buffer(capacity: toWrite.utf8.count)
dataToWrite.write(string: toWrite)
ctx.writeAndFlush(data: NIOAny(dataToWrite), promise: nil)
ctx.writeAndFlush(NIOAny(dataToWrite), promise: nil)
ctx.fireChannelActive()
}
}
@@ -483,7 +483,7 @@ class EchoServerClientTest : XCTestCase {
// First we confirm that the channel really is up by sending in the appropriate number of bytes.
var bytesToWrite = clientChannel.allocator.buffer(capacity: writingBytes.utf8.count)
bytesToWrite.write(string: writingBytes)
clientChannel.writeAndFlush(data: NIOAny(bytesToWrite), promise: nil)
clientChannel.writeAndFlush(NIOAny(bytesToWrite), promise: nil)
// When we've received all the bytes we know the connection is up.
_ = try bytesReceivedPromise.futureResult.wait()
@@ -591,7 +591,7 @@ class EchoServerClientTest : XCTestCase {
var buffer = clientChannel.allocator.buffer(capacity: str.utf8.count)
buffer.write(string: str)
try clientChannel.writeAndFlush(data: NIOAny(buffer)).wait()
try clientChannel.writeAndFlush(NIOAny(buffer)).wait()
try countingHandler.assertReceived(buffer: buffer)
@@ -625,7 +625,7 @@ class EchoServerClientTest : XCTestCase {
}
private func writeUntilFailed(_ ctx: ChannelHandlerContext, _ buffer: ByteBuffer) {
ctx.writeAndFlush(data: NIOAny(buffer)).whenSuccess { _ in
ctx.writeAndFlush(NIOAny(buffer)).whenSuccess { _ in
ctx.eventLoop.execute {
self.writeUntilFailed(ctx, buffer)
}
@@ -649,14 +649,14 @@ class EchoServerClientTest : XCTestCase {
buffer.write(string: str)
// write it four times and then close the connect.
ctx.writeAndFlush(data: NIOAny(buffer)).then{ _ in
ctx.writeAndFlush(data: NIOAny(buffer)).then{ _ in
ctx.writeAndFlush(data: NIOAny(buffer)).then{ _ in
ctx.writeAndFlush(data: NIOAny(buffer)).then{ _ in
ctx.close()
}
}
}
ctx.writeAndFlush(NIOAny(buffer)).then { () in
ctx.writeAndFlush(NIOAny(buffer))
}.then { () in
ctx.writeAndFlush(NIOAny(buffer))
}.then { () in
ctx.writeAndFlush(NIOAny(buffer))
}.then { () in
ctx.close()
}.whenComplete{ _ in
self.dpGroup.leave()
}
+5 -5
View File
@@ -21,7 +21,7 @@ class EmbeddedChannelTest: XCTestCase {
var buf = channel.allocator.buffer(capacity: 1024)
buf.write(string: "hello")
XCTAssertTrue(try channel.writeOutbound(data: buf))
XCTAssertTrue(try channel.writeOutbound(buf))
XCTAssertTrue(try channel.finish())
XCTAssertEqual(.byteBuffer(buf), channel.readOutbound())
XCTAssertNil(channel.readOutbound())
@@ -33,7 +33,7 @@ class EmbeddedChannelTest: XCTestCase {
var buf = channel.allocator.buffer(capacity: 1024)
buf.write(string: "hello")
XCTAssertTrue(try channel.writeInbound(data: buf))
XCTAssertTrue(try channel.writeInbound(buf))
XCTAssertTrue(try channel.finish())
XCTAssertEqual(buf, channel.readInbound())
XCTAssertNil(channel.readInbound())
@@ -44,7 +44,7 @@ class EmbeddedChannelTest: XCTestCase {
let channel = EmbeddedChannel()
_ = try channel.pipeline.add(handler: ExceptionThrowingInboundHandler()).wait()
do {
try channel.writeInbound(data: "msg")
try channel.writeInbound("msg")
XCTFail()
} catch let err {
XCTAssertEqual(ChannelError.operationUnsupported, err as! ChannelError)
@@ -56,7 +56,7 @@ class EmbeddedChannelTest: XCTestCase {
let channel = EmbeddedChannel()
_ = try channel.pipeline.add(handler: ExceptionThrowingOutboundHandler()).wait()
do {
try channel.writeOutbound(data: "msg")
try channel.writeOutbound("msg")
XCTFail()
} catch let err {
XCTAssertEqual(ChannelError.operationUnsupported, err as! ChannelError)
@@ -145,7 +145,7 @@ class EmbeddedChannelTest: XCTestCase {
let channel = EmbeddedChannel()
do {
try channel.write(data: NIOAny(5)).wait()
try channel.write(NIOAny(5)).wait()
XCTFail("Did not throw")
} catch ChannelError.writeDataUnsupported {
// All good
+1 -1
View File
@@ -113,7 +113,7 @@ public class EventLoopTest : XCTestCase {
buffer.write(integer: UInt8(i % 256))
}
try clientChannel.writeAndFlush(data: NIOAny(buffer)).wait()
try clientChannel.writeAndFlush(NIOAny(buffer)).wait()
}
// We should now shut down gracefully.
+6 -6
View File
@@ -53,7 +53,7 @@ class FileRegionTest : XCTestCase {
XCTAssertNoThrow(try fr.close())
}
try content.write(toFile: filePath, atomically: false, encoding: .ascii)
try clientChannel.writeAndFlush(data: NIOAny(fr)).wait()
try clientChannel.writeAndFlush(NIOAny(fr)).wait()
var buffer = clientChannel.allocator.buffer(capacity: bytes.count)
buffer.write(bytes: bytes)
@@ -92,9 +92,9 @@ class FileRegionTest : XCTestCase {
var futures: [EventLoopFuture<()>] = []
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 }
+2 -2
View File
@@ -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()
}