Allow to handle user events

This commit is contained in:
Norman Maurer committed 2017-04-30 19:52:41 +02:00
1 parent 5bee1c7bcd
commit cbb414edff
5 files changed
+24

No files matched your search

+5
View File
@@ -21,6 +21,7 @@ public protocol ChannelHandler {
func channelRead(ctx: ChannelHandlerContext, data: Buffer)
func channelReadComplete(ctx: ChannelHandlerContext)
func channelWritabilityChanged(ctx: ChannelHandlerContext, writable: Bool)
func userEventTriggered(ctx: ChannelHandlerContext, event: AnyClass)
func errorCaught(ctx: ChannelHandlerContext, error: Error)
func write(ctx: ChannelHandlerContext, data: Buffer, promise: Promise<Void>)
func flush(ctx: ChannelHandlerContext)
@@ -52,6 +53,10 @@ extension ChannelHandler {
ctx.fireChannelWritabilityChanged(writable: writable)
}
public func userEventTriggered(ctx: ChannelHandlerContext, event: AnyClass) {
ctx.fireUserEventTriggered(event: event)
}
public func errorCaught(ctx: ChannelHandlerContext, error: Error) {
ctx.fireErrorCaught(error: error)
}
+8
View File
@@ -76,6 +76,14 @@ public class ChannelHandlerContext : ChannelInboundInvoker, ChannelOutboundInvok
handler.errorCaught(ctx: self, error: error)
}
public func fireUserEventTriggered(event: AnyClass) {
next!.invokeUserEventTriggered(event: event)
}
func invokeUserEventTriggered(event: AnyClass) {
handler.userEventTriggered(ctx: self, event: event)
}
public func write(data: Buffer, promise: Promise<Void>) -> Future<Void> {
prev!.invokeWrite(data: data, promise: promise)
return promise.futureResult
+2
View File
@@ -27,4 +27,6 @@ public protocol ChannelInboundInvoker {
func fireChannelWritabilityChanged(writable: Bool)
func fireErrorCaught(error: Error)
func fireUserEventTriggered(event: AnyClass)
}
+8
View File
@@ -72,6 +72,10 @@ public class ChannelPipeline : ChannelInboundInvoker, ChannelOutboundInvoker {
head!.fireChannelWritabilityChanged(writable: writable)
}
public func fireUserEventTriggered(event: AnyClass) {
head!.fireUserEventTriggered(event: event)
}
public func fireErrorCaught(error: Error) {
head!.fireErrorCaught(error: error)
}
@@ -138,4 +142,8 @@ class TailChannelHandler : ChannelHandler {
public func channelWritabilityChanged(ctx: ChannelHandlerContext, writable: Bool) {
// Discard
}
public func userEventTriggered(ctx: ChannelHandlerContext, event: AnyClass) {
// Discard
}
}
+1
View File
@@ -24,6 +24,7 @@ import Foundation
#endif
// TODO: Handle AF_INET6 as well
public class ServerSocket: BaseSocket {
public class func bootstrap(host: String, port: Int32) throws -> ServerSocket {