@@ -22,6 +22,10 @@ import NIOTransportServices
22
22
import NIOSSL
23
23
#endif
24
24
25
+ #if canImport(Network)
26
+ import Network
27
+ #endif
28
+
25
29
@usableFromInline
26
30
internal protocol ConnectionManagerChannelProvider {
27
31
/// Make an `EventLoopFuture<Channel>`.
@@ -72,6 +76,52 @@ internal struct DefaultChannelProvider: ConnectionManagerChannelProvider {
72
76
@usableFromInline
73
77
internal var debugChannelInitializer : Optional < ( Channel ) -> EventLoopFuture < Void > >
74
78
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
+
75
125
@inlinable
76
126
internal init (
77
127
connectionTarget: ConnectionTarget ,
@@ -133,6 +183,12 @@ internal struct DefaultChannelProvider: ConnectionManagerChannelProvider {
133
183
errorDelegate: configuration. errorDelegate,
134
184
debugChannelInitializer: configuration. debugChannelInitializer
135
185
)
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
136
192
}
137
193
138
194
private var serverHostname : String ? {
@@ -222,6 +278,15 @@ internal struct DefaultChannelProvider: ConnectionManagerChannelProvider {
222
278
_ = bootstrap. connectTimeout ( connectTimeout)
223
279
}
224
280
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
+
225
290
return bootstrap. connect ( to: self . connectionTarget)
226
291
}
227
292
}
0 commit comments