Create ChannelCore.removeHandlers(pipeline:) and use it (#1916)

Motivation:

A while back we added a ChannelCore extension method that would allow
removing handlers from a channel pipeline, in order to implement
Channels outside of NIO. This extension worked well, but it did assume
that you had a Channel to give it. There's no reason it needed a Channel
instead of just a ChannelPipeline, but it was based on the assumption
that Self would conform to Channel. Of course, this is usually true, but
it turns out not to always be true, and EmbeddedChannel is one example
where the Channel and ChannelCore are separate.

To that end, we shouldn't require using the Channel here, just the
ChannelPipeline. This will also let us force our NIO channels onto the
public API, which will make migrating to NIOCore easier.

Modifications:

- Deprecate ChannelCore.removeHandlers(channel:)
- Implement ChannelCore.removeHandlers(pipeline:)
- Swap existing Channel implementations to use the new method.

Result:

More consistent usage of our APIs.

Co-authored-by: George Barnett <gbarnett@apple.com>
This commit is contained in:
Cory BenfieldandGeorge Barnett authored and GitHub committed 2021-07-26 11:03:43 +01:00
1 parent f9b8f15512
commit dc9edbb976
3 files changed
+17 -3

No files matched your search

+1 -1
View File
@@ -842,7 +842,7 @@ class BaseSocketChannel<SocketType: BaseSocketProtocol>: SelectableChannel, Chan
eventLoop.execute {
// ensure this is executed in a delayed fashion as the users code may still traverse the pipeline
self.pipeline.removeHandlers()
self.removeHandlers(pipeline: self.pipeline)
self.closePromise.succeed(())
+15 -1
View File
@@ -310,8 +310,22 @@ extension ChannelCore {
///
/// - parameters:
/// - channel: The `Channel` whose `ChannelPipeline` will be closed.
@available(*, deprecated, renamed: "removeHandlers(pipeline:)")
public func removeHandlers(channel: Channel) {
channel.pipeline.removeHandlers()
self.removeHandlers(pipeline: channel.pipeline)
}
/// Removes the `ChannelHandler`s from the `ChannelPipeline` `pipeline`, and
/// closes that `ChannelPipeline`.
///
/// This method is intended for use when writing custom `ChannelCore` implementations.
/// This can be called from `close0` to tear down the `ChannelPipeline` when closure is
/// complete.
///
/// - parameters:
/// - pipeline: The `ChannelPipline` to be closed.
public func removeHandlers(pipeline: ChannelPipeline) {
pipeline.removeHandlers()
}
}
+1 -1
View File
@@ -281,7 +281,7 @@ class EmbeddedChannelCore: ChannelCore {
eventLoop.execute {
// ensure this is executed in a delayed fashion as the users code may still traverse the pipeline
self.pipeline.removeHandlers()
self.removeHandlers(pipeline: self.pipeline)
self.closePromise.succeed(())
}
}