Skip to content

Commit

Permalink
adopt NIOAsyncChannel.Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rnro committed Jul 11, 2023
1 parent 6568b87 commit df3b529
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
.library(name: "NIOHTTP2", targets: ["NIOHTTP2"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.35.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.56.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
Expand Down
18 changes: 3 additions & 15 deletions Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,32 +248,20 @@ extension NIOHTTP2Handler {
///
/// - Parameters:
/// - backpressureStrategy: The backpressure strategy of the ``NIOAsyncChannel`` wrapping the HTTP/2 stream channel.
/// - isOutboundHalfClosureEnabled: If outbound half closure should be enabled for the ``NIOAsyncChannel`` wrapping the HTTP/2 stream channel.
/// - inboundType: The ``NIOAsyncChannel/inboundStream`` message type for the created channel.
/// This type must match the `InboundOut` type of the final handler added to the stream channel by the `initializer`
/// or ``HTTP2Frame/FramePayload`` if there are none.
/// - outboundType: The ``NIOAsyncChannel/outboundWriter`` message type for the created channel.
/// This type must match the `OutboundIn` type of the final handler added to the stream channel by the `initializer`
/// or ``HTTP2Frame/FramePayload`` if there are none.
/// - configuration: Configuration for the ``NIOAsyncChannel`` wrapping the HTTP/2 stream channel.
/// - initializer: A callback that will be invoked to allow you to configure the
/// `ChannelPipeline` for the newly created channel.
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@_spi(AsyncChannel)
public func createStreamChannel<Inbound, Outbound>(
backpressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies.HighLowWatermark? = nil,
isOutboundHalfClosureEnabled: Bool = false,
inboundType: Inbound.Type = Inbound.self,
outboundType: Outbound.Type = Outbound.self,
configuration: NIOAsyncChannel<Inbound, Outbound>.Configuration = .init(),
initializer: @escaping NIOChannelInitializer
) async throws -> NIOAsyncChannel<Inbound, Outbound> {
return try await self.createStreamChannel { channel in
initializer(channel).flatMapThrowing { _ in
return try NIOAsyncChannel(
synchronouslyWrapping: channel,
backpressureStrategy: backpressureStrategy,
isOutboundHalfClosureEnabled: isOutboundHalfClosureEnabled,
inboundType: Inbound.self,
outboundType: Outbound.self
configuration: configuration
)
}
}
Expand Down
33 changes: 3 additions & 30 deletions Sources/NIOHTTP2/HTTP2PipelineHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,7 @@ extension Channel {
return configuration.connectionInitializer(self).flatMapThrowing { _ in
let connectionAsyncChannel = try NIOAsyncChannel<ConnectionInbound, ConnectionOutbound>(
synchronouslyWrapping: self,
backpressureStrategy: configuration.connectionAsyncChannel.backpressureStrategy,
isOutboundHalfClosureEnabled: configuration.connectionAsyncChannel.isOutboundHalfClosureEnabled
configuration: configuration.connectionAsyncChannel
)
return (connectionAsyncChannel, multiplexer)
}
Expand Down Expand Up @@ -755,8 +754,7 @@ extension ChannelPipeline.SynchronousOperations {
inboundStreamInitializer(channel).flatMapThrowing { _ in
return try NIOAsyncChannel<StreamInbound, StreamOutbound>(
synchronouslyWrapping: channel,
backpressureStrategy: inboundStreamAsyncChannelConfiguration.backpressureStrategy,
isOutboundHalfClosureEnabled: inboundStreamAsyncChannelConfiguration.isOutboundHalfClosureEnabled
configuration: inboundStreamAsyncChannelConfiguration
)
}
}
Expand Down Expand Up @@ -810,30 +808,5 @@ public struct NIOHTTP2AsyncConfiguration<HTTP2ConnectionInbound: Sendable, HTTP2
#if swift(>=5.7)
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@_spi(AsyncChannel)
extension NIOHTTP2AsyncConfiguration: Sendable {}
extension NIOHTTP2AsyncConfiguration: @unchecked Sendable {}
#endif

// TODO: remove. This is a placeholder for the upcoming native type
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension NIOAsyncChannel {
@_spi(AsyncChannel)
public struct Configuration: Sendable{
let inboundType: Inbound.Type
let outboundType: Outbound.Type
let backpressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies.HighLowWatermark?
let isOutboundHalfClosureEnabled: Bool

public init(
backpressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies.HighLowWatermark? = nil,
isOutboundHalfClosureEnabled: Bool? = nil,
inboundType: Inbound.Type = Inbound.self,
outboundType: Outbound.Type = Outbound.self
) {
self.inboundType = Inbound.self
self.outboundType = Outbound.self

self.backpressureStrategy = backpressureStrategy
self.isOutboundHalfClosureEnabled = isOutboundHalfClosureEnabled ?? false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ final class ConfiguringPipelineAsyncMultiplexerTests: XCTestCase {
// client
for _ in 0 ..< requestCount {
let streamChannel = try await clientMultiplexer.createStreamChannel(
inboundType: HTTP2Frame.FramePayload.self,
outboundType: HTTP2Frame.FramePayload.self
configuration: .init(
inboundType: HTTP2Frame.FramePayload.self,
outboundType: HTTP2Frame.FramePayload.self
)
) { channel -> EventLoopFuture<Void> in
channel.eventLoop.makeSucceededVoidFuture()
}
Expand Down

0 comments on commit df3b529

Please sign in to comment.