@@ -22,6 +22,10 @@ import NIOTransportServices
2222import NIOSSL
2323#endif
2424
25+ #if canImport(Network)
26+ import Network
27+ #endif
28+
2529@usableFromInline
2630internal protocol ConnectionManagerChannelProvider {
2731 /// Make an `EventLoopFuture<Channel>`.
@@ -72,6 +76,52 @@ internal struct DefaultChannelProvider: ConnectionManagerChannelProvider {
7276 @usableFromInline
7377 internal var debugChannelInitializer : Optional < ( Channel ) -> EventLoopFuture < Void > >
7478
79+ #if canImport(Network)
80+ @available ( macOS 10 . 14 , iOS 12 . 0 , watchOS 6 . 0 , tvOS 12 . 0 , * )
81+ @usableFromInline
82+ internal var nwParametersConfigurator : ( @Sendable ( NWParameters ) -> Void ) ? {
83+ get {
84+ self . _nwParametersConfigurator as! ( @Sendable ( NWParameters ) -> Void ) ?
85+ }
86+ set {
87+ self . _nwParametersConfigurator = newValue
88+ }
89+ }
90+
91+ private var _nwParametersConfigurator : ( any Sendable ) ?
92+ #endif
93+
94+ #if canImport(Network)
95+ @inlinable
96+ @available ( macOS 10 . 14 , iOS 12 . 0 , watchOS 6 . 0 , tvOS 12 . 0 , * )
97+ internal init (
98+ connectionTarget: ConnectionTarget ,
99+ connectionKeepalive: ClientConnectionKeepalive ,
100+ connectionIdleTimeout: TimeAmount ,
101+ tlsMode: TLSMode ,
102+ tlsConfiguration: GRPCTLSConfiguration ? ,
103+ httpTargetWindowSize: Int ,
104+ httpMaxFrameSize: Int ,
105+ errorDelegate: ClientErrorDelegate ? ,
106+ debugChannelInitializer: ( ( Channel ) -> EventLoopFuture < Void > ) ? ,
107+ nwParametersConfigurator: ( @Sendable ( NWParameters ) -> Void ) ?
108+ ) {
109+ self . init (
110+ connectionTarget: connectionTarget,
111+ connectionKeepalive: connectionKeepalive,
112+ connectionIdleTimeout: connectionIdleTimeout,
113+ tlsMode: tlsMode,
114+ tlsConfiguration: tlsConfiguration,
115+ httpTargetWindowSize: httpTargetWindowSize,
116+ httpMaxFrameSize: httpMaxFrameSize,
117+ errorDelegate: errorDelegate,
118+ debugChannelInitializer: debugChannelInitializer
119+ )
120+
121+ self . nwParametersConfigurator = nwParametersConfigurator
122+ }
123+ #endif
124+
75125 @inlinable
76126 internal init (
77127 connectionTarget: ConnectionTarget ,
@@ -133,6 +183,12 @@ internal struct DefaultChannelProvider: ConnectionManagerChannelProvider {
133183 errorDelegate: configuration. errorDelegate,
134184 debugChannelInitializer: configuration. debugChannelInitializer
135185 )
186+
187+ #if canImport(Network)
188+ if #available( macOS 10 . 14 , iOS 12 . 0 , watchOS 6 . 0 , tvOS 12 . 0 , * ) {
189+ self . nwParametersConfigurator = configuration. nwParametersConfigurator
190+ }
191+ #endif
136192 }
137193
138194 private var serverHostname : String ? {
@@ -222,6 +278,15 @@ internal struct DefaultChannelProvider: ConnectionManagerChannelProvider {
222278 _ = bootstrap. connectTimeout ( connectTimeout)
223279 }
224280
281+ #if canImport(Network)
282+ if #available( macOS 10 . 14 , iOS 12 . 0 , watchOS 6 . 0 , tvOS 12 . 0 , * ) ,
283+ let configurator = self . nwParametersConfigurator,
284+ let transportServicesBootstrap = bootstrap as? NIOTSConnectionBootstrap
285+ {
286+ _ = transportServicesBootstrap. configureNWParameters ( configurator)
287+ }
288+ #endif
289+
225290 return bootstrap. connect ( to: self . connectionTarget)
226291 }
227292}
0 commit comments