@@ -244,9 +244,29 @@ extension WebSocketServer {
244
244
245
245
func makeServerBootstrap( ) -> EventLoopFuture < Channel > {
246
246
return ServerBootstrap ( group: self . eventloopGroup)
247
- . serverChannelOption ( . socketOption( . so_reuseaddr) , value: 1 )
248
247
. serverChannelInitializer { channel in
249
- print ( " parent channel: \( channel) " )
248
+ logger. info ( " Server is listening on \( resolvedAddress) " )
249
+ if self . eventloopGroup is MultiThreadedEventLoopGroup {
250
+ if configuration. socketReuseAddress,
251
+ let syncOptions = channel. syncOptions
252
+ {
253
+ do {
254
+ try syncOptions. setOption ( . socketOption( . so_reuseaddr) , value: 1 )
255
+ } catch {
256
+ return channel. eventLoop. makeFailedFuture ( error)
257
+ }
258
+ }
259
+
260
+ if configuration. socketTcpNoDelay,
261
+ let syncOptions = channel. syncOptions {
262
+ do {
263
+ try syncOptions. setOption ( . socketOption( . tcp_nodelay) , value: 1 )
264
+ } catch {
265
+ return channel. eventLoop. makeFailedFuture ( error)
266
+ }
267
+ }
268
+ }
269
+
250
270
if let socketSendBufferSize = configuration. socketSendBufferSize,
251
271
let syncOptions = channel. syncOptions
252
272
{
@@ -280,17 +300,20 @@ extension WebSocketServer {
280
300
281
301
return channel. eventLoop. makeSucceededVoidFuture ( )
282
302
}
283
- . childChannelOption ( . socketOption( . so_reuseaddr) , value: 1 )
284
303
. childChannelInitializer ( childChannelInitializer)
285
304
. bind ( to: resolvedAddress)
286
305
}
287
306
288
307
#if canImport(Network)
289
308
func makeNIOTSListenerBootstrap( ) -> EventLoopFuture < Channel > {
309
+
310
+ let tcpOptions = NWProtocolTCP . Options ( )
311
+ tcpOptions. noDelay = configuration. socketTcpNoDelay
312
+
290
313
return NIOTSListenerBootstrap ( group: self . eventloopGroup)
291
- . serverChannelOption ( . socketOption ( . so_reuseaddr ) , value : 1 )
314
+ . tcpOptions ( tcpOptions )
292
315
. serverChannelInitializer { channel in
293
- print ( " parent channel: \( channel ) " )
316
+ logger . info ( " Server is listening on \( resolvedAddress ) " )
294
317
if let socketSendBufferSize = configuration. socketSendBufferSize,
295
318
let syncOptions = channel. syncOptions
296
319
{
@@ -361,8 +384,29 @@ extension WebSocketServer {
361
384
configuration: LCLWebSocket . Configuration
362
385
) -> EventLoopFuture < Void > {
363
386
self . makeBootstrapAndBind ( with: configuration, resolvedAddress: address) { channel in
364
- // enable tls if configuration is provided
365
387
logger. debug ( " child channel: \( channel) " )
388
+
389
+ if self . eventloopGroup is MultiThreadedEventLoopGroup {
390
+ if configuration. socketReuseAddress,
391
+ let syncOptions = channel. syncOptions {
392
+ do {
393
+ try syncOptions. setOption ( . socketOption( . so_reuseaddr) , value: 1 )
394
+ } catch {
395
+ return channel. eventLoop. makeFailedFuture ( error)
396
+ }
397
+ }
398
+
399
+ if configuration. socketTcpNoDelay,
400
+ let syncOptions = channel. syncOptions {
401
+ do {
402
+ try syncOptions. setOption ( . socketOption( . tcp_nodelay) , value: 1 )
403
+ } catch {
404
+ return channel. eventLoop. makeFailedFuture ( error)
405
+ }
406
+ }
407
+ }
408
+
409
+ // enable tls if configuration is provided
366
410
if let tlsConfiguration = configuration. tlsConfiguration {
367
411
guard let sslContext = try ? NIOSSLContext ( configuration: tlsConfiguration) else {
368
412
return channel. eventLoop. makeFailedFuture ( LCLWebSocketError . tlsInitializationFailed)
0 commit comments