Skip to content

Commit 03bbabf

Browse files
committed
Revert some swift-format changes
1 parent 2901abd commit 03bbabf

File tree

12 files changed

+102
-67
lines changed

12 files changed

+102
-67
lines changed

Package.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ let package = Package(
1111
dependencies: [
1212
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.0"),
1313
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
14-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.42.0"),
14+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.80.0"),
1515
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.14.0"),
16-
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.6.0"),
16+
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.20.0"),
1717
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
1818
],
1919
targets: [
2020
.target(
2121
name: "MQTTNIO",
22-
dependencies:
23-
[
22+
dependencies: [
2423
.product(name: "Atomics", package: "swift-atomics"),
2524
.product(name: "Logging", package: "swift-log"),
2625
.product(name: "NIO", package: "swift-nio"),

Sources/MQTTNIO/ChannelHandlers/MQTTTaskHandler.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,21 @@ final class MQTTTaskHandler: ChannelInboundHandler, RemovableChannelHandler {
8787

8888
switch packet.type {
8989
case .PUBREC:
90-
_ = connection.sendMessageNoWait(MQTTPubAckPacket(type: .PUBREL, packetId: packet.packetId, reason: .packetIdentifierNotFound))
90+
_ = connection.sendMessageNoWait(
91+
MQTTPubAckPacket(
92+
type: .PUBREL,
93+
packetId: packet.packetId,
94+
reason: .packetIdentifierNotFound
95+
)
96+
)
9197
case .PUBREL:
92-
_ = connection.sendMessageNoWait(MQTTPubAckPacket(type: .PUBCOMP, packetId: packet.packetId, reason: .packetIdentifierNotFound))
98+
_ = connection.sendMessageNoWait(
99+
MQTTPubAckPacket(
100+
type: .PUBCOMP,
101+
packetId: packet.packetId,
102+
reason: .packetIdentifierNotFound
103+
)
104+
)
93105
default:
94106
break
95107
}

Sources/MQTTNIO/ChannelHandlers/WebSocketInitialRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import NIOHTTP1
1717
// The HTTP handler to be used to initiate the request.
1818
// This initial request will be adapted by the WebSocket upgrader to contain the upgrade header parameters.
1919
// Channel read will only be called if the upgrade fails.
20-
final class WebSocketInitialRequestHandler: ChannelInboundHandler, RemovableChannelHandler {
20+
final class WebSocketInitialRequestHandler: ChannelInboundHandler, RemovableChannelHandler, Sendable {
2121
public typealias InboundIn = HTTPClientResponsePart
2222
public typealias OutboundOut = HTTPClientRequestPart
2323

Sources/MQTTNIO/MQTTClient.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
import Atomics
1515
import Dispatch
1616
import Logging
17+
import NIO
18+
import NIOConcurrencyHelpers
19+
import NIOTransportServices
20+
1721
#if canImport(Network)
1822
import Network
1923
#endif
20-
import NIO
21-
import NIOConcurrencyHelpers
22-
#if canImport(NIOSSL)
24+
#if os(macOS) || os(Linux)
2325
import NIOSSL
2426
#endif
25-
import NIOTransportServices
2627

2728
/// Swift NIO MQTT Client
2829
///
@@ -180,11 +181,13 @@ public final class MQTTClient {
180181
/// - Throws: MQTTError.alreadyShutdown: You have already shutdown the client
181182
public func syncShutdownGracefully() throws {
182183
if let eventLoop = MultiThreadedEventLoopGroup.currentEventLoop {
183-
preconditionFailure("""
184-
BUG DETECTED: syncShutdown() must not be called when on an EventLoop.
185-
Calling syncShutdown() on any EventLoop can lead to deadlocks.
186-
Current eventLoop: \(eventLoop)
187-
""")
184+
preconditionFailure(
185+
"""
186+
BUG DETECTED: syncShutdown() must not be called when on an EventLoop.
187+
Calling syncShutdown() on any EventLoop can lead to deadlocks.
188+
Current eventLoop: \(eventLoop)
189+
"""
190+
)
188191
}
189192
let errorStorageLock = NIOLock()
190193
var errorStorage: Error?
@@ -403,12 +406,12 @@ public final class MQTTClient {
403406
/// Disconnect from server
404407
/// - Returns: Future waiting on disconnect message to be sent
405408
public func disconnect() -> EventLoopFuture<Void> {
406-
return self.disconnect(packet: MQTTDisconnectPacket())
409+
self.disconnect(packet: MQTTDisconnectPacket())
407410
}
408411

409412
/// Return if client has an active connection to broker
410413
public func isActive() -> Bool {
411-
return self.connection?.channel.isActive ?? false
414+
self.connection?.channel.isActive ?? false
412415
}
413416

414417
/// Add named publish listener. Called whenever a PUBLISH message is received from the server
@@ -530,7 +533,7 @@ extension MQTTClient {
530533
func resendOnRestart() {
531534
let inflight = self.inflight.packets
532535
self.inflight.clear()
533-
inflight.forEach { packet in
536+
for packet in inflight {
534537
switch packet {
535538
case let publish as MQTTPublishPacket:
536539
let newPacket = MQTTPublishPacket(

Sources/MQTTNIO/MQTTConnection.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
import NIO
15+
import NIOHTTP1
16+
import NIOTransportServices
17+
import NIOWebSocket
18+
1419
#if canImport(FoundationEssentials)
1520
import FoundationEssentials
1621
#else
@@ -19,13 +24,9 @@ import Foundation
1924
#if canImport(Network)
2025
import Network
2126
#endif
22-
import NIO
23-
import NIOHTTP1
2427
#if canImport(NIOSSL)
2528
import NIOSSL
2629
#endif
27-
import NIOTransportServices
28-
import NIOWebSocket
2930

3031
final class MQTTConnection {
3132
let channel: Channel
@@ -72,7 +73,7 @@ final class MQTTConnection {
7273
webSocketConfiguration: webSocketConfiguration,
7374
upgradePromise: promise
7475
) {
75-
return channel.pipeline.addHandlers(handlers)
76+
try channel.pipeline.syncOperations.addHandlers(handlers)
7677
}
7778
} else {
7879
return channel.pipeline.addHandlers(handlers)
@@ -159,7 +160,7 @@ final class MQTTConnection {
159160
channel: Channel,
160161
webSocketConfiguration: MQTTClient.WebSocketConfiguration,
161162
upgradePromise promise: EventLoopPromise<Void>,
162-
afterHandlerAdded: @escaping () -> EventLoopFuture<Void>
163+
afterHandlerAdded: @escaping () throws -> Void
163164
) -> EventLoopFuture<Void> {
164165
// initial HTTP request handler, before upgrade
165166
let httpHandler = WebSocketInitialRequestHandler(
@@ -174,10 +175,10 @@ final class MQTTConnection {
174175
requestKey: Data(requestKey).base64EncodedString(),
175176
maxFrameSize: client.configuration.webSocketMaxFrameSize
176177
) { channel, _ in
177-
let future = channel.pipeline.addHandler(WebSocketHandler())
178-
.flatMap { _ in
179-
afterHandlerAdded()
180-
}
178+
let future = channel.eventLoop.makeCompletedFuture {
179+
try channel.pipeline.syncOperations.addHandler(WebSocketHandler())
180+
try afterHandlerAdded()
181+
}
181182
future.cascade(to: promise)
182183
return future
183184
}

Sources/MQTTNIO/MQTTCoreTypes.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ public struct MQTTPublishInfo: Sendable {
6262
/// Message payload.
6363
public let payload: ByteBuffer
6464

65-
public init(qos: MQTTQoS, retain: Bool, dup: Bool = false, topicName: String, payload: ByteBuffer, properties: MQTTProperties) {
65+
public init(
66+
qos: MQTTQoS,
67+
retain: Bool,
68+
dup: Bool = false,
69+
topicName: String,
70+
payload: ByteBuffer,
71+
properties: MQTTProperties
72+
) {
6673
self.qos = qos
6774
self.retain = retain
6875
self.dup = dup

Sources/MQTTNIO/MQTTListeners.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class MQTTListeners<ReturnType> {
2121
let listeners = self.lock.withLock {
2222
return self.listeners
2323
}
24-
listeners.values.forEach { listener in
24+
for listener in listeners.values {
2525
listener(result)
2626
}
2727
}

Sources/MQTTNIO/TSTLSConfiguration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ extension TSTLSConfiguration {
234234
sec_protocol_options_set_local_identity(options.securityProtocolOptions, secClientIdentity)
235235
}
236236

237-
self.applicationProtocols.forEach {
238-
sec_protocol_options_add_tls_application_protocol(options.securityProtocolOptions, $0)
237+
for applicationProtocol in self.applicationProtocols {
238+
sec_protocol_options_add_tls_application_protocol(options.securityProtocolOptions, applicationProtocol)
239239
}
240240

241241
if self.certificateVerification != .fullVerification || self.trustRoots != nil {

Tests/MQTTNIOTests/MQTTNIOTests+async.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ import NIO
1717
import NIOFoundationCompat
1818
import NIOHTTP1
1919
import XCTest
20+
21+
@testable import MQTTNIO
22+
2023
#if canImport(NIOSSL)
2124
import NIOSSL
2225
#endif
23-
@testable import MQTTNIO
2426

2527
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
2628
final class AsyncMQTTNIOTests: XCTestCase {
@@ -36,7 +38,7 @@ final class AsyncMQTTNIOTests: XCTestCase {
3638
host: Self.hostname,
3739
port: 1883,
3840
identifier: identifier,
39-
eventLoopGroupProvider: .createNew,
41+
eventLoopGroupProvider: .shared(MultiThreadedEventLoopGroup.singleton),
4042
logger: Self.logger,
4143
configuration: .init(version: version, timeout: timeout)
4244
)
@@ -91,7 +93,7 @@ final class AsyncMQTTNIOTests: XCTestCase {
9193
host: Self.hostname,
9294
port: 1883,
9395
identifier: "TestPing",
94-
eventLoopGroupProvider: .createNew,
96+
eventLoopGroupProvider: .shared(MultiThreadedEventLoopGroup.singleton),
9597
logger: Self.logger,
9698
configuration: .init(disablePing: true)
9799
)
@@ -184,7 +186,8 @@ final class AsyncMQTTNIOTests: XCTestCase {
184186
}
185187

186188
func testMQTTPublishRetain() async throws {
187-
let payloadString = #"{"from":1000000,"to":1234567,"type":1,"content":"I am a beginner in swift and I am studying hard!!测试\n\n test, message","timestamp":1607243024,"nonce":"pAx2EsUuXrVuiIU3GGOGHNbUjzRRdT5b","sign":"ff902e31a6a5f5343d70a3a93ac9f946adf1caccab539c6f3a6"}"#
189+
let payloadString =
190+
#"{"from":1000000,"to":1234567,"type":1,"content":"I am a beginner in swift and I am studying hard!!测试\n\n test, message","timestamp":1607243024,"nonce":"pAx2EsUuXrVuiIU3GGOGHNbUjzRRdT5b","sign":"ff902e31a6a5f5343d70a3a93ac9f946adf1caccab539c6f3a6"}"#
188191
let payload = ByteBufferAllocator().buffer(string: payloadString)
189192

190193
let client = self.createClient(identifier: "testMQTTPublishRetain_publisher")

0 commit comments

Comments
 (0)