|
|
@@ -22,6 +22,10 @@ import NIOTransportServices
|
|
|
import NIOSSL
|
|
|
#endif
|
|
|
|
|
|
+#if canImport(Network)
|
|
|
+import Network
|
|
|
+#endif
|
|
|
+
|
|
|
@usableFromInline
|
|
|
internal protocol ConnectionManagerChannelProvider {
|
|
|
/// Make an `EventLoopFuture<Channel>`.
|
|
|
@@ -72,6 +76,52 @@ internal struct DefaultChannelProvider: ConnectionManagerChannelProvider {
|
|
|
@usableFromInline
|
|
|
internal var debugChannelInitializer: Optional<(Channel) -> EventLoopFuture<Void>>
|
|
|
|
|
|
+ #if canImport(Network)
|
|
|
+ @available(macOS 10.14, iOS 12.0, watchOS 6.0, tvOS 12.0, *)
|
|
|
+ @usableFromInline
|
|
|
+ internal var nwParametersConfigurator: (@Sendable (NWParameters) -> Void)? {
|
|
|
+ get {
|
|
|
+ self._nwParametersConfigurator as! (@Sendable (NWParameters) -> Void)?
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ self._nwParametersConfigurator = newValue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private var _nwParametersConfigurator: (any Sendable)?
|
|
|
+ #endif
|
|
|
+
|
|
|
+ #if canImport(Network)
|
|
|
+ @inlinable
|
|
|
+ @available(macOS 10.14, iOS 12.0, watchOS 6.0, tvOS 12.0, *)
|
|
|
+ internal init(
|
|
|
+ connectionTarget: ConnectionTarget,
|
|
|
+ connectionKeepalive: ClientConnectionKeepalive,
|
|
|
+ connectionIdleTimeout: TimeAmount,
|
|
|
+ tlsMode: TLSMode,
|
|
|
+ tlsConfiguration: GRPCTLSConfiguration?,
|
|
|
+ httpTargetWindowSize: Int,
|
|
|
+ httpMaxFrameSize: Int,
|
|
|
+ errorDelegate: ClientErrorDelegate?,
|
|
|
+ debugChannelInitializer: ((Channel) -> EventLoopFuture<Void>)?,
|
|
|
+ nwParametersConfigurator: (@Sendable (NWParameters) -> Void)?
|
|
|
+ ) {
|
|
|
+ self.init(
|
|
|
+ connectionTarget: connectionTarget,
|
|
|
+ connectionKeepalive: connectionKeepalive,
|
|
|
+ connectionIdleTimeout: connectionIdleTimeout,
|
|
|
+ tlsMode: tlsMode,
|
|
|
+ tlsConfiguration: tlsConfiguration,
|
|
|
+ httpTargetWindowSize: httpTargetWindowSize,
|
|
|
+ httpMaxFrameSize: httpMaxFrameSize,
|
|
|
+ errorDelegate: errorDelegate,
|
|
|
+ debugChannelInitializer: debugChannelInitializer
|
|
|
+ )
|
|
|
+
|
|
|
+ self.nwParametersConfigurator = nwParametersConfigurator
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+
|
|
|
@inlinable
|
|
|
internal init(
|
|
|
connectionTarget: ConnectionTarget,
|
|
|
@@ -133,6 +183,12 @@ internal struct DefaultChannelProvider: ConnectionManagerChannelProvider {
|
|
|
errorDelegate: configuration.errorDelegate,
|
|
|
debugChannelInitializer: configuration.debugChannelInitializer
|
|
|
)
|
|
|
+
|
|
|
+ #if canImport(Network)
|
|
|
+ if #available(macOS 10.14, iOS 12.0, watchOS 6.0, tvOS 12.0, *) {
|
|
|
+ self.nwParametersConfigurator = configuration.nwParametersConfigurator
|
|
|
+ }
|
|
|
+ #endif
|
|
|
}
|
|
|
|
|
|
private var serverHostname: String? {
|
|
|
@@ -222,6 +278,15 @@ internal struct DefaultChannelProvider: ConnectionManagerChannelProvider {
|
|
|
_ = bootstrap.connectTimeout(connectTimeout)
|
|
|
}
|
|
|
|
|
|
+ #if canImport(Network)
|
|
|
+ if #available(macOS 10.14, iOS 12.0, watchOS 6.0, tvOS 12.0, *),
|
|
|
+ let configurator = self.nwParametersConfigurator,
|
|
|
+ let transportServicesBootstrap = bootstrap as? NIOTSConnectionBootstrap
|
|
|
+ {
|
|
|
+ _ = transportServicesBootstrap.configureNWParameters(configurator)
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+
|
|
|
return bootstrap.connect(to: self.connectionTarget)
|
|
|
}
|
|
|
}
|