Skip to content

Commit

Permalink
Add ChannelCore.removeHandlers. (#408)
Browse files Browse the repository at this point in the history
Motivation:

If ChannelPipeline.removeHandlers is internal it is extremely difficult
to implement a correct ChannelCore. For that reason, we should make it
available as an extension on ChannelCore.

This is a minor layering violation, but that's ok: ChannelCore and
Channel are not actually intended to be separate objects in most cases,
they are just separate for code clarity reasons.

Modifications:

Add ChannelCore.removeHandlers as a public method.

Result:

Easier to implement ChannelCore.
  • Loading branch information
Lukasa authored and normanmaurer committed May 18, 2018
1 parent cea8476 commit bad7c29
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Sources/NIO/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ public extension ChannelCore {
public func unwrapData<T>(_ data: NIOAny, as: T.Type = T.self) -> T {
return data.forceAs()
}

/// Removes the `ChannelHandler`s from the `ChannelPipeline` belonging to `channel`, 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:
/// - channel: The `Channel` whose `ChannelPipeline` will be closed.
public func removeHandlers(channel: Channel) {
channel.pipeline.removeHandlers()
}
}

/// An error that can occur on `Channel` operations.
Expand Down
5 changes: 4 additions & 1 deletion Sources/NIO/ChannelPipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,10 @@ public final class ChannelPipeline: ChannelInvoker {
return name
}

/// Remove all the `ChannelHandler`s from the `ChannelPipeline` and destroy these. This method must only be called from within the `EventLoop`.
/// Remove all the `ChannelHandler`s from the `ChannelPipeline` and destroy these.
///
/// This method must only be called from within the `EventLoop`. It should only be called from a `ChannelCore`
/// implementation. Once called, the `ChannelPipeline` is no longer active and cannot be used again.
func removeHandlers() {
assert(eventLoop.inEventLoop)

Expand Down

0 comments on commit bad7c29

Please sign in to comment.