Skip to content

Commit

Permalink
adopt NIOAsyncChannel.Configuration (#409)
Browse files Browse the repository at this point in the history
Adopt NIOAsyncChannel.Configuration as the NIO SPI changed
  • Loading branch information
rnro authored Jul 11, 2023
1 parent d5f0715 commit 188fa9b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 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
19 changes: 3 additions & 16 deletions Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,33 +247,20 @@ extension NIOHTTP2Handler {
/// Create a stream channel initialized with the provided closure and return it wrapped within a `NIOAsyncChannel`.
///
/// - 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,
initializer: @escaping NIOHTTP2Handler.StreamInitializer
) 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
20 changes: 12 additions & 8 deletions Sources/NIOHTTP2/HTTP2PipelineHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,12 @@ extension Channel {
return connectionInitializer(self).flatMapThrowing { _ in
let connectionAsyncChannel = try NIOAsyncChannel(
synchronouslyWrapping: self,
backpressureStrategy: connectionBackpressureStrategy,
isOutboundHalfClosureEnabled: isConnectionOutboundHalfClosureEnabled,
inboundType: ConnectionInbound.self,
outboundType: ConnectionOutbound.self
configuration: .init(
backpressureStrategy: connectionBackpressureStrategy ?? .init(lowWatermark: 2, highWatermark: 10),
isOutboundHalfClosureEnabled: isConnectionOutboundHalfClosureEnabled,
inboundType: ConnectionInbound.self,
outboundType: ConnectionOutbound.self
)
)
return (connectionAsyncChannel, multiplexer)
}
Expand Down Expand Up @@ -716,10 +718,12 @@ extension ChannelPipeline.SynchronousOperations {
inboundStreamInitializer(channel).flatMapThrowing { _ in
return try NIOAsyncChannel(
synchronouslyWrapping: channel,
backpressureStrategy: inboundStreamBackpressureStrategy,
isOutboundHalfClosureEnabled: isInboundStreamOutboundHalfClosureEnabled,
inboundType: StreamInbound.self,
outboundType: StreamOutbound.self
configuration: .init(
backpressureStrategy: inboundStreamBackpressureStrategy ?? .init(lowWatermark: 2, highWatermark: 10),
isOutboundHalfClosureEnabled: isInboundStreamOutboundHalfClosureEnabled,
inboundType: StreamInbound.self,
outboundType: StreamOutbound.self
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,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 Expand Up @@ -268,8 +270,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 188fa9b

Please sign in to comment.