mirror of
https://github.com/apple/swift-nio
synced 2026-11-30 05:28:44 +00:00
better ChannelHandler removal API (#767)
Motivation: If ChannelHandler removal worked correctly, it was often either by accident or by intricate knowledge about the implementation of the ChannelHandler that is to be removed. Especially when it comes to re-entrancy it mostly didn't work correctly. Modifications: - introduce a `RemovableChannelHandler` API - raise allocation limit per HTTP connection by 1 (https://bugs.swift.org/browse/SR-9905) Result: Make things work by contruction rather than accident
This commit is contained in:
1 parent
2738b6d54f
commit
d938264fcb
22 files changed
+334
-62
No files matched your search
@@ -16,7 +16,7 @@ import XCTest
|
||||
import NIO
|
||||
import NIOWebSocket
|
||||
|
||||
private class CloseSwallower: ChannelOutboundHandler {
|
||||
private class CloseSwallower: ChannelOutboundHandler, RemovableChannelHandler {
|
||||
typealias OutboundIn = Any
|
||||
typealias OutboundOut = Any
|
||||
|
||||
@@ -103,9 +103,15 @@ public class WebSocketFrameDecoderTest: XCTestCase {
|
||||
private func swapDecoder(for handler: ChannelHandler) {
|
||||
// We need to insert a decoder that doesn't do error handling. We still insert
|
||||
// an encoder because we want to fail gracefully if a frame is written.
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.context(handlerType: ByteToMessageHandler<WebSocketFrameDecoder>.self).flatMap {
|
||||
self.decoderChannel.pipeline.remove(handler: $0.handler)
|
||||
}.flatMap { (_: Bool) in
|
||||
XCTAssertNoThrow(try self.decoderChannel.pipeline.context(handlerType: ByteToMessageHandler<WebSocketFrameDecoder>.self).flatMapThrowing {
|
||||
if let handler = $0.handler as? RemovableChannelHandler {
|
||||
return handler
|
||||
} else {
|
||||
throw ChannelError.unremovableHandler
|
||||
}
|
||||
}.flatMap {
|
||||
self.decoderChannel.pipeline.remove(handler: $0)
|
||||
}.flatMap {
|
||||
self.decoderChannel.pipeline.add(handler: handler)
|
||||
}.wait())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user