@@ -47,6 +47,7 @@ public struct WebSocketServer: Sendable, LCLWebSocketListenable {
47
47
private var _onError : ( @Sendable ( Error ) -> Void ) ?
48
48
49
49
private let isShutdown : ManagedAtomic < Bool >
50
+ private let isMultiThreadedEventLoop : Bool
50
51
51
52
/// Initialize a `WebSocketServer` instance on the given `EventLoopGroup` using the provided `serverConfiguration`
52
53
///
@@ -60,6 +61,7 @@ public struct WebSocketServer: Sendable, LCLWebSocketListenable {
60
61
self . eventloopGroup = eventloopGroup
61
62
self . serverUpgradeConfiguration = serverUpgradeConfiguration
62
63
self . isShutdown = ManagedAtomic ( false )
64
+ self . isMultiThreadedEventLoop = self . eventloopGroup is MultiThreadedEventLoopGroup
63
65
}
64
66
65
67
public mutating func onOpen( _ callback: ( @Sendable ( WebSocket ) -> Void ) ? ) {
@@ -119,7 +121,7 @@ public struct WebSocketServer: Sendable, LCLWebSocketListenable {
119
121
self . makeBootstrapAndBind ( with: configuration, resolvedAddress: address) { channel in
120
122
logger. debug ( " child channel: \( channel) " )
121
123
do {
122
- try self . makeChildChannelInitializer ( configuration : configuration, channel : channel)
124
+ try self . initializeChildChannel ( using : configuration, on : channel)
123
125
} catch {
124
126
return channel. eventLoop. makeFailedFuture ( error)
125
127
}
@@ -230,7 +232,7 @@ public struct WebSocketServer: Sendable, LCLWebSocketListenable {
230
232
231
233
extension WebSocketServer {
232
234
233
- private func makeChildChannelInitializer ( configuration: LCLWebSocket . Configuration , channel: Channel ) throws {
235
+ private func initializeChildChannel ( using configuration: LCLWebSocket . Configuration , on channel: Channel ) throws {
234
236
if self . eventloopGroup is MultiThreadedEventLoopGroup {
235
237
if configuration. socketReuseAddress,
236
238
let syncOptions = channel. syncOptions
@@ -326,6 +328,7 @@ extension WebSocketServer {
326
328
func makeNIOTSListenerBootstrap( ) -> EventLoopFuture < Channel > {
327
329
328
330
let tcpOptions = NWProtocolTCP . Options ( )
331
+ tcpOptions. connectionTimeout = Int ( configuration. connectionTimeout. seconds)
329
332
tcpOptions. noDelay = configuration. socketTcpNoDelay
330
333
331
334
return NIOTSListenerBootstrap ( group: self . eventloopGroup)
@@ -371,7 +374,7 @@ extension WebSocketServer {
371
374
#endif
372
375
373
376
#if canImport(Network)
374
- if self . eventloopGroup is MultiThreadedEventLoopGroup {
377
+ if self . isMultiThreadedEventLoop {
375
378
return makeServerBootstrap ( )
376
379
} else {
377
380
return makeNIOTSListenerBootstrap ( )
@@ -403,7 +406,7 @@ extension WebSocketServer {
403
406
self . makeBootstrapAndBind ( with: configuration, resolvedAddress: address) { channel in
404
407
logger. debug ( " child channel: \( channel) " )
405
408
do {
406
- try self . makeChildChannelInitializer ( configuration : configuration, channel : channel)
409
+ try self . initializeChildChannel ( using : configuration, on : channel)
407
410
} catch {
408
411
return channel. eventLoop. makeFailedFuture ( error)
409
412
}
@@ -465,7 +468,6 @@ extension WebSocketServer {
465
468
) ,
466
469
WebSocketHandler ( websocket: websocket) ,
467
470
] )
468
- print ( channel. pipeline. debugDescription, channel)
469
471
return channel. eventLoop. makeSucceededFuture ( UpgradeResult . websocket)
470
472
} catch {
471
473
return channel. eventLoop. makeFailedFuture ( error)
0 commit comments