@@ -233,20 +233,6 @@ public struct WebSocketServer: Sendable, LCLWebSocketListenable {
233
233
extension WebSocketServer {
234
234
235
235
private func initializeChildChannel( using configuration: LCLWebSocket . Configuration , on channel: Channel ) throws {
236
- if self . eventloopGroup is MultiThreadedEventLoopGroup {
237
- if configuration. socketReuseAddress,
238
- let syncOptions = channel. syncOptions
239
- {
240
- try syncOptions. setOption ( . socketOption( . so_reuseaddr) , value: 1 )
241
- }
242
-
243
- if configuration. socketTcpNoDelay,
244
- let syncOptions = channel. syncOptions
245
- {
246
- try syncOptions. setOption ( . socketOption( . tcp_nodelay) , value: 1 )
247
- }
248
- }
249
-
250
236
// enable tls if configuration is provided
251
237
if let tlsConfiguration = configuration. tlsConfiguration {
252
238
guard let sslContext = try ? NIOSSLContext ( configuration: tlsConfiguration) else {
@@ -265,57 +251,20 @@ extension WebSocketServer {
265
251
266
252
func makeServerBootstrap( ) -> EventLoopFuture < Channel > {
267
253
ServerBootstrap ( group: self . eventloopGroup)
254
+ . serverChannelOption ( . socketOption( . so_reuseaddr) , value: SocketOptionValue ( configuration. socketReuseAddress ? 1 : 0 ) )
255
+ . serverChannelOption ( . tcpOption( . tcp_nodelay) , value: SocketOptionValue ( configuration. socketTcpNoDelay ? 1 : 0 ) )
256
+ . childChannelOption ( . socketOption( . so_reuseaddr) , value: SocketOptionValue ( configuration. socketReuseAddress ? 1 : 0 ) )
257
+ . childChannelOption ( . tcpOption( . tcp_nodelay) , value: SocketOptionValue ( configuration. socketTcpNoDelay ? 1 : 0 ) )
258
+ . childChannelOption ( . socketOption( . so_sndbuf) , value: configuration. socketSendBufferSize)
259
+ . childChannelOption ( . socketOption( . so_rcvbuf) , value: configuration. socketReceiveBufferSize)
268
260
. serverChannelInitializer { channel in
269
261
logger. info ( " Server is listening on \( resolvedAddress) " )
270
- if configuration. socketReuseAddress,
271
- let syncOptions = channel. syncOptions
272
- {
273
- do {
274
- try syncOptions. setOption ( . socketOption( . so_reuseaddr) , value: 1 )
275
- } catch {
276
- return channel. eventLoop. makeFailedFuture ( error)
277
- }
278
- }
279
-
280
- if configuration. socketTcpNoDelay,
281
- let syncOptions = channel. syncOptions
282
- {
283
- do {
284
- try syncOptions. setOption ( . socketOption( . tcp_nodelay) , value: 1 )
285
- } catch {
286
- return channel. eventLoop. makeFailedFuture ( error)
287
- }
288
- }
289
-
290
- if let socketSendBufferSize = configuration. socketSendBufferSize,
291
- let syncOptions = channel. syncOptions
292
- {
293
- do {
294
- try syncOptions. setOption ( . socketOption( . so_sndbuf) , value: socketSendBufferSize)
295
- } catch {
296
- return channel. eventLoop. makeFailedFuture ( error)
297
- }
298
- }
299
-
300
- if let socketReceiveBuffer = configuration. socketReceiveBufferSize,
301
- let syncOptions = channel. syncOptions
302
- {
303
- do {
304
- try syncOptions. setOption ( . socketOption( . so_rcvbuf) , value: socketReceiveBuffer)
305
- } catch {
306
- return channel. eventLoop. makeFailedFuture ( error)
307
- }
308
- }
309
262
310
263
// bind to selected device, if any
311
264
if let deviceName = configuration. deviceName,
312
265
let device = findDevice ( with: deviceName, protocol: resolvedAddress. protocol)
313
266
{
314
- do {
315
- try bindTo ( device: device, on: channel)
316
- } catch {
317
- return channel. eventLoop. makeFailedFuture ( error)
318
- }
267
+ return bindTo ( device: device, on: channel)
319
268
}
320
269
321
270
return channel. eventLoop. makeSucceededVoidFuture ( )
@@ -333,37 +282,16 @@ extension WebSocketServer {
333
282
334
283
return NIOTSListenerBootstrap ( group: self . eventloopGroup)
335
284
. tcpOptions ( tcpOptions)
285
+ . serverChannelOption ( . socketOption( . so_reuseaddr) , value: SocketOptionValue ( configuration. socketReuseAddress ? 1 : 0 ) )
286
+ . childChannelOption ( . socketOption( . so_reuseaddr) , value: SocketOptionValue ( configuration. socketReuseAddress ? 1 : 0 ) )
336
287
. serverChannelInitializer { channel in
337
288
logger. info ( " Server is listening on \( resolvedAddress) " )
338
- if let socketSendBufferSize = configuration. socketSendBufferSize,
339
- let syncOptions = channel. syncOptions
340
- {
341
- do {
342
- try syncOptions. setOption ( . socketOption( . so_sndbuf) , value: socketSendBufferSize)
343
- } catch {
344
- return channel. eventLoop. makeFailedFuture ( error)
345
- }
346
- }
347
-
348
- if let socketReceiveBuffer = configuration. socketReceiveBufferSize,
349
- let syncOptions = channel. syncOptions
350
- {
351
- do {
352
- try syncOptions. setOption ( . socketOption( . so_rcvbuf) , value: socketReceiveBuffer)
353
- } catch {
354
- return channel. eventLoop. makeFailedFuture ( error)
355
- }
356
- }
357
289
358
290
// bind to selected device, if any
359
291
if let deviceName = configuration. deviceName,
360
292
let device = findDevice ( with: deviceName, protocol: resolvedAddress. protocol)
361
293
{
362
- do {
363
- try bindTo ( device: device, on: channel)
364
- } catch {
365
- return channel. eventLoop. makeFailedFuture ( error)
366
- }
294
+ return bindTo ( device: device, on: channel)
367
295
}
368
296
369
297
return channel. eventLoop. makeSucceededVoidFuture ( )
0 commit comments