Skip to content

Commit 6e8d069

Browse files
committed
lint
1 parent feaa53c commit 6e8d069

File tree

7 files changed

+67
-45
lines changed

7 files changed

+67
-45
lines changed

Sources/AutobahnClient/AutobahnClient.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,25 @@
1010
// SPDX-License-Identifier: Apache-2.0
1111
//
1212

13-
1413
import Foundation
1514
import LCLWebSocket
1615
import NIOCore
1716
import NIOPosix
1817

1918
@main
2019
struct TestWebSocketClient {
21-
20+
2221
static let config = LCLWebSocket.Configuration(
2322
maxFrameSize: 1 << 16,
2423
autoPingConfiguration: .disabled,
2524
leftoverBytesStrategy: .forwardBytes
2625
)
27-
26+
2827
static let serverAddress = "127.0.0.1"
2928
static let serverPort = 9001
30-
29+
3130
public static func main() throws {
32-
31+
3332
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
3433
var client = LCLWebSocket.client(on: elg)
3534
let totalTestCount = elg.any().makePromise(of: Int.self)
@@ -41,11 +40,12 @@ struct TestWebSocketClient {
4140
totalTestCount.succeed(total)
4241
}
4342

44-
try client.connect(to: "ws://\(Self.serverAddress):\(Self.serverPort)/getCaseCount", configuration: Self.config).wait()
45-
43+
try client.connect(to: "ws://\(Self.serverAddress):\(Self.serverPort)/getCaseCount", configuration: Self.config)
44+
.wait()
45+
4646
let total = try totalTestCount.futureResult.wait()
4747
print("Running total tests: \(total)")
48-
48+
4949
for i in 1...total {
5050
var client = LCLWebSocket.client(on: elg)
5151
client.onText { ws, text in
@@ -54,11 +54,17 @@ struct TestWebSocketClient {
5454
client.onBinary { ws, binary in
5555
ws.send(binary, opcode: .binary)
5656
}
57-
try client.connect(to: "ws://\(Self.serverAddress):\(Self.serverPort)/runCase?case=\(i)&agent={LCLWebSocketClient}", configuration: Self.config).wait()
57+
try client.connect(
58+
to: "ws://\(Self.serverAddress):\(Self.serverPort)/runCase?case=\(i)&agent={LCLWebSocketClient}",
59+
configuration: Self.config
60+
).wait()
5861
}
59-
62+
6063
let closeClient = LCLWebSocket.client()
61-
try closeClient.connect(to: "ws://\(Self.serverAddress):\(Self.serverPort)/updateReports?agent={LCLWebSocketClient}", configuration: Self.config).wait()
62-
64+
try closeClient.connect(
65+
to: "ws://\(Self.serverAddress):\(Self.serverPort)/updateReports?agent={LCLWebSocketClient}",
66+
configuration: Self.config
67+
).wait()
68+
6369
}
6470
}

Sources/AutobahnServer/AutohahnServer.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ import NIOPosix
1717

1818
@main
1919
struct AutohahnServer {
20-
20+
2121
static let config = LCLWebSocket.Configuration(
2222
maxFrameSize: 1 << 16,
2323
autoPingConfiguration: .disabled,
2424
leftoverBytesStrategy: .forwardBytes
2525
)
26-
26+
2727
static let serverAddress = "127.0.0.1"
2828
static let serverPort = 9000
29-
29+
3030
static func main() throws {
31-
31+
3232
let args = CommandLine.arguments
3333
var port: Int = Self.serverPort
3434
precondition(args.count == 1 || args.count == 3, "Usage: \(args[0]) [--port <port>]")
@@ -37,18 +37,17 @@ struct AutohahnServer {
3737
let portIndex = portCmdIndex + 1
3838
port = Int(args[portIndex]) ?? port
3939
}
40-
40+
4141
var server = LCLWebSocket.server()
42-
42+
4343
server.onBinary { ws, buffer in
4444
ws.send(buffer, opcode: .binary)
4545
}
46-
46+
4747
server.onText { ws, text in
4848
ws.send(.init(string: text), opcode: .text)
4949
}
50-
50+
5151
try server.listen(host: Self.serverAddress, port: port, configuration: Self.config).wait()
5252
}
5353
}
54-

Sources/LCLWebSocket/Client/WebSocketClient.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public struct WebSocketClient: Sendable, LCLWebSocketListenable {
166166
func makeChannelInitializer(_ channel: Channel) -> EventLoopFuture<Void> {
167167
if self.eventloopGroup is MultiThreadedEventLoopGroup {
168168
if configuration.socketReuseAddress,
169-
let syncOptions = channel.syncOptions
169+
let syncOptions = channel.syncOptions
170170
{
171171
do {
172172
try syncOptions.setOption(.socketOption(.so_reuseaddr), value: 1)
@@ -176,7 +176,8 @@ public struct WebSocketClient: Sendable, LCLWebSocketListenable {
176176
}
177177

178178
if configuration.socketTcpNoDelay,
179-
let syncOptions = channel.syncOptions {
179+
let syncOptions = channel.syncOptions
180+
{
180181
do {
181182
try syncOptions.setOption(.socketOption(.tcp_nodelay), value: 1)
182183
} catch {
@@ -361,7 +362,7 @@ extension WebSocketClient {
361362
) -> EventLoopFuture<Channel> {
362363

363364
func makeClientBootstrap() -> EventLoopFuture<Channel> {
364-
return ClientBootstrap(group: self.eventloopGroup)
365+
ClientBootstrap(group: self.eventloopGroup)
365366
.connectTimeout(configuration.connectionTimeout)
366367
.channelInitializer(channelInitializer)
367368
.connect(to: resolvedAddress)
@@ -486,25 +487,26 @@ extension WebSocketClient {
486487
func makeChannelInitializer(_ channel: Channel) -> EventLoopFuture<Void> {
487488
if self.eventloopGroup is MultiThreadedEventLoopGroup {
488489
if configuration.socketReuseAddress,
489-
let syncOptions = channel.syncOptions
490+
let syncOptions = channel.syncOptions
490491
{
491492
do {
492493
try syncOptions.setOption(.socketOption(.so_reuseaddr), value: 1)
493494
} catch {
494495
return channel.eventLoop.makeFailedFuture(error)
495496
}
496497
}
497-
498+
498499
if configuration.socketTcpNoDelay,
499-
let syncOptions = channel.syncOptions {
500+
let syncOptions = channel.syncOptions
501+
{
500502
do {
501503
try syncOptions.setOption(.socketOption(.tcp_nodelay), value: 1)
502504
} catch {
503505
return channel.eventLoop.makeFailedFuture(error)
504506
}
505507
}
506508
}
507-
509+
508510
if let socketSendBufferSize = configuration.socketSendBufferSize,
509511
let syncOptions = channel.syncOptions
510512
{

Sources/LCLWebSocket/Server/WebSocketServer.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,30 +243,31 @@ extension WebSocketServer {
243243
) -> EventLoopFuture<Channel> {
244244

245245
func makeServerBootstrap() -> EventLoopFuture<Channel> {
246-
return ServerBootstrap(group: self.eventloopGroup)
246+
ServerBootstrap(group: self.eventloopGroup)
247247
.serverChannelInitializer { channel in
248248
logger.info("Server is listening on \(resolvedAddress)")
249249
if self.eventloopGroup is MultiThreadedEventLoopGroup {
250250
if configuration.socketReuseAddress,
251-
let syncOptions = channel.syncOptions
251+
let syncOptions = channel.syncOptions
252252
{
253253
do {
254254
try syncOptions.setOption(.socketOption(.so_reuseaddr), value: 1)
255255
} catch {
256256
return channel.eventLoop.makeFailedFuture(error)
257257
}
258258
}
259-
259+
260260
if configuration.socketTcpNoDelay,
261-
let syncOptions = channel.syncOptions {
261+
let syncOptions = channel.syncOptions
262+
{
262263
do {
263264
try syncOptions.setOption(.socketOption(.tcp_nodelay), value: 1)
264265
} catch {
265266
return channel.eventLoop.makeFailedFuture(error)
266267
}
267268
}
268269
}
269-
270+
270271
if let socketSendBufferSize = configuration.socketSendBufferSize,
271272
let syncOptions = channel.syncOptions
272273
{
@@ -306,10 +307,10 @@ extension WebSocketServer {
306307

307308
#if canImport(Network)
308309
func makeNIOTSListenerBootstrap() -> EventLoopFuture<Channel> {
309-
310+
310311
let tcpOptions = NWProtocolTCP.Options()
311312
tcpOptions.noDelay = configuration.socketTcpNoDelay
312-
313+
313314
return NIOTSListenerBootstrap(group: self.eventloopGroup)
314315
.tcpOptions(tcpOptions)
315316
.serverChannelInitializer { channel in
@@ -385,10 +386,11 @@ extension WebSocketServer {
385386
) -> EventLoopFuture<Void> {
386387
self.makeBootstrapAndBind(with: configuration, resolvedAddress: address) { channel in
387388
logger.debug("child channel: \(channel)")
388-
389+
389390
if self.eventloopGroup is MultiThreadedEventLoopGroup {
390391
if configuration.socketReuseAddress,
391-
let syncOptions = channel.syncOptions {
392+
let syncOptions = channel.syncOptions
393+
{
392394
do {
393395
try syncOptions.setOption(.socketOption(.so_reuseaddr), value: 1)
394396
} catch {
@@ -397,15 +399,16 @@ extension WebSocketServer {
397399
}
398400

399401
if configuration.socketTcpNoDelay,
400-
let syncOptions = channel.syncOptions {
402+
let syncOptions = channel.syncOptions
403+
{
401404
do {
402405
try syncOptions.setOption(.socketOption(.tcp_nodelay), value: 1)
403406
} catch {
404407
return channel.eventLoop.makeFailedFuture(error)
405408
}
406409
}
407410
}
408-
411+
409412
// enable tls if configuration is provided
410413
if let tlsConfiguration = configuration.tlsConfiguration {
411414
guard let sslContext = try? NIOSSLContext(configuration: tlsConfiguration) else {

Sources/LCLWebSocket/WebSocket.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import Foundation
1414
import NIOConcurrencyHelpers
1515
import NIOCore
16+
import NIOFoundationCompat
1617
import NIOHTTP1
1718
import NIOPosix
1819
import NIOWebSocket
19-
import NIOFoundationCompat
2020

2121
public final class WebSocket: Sendable {
2222

@@ -327,7 +327,11 @@ public final class WebSocket: Sendable {
327327
case 3000..<5000:
328328
break
329329
default:
330-
self.close(code: .protocolError, shouldForceCloseConnection: self.type == .server, promise: nil)
330+
self.close(
331+
code: .protocolError,
332+
shouldForceCloseConnection: self.type == .server,
333+
promise: nil
334+
)
331335
return
332336
}
333337
default:
@@ -338,7 +342,11 @@ public final class WebSocket: Sendable {
338342
let reason = data.readString(length: data.readableBytes, encoding: .utf8)
339343

340344
if bytesLeftForReason > 0 && reason == nil {
341-
self.close(code: .dataInconsistentWithMessage, shouldForceCloseConnection: self.type == .server, promise: nil)
345+
self.close(
346+
code: .dataInconsistentWithMessage,
347+
shouldForceCloseConnection: self.type == .server,
348+
promise: nil
349+
)
342350
return
343351
}
344352
self._onClosing.value?(closeCode, reason)

Sources/LCLWebSocket/WebSocketConfiguration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ extension LCLWebSocket {
9393

9494
/// Socket receive buffer size in bytes.
9595
var socketReceiveBufferSize: SocketOptionValue?
96-
96+
9797
/// Indicate that the underlying socket should reuse address or not.
9898
///
9999
/// This option has no effect if `NIOTSEventLoopGroup` is used.
100100
///
101101
/// - Note: see more in `man socket(7)`.
102102
var socketReuseAddress: Bool
103-
103+
104104
/// Indicate that the socket should send the segments as soon as possible. If set, the Nagle algorithm is disabled.
105105
///
106106
/// - Note: see more in `man socket(7)`

Sources/LCLWebSocket/WebSocketHandler.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ final class WebSocketHandler: ChannelInboundHandler {
2929
func errorCaught(context: ChannelHandlerContext, error: any Error) {
3030
logger.debug("WebSocketHandler caught error: \(error)")
3131
if let err = error as? NIOWebSocketError {
32-
self.websocket.close(code: WebSocketErrorCode(err), shouldForceCloseConnection: self.websocket.type == .server, promise: nil)
32+
self.websocket.close(
33+
code: WebSocketErrorCode(err),
34+
shouldForceCloseConnection: self.websocket.type == .server,
35+
promise: nil
36+
)
3337
} else {
3438
self.websocket.close(code: .protocolError, shouldForceCloseConnection: true, promise: nil)
3539
}

0 commit comments

Comments
 (0)