mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
Allow to handle user events
This commit is contained in:
1 parent
5bee1c7bcd
commit
cbb414edff
5 files changed
+24
No files matched your search
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -27,4 +27,6 @@ public protocol ChannelInboundInvoker {
|
||||
func fireChannelWritabilityChanged(writable: Bool)
|
||||
|
||||
func fireErrorCaught(error: Error)
|
||||
|
||||
func fireUserEventTriggered(event: AnyClass)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user