Skip to content

Commit d8b385c

Browse files
committed
Almost there
1 parent b1177fe commit d8b385c

13 files changed

+28
-24
lines changed

Package.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:6.0
22

33
import PackageDescription
44

@@ -19,5 +19,6 @@ let package = Package(
1919
targets: [
2020
.target(name: "SocketIO", dependencies: ["Starscream"]),
2121
.testTarget(name: "TestSocketIO", dependencies: ["SocketIO"]),
22-
]
22+
],
23+
swiftLanguageModes: [.v6]
2324
)

Source/SocketIO/Ack/SocketAckEmitter.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ public final class OnAckCallback: NSObject {
132132
socket.emit(items, ack: ackNumber, binary: binary)
133133

134134
guard seconds != 0 else { return }
135-
135+
let _ackNumber = ackNumber
136136
socket.manager?.handleQueue.asyncAfter(deadline: DispatchTime.now() + seconds) {[weak socket] in
137137
guard let socket = socket else { return }
138138

139-
socket.ackHandlers.timeoutAck(self.ackNumber)
139+
socket.ackHandlers.timeoutAck(_ackNumber)
140140
}
141141
}
142142

Source/SocketIO/Client/SocketIOClient.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import Foundation
4040
///
4141
/// **NOTE**: The client is not thread/queue safe, all interaction with the socket should be done on the `manager.handleQueue`
4242
///
43-
open class SocketIOClient: NSObject, SocketIOClientSpec {
43+
open class SocketIOClient: NSObject, SocketIOClientSpec, @unchecked Sendable {
4444
// MARK: Properties
4545

4646
/// The namespace that this socket is currently connected to.
@@ -122,7 +122,7 @@ open class SocketIOClient: NSObject, SocketIOClientSpec {
122122
/// - parameter timeoutAfter: The number of seconds after which if we are not connected we assume the connection
123123
/// has failed. Pass 0 to never timeout.
124124
/// - parameter handler: The handler to call when the client fails to connect.
125-
open func connect(withPayload payload: [String: Any]? = nil, timeoutAfter: Double, withHandler handler: (() -> ())?) {
125+
open func connect(withPayload payload: [String: Any]? = nil, timeoutAfter: Double, withHandler handler: (@Sendable () -> ())?) {
126126
assert(timeoutAfter >= 0, "Invalid timeout: \(timeoutAfter)")
127127

128128
guard let manager = self.manager, status != .connected else {

Source/SocketIO/Client/SocketIOClientSpec.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public protocol SocketIOClientSpec : AnyObject {
7777
/// - parameter timeoutAfter: The number of seconds after which if we are not connected we assume the connection
7878
/// has failed. Pass 0 to never timeout.
7979
/// - parameter handler: The handler to call when the client fails to connect.
80-
func connect(withPayload payload: [String: Any]?, timeoutAfter: Double, withHandler handler: (() -> ())?)
80+
func connect(withPayload payload: [String: Any]?, timeoutAfter: Double, withHandler handler: (@Sendable() -> ())?)
8181

8282
/// Called when the client connects to a namespace. If the client was created with a namespace upfront,
8383
/// then this is only called when the client connects to that namespace.

Source/SocketIO/Engine/SocketEngine.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import FoundationNetworking
3232
/// The class that handles the engine.io protocol and transports.
3333
/// See `SocketEnginePollable` and `SocketEngineWebsocket` for transport specific methods.
3434
open class SocketEngine: NSObject, WebSocketDelegate, URLSessionDelegate,
35-
SocketEnginePollable, SocketEngineWebsocket, ConfigSettable {
35+
SocketEnginePollable, SocketEngineWebsocket, ConfigSettable, @unchecked Sendable {
3636

3737

3838
// MARK: Properties

Source/SocketIO/Engine/SocketEnginePacketType.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import Foundation
2727

2828
/// Represents the type of engine.io packet types.
29-
public enum SocketEnginePacketType: Int {
29+
public enum SocketEnginePacketType: Int, Sendable {
3030
/// Open message.
3131
case open
3232

Source/SocketIO/Engine/SocketEnginePollable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ extension SocketEnginePollable {
119119
doLongPoll(for: req)
120120
}
121121

122-
func doRequest(for req: URLRequest, callbackWith callback: @escaping (Data?, URLResponse?, Error?) -> ()) {
122+
func doRequest(for req: URLRequest, callbackWith callback: @escaping (@Sendable(Data?, URLResponse?, Error?) -> ())) {
123123
guard polling && !closed && !invalidated && !fastUpgrade else { return }
124124

125125
DefaultSocketLogger.Logger.log("Doing polling \(req.httpMethod ?? "") \(req)", type: "SocketEnginePolling")

Source/SocketIO/Engine/SocketEngineSpec.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import FoundationNetworking
3030
#endif
3131

3232
/// Specifies a SocketEngine.
33-
public protocol SocketEngineSpec: AnyObject {
33+
public protocol SocketEngineSpec: AnyObject, Sendable {
3434
// MARK: Properties
3535

3636
/// The client for this engine.

Source/SocketIO/Manager/SocketManager.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import Foundation
4545
///
4646
/// **NOTE**: The manager is not thread/queue safe, all interaction with the manager should be done on the `handleQueue`
4747
///
48-
open class SocketManager: NSObject, SocketManagerSpec, SocketParsable, SocketDataBufferable, ConfigSettable {
48+
open class SocketManager: NSObject, SocketManagerSpec, SocketParsable, SocketDataBufferable, ConfigSettable, @unchecked Sendable {
4949
private static let logType = "SocketManager"
5050

5151
// MARK: Properties
@@ -95,16 +95,16 @@ open class SocketManager: NSObject, SocketManagerSpec, SocketParsable, SocketDat
9595
public var nsps = [String: SocketIOClient]()
9696

9797
/// If `true`, this client will try and reconnect on any disconnects.
98-
public var reconnects = true
98+
public var reconnects: Bool = true
9999

100100
/// The minimum number of seconds to wait before attempting to reconnect.
101-
public var reconnectWait = 10
101+
public var reconnectWait: Int = 10
102102

103103
/// The maximum number of seconds to wait before attempting to reconnect.
104-
public var reconnectWaitMax = 30
104+
public var reconnectWaitMax: Int = 30
105105

106106
/// The randomization factor for calculating reconnect jitter.
107-
public var randomizationFactor = 0.5
107+
public var randomizationFactor: Double = 0.5
108108

109109
/// The status of this manager.
110110
public private(set) var status: SocketIOStatus = .notConnected {

Source/SocketIO/Util/SocketLogger.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public extension SocketLogger {
6868
}
6969
}
7070

71-
class DefaultSocketLogger : SocketLogger {
72-
static var Logger: SocketLogger = DefaultSocketLogger()
71+
final class DefaultSocketLogger : SocketLogger, Sendable {
72+
static nonisolated(unsafe) var Logger: SocketLogger = DefaultSocketLogger()
7373

74-
var log = false
74+
nonisolated(unsafe) var log = false
7575
}

Tests/TestSocketIO/SocketMangerTest.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public enum ManagerExpectation: String {
201201
case emitAllEventCalled
202202
}
203203

204-
public class TestManager: SocketManager {
204+
public class TestManager: SocketManager, @unchecked Sendable {
205205
public func setCurrentReconnect(currentReconnect: Int) {
206206
self.currentReconnectAttempt = currentReconnect
207207
}
@@ -233,7 +233,7 @@ public class TestManager: SocketManager {
233233
}
234234
}
235235

236-
public class TestSocket: SocketIOClient {
236+
public class TestSocket: SocketIOClient, @unchecked Sendable {
237237
public var expectations = [ManagerExpectation: XCTestExpectation]()
238238

239239
public override func didConnect(toNamespace nsp: String, payload: [String: Any]?) {

Tests/TestSocketIO/SocketParserTest.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class SocketParserTest: XCTestCase {
127127
let testManager = SocketManager(socketURL: URL(string: "http://localhost/")!)
128128

129129
//Format key: message; namespace-data-binary-id
130-
static let packetTypes: [String: (String, [Any], [Data], Int)] = [
130+
static let packetTypes: [String: (String, [any Sendable], [Data], Int)] = [
131131
"0": ("/", [], [], -1), "1": ("/", [], [], -1),
132132
"25[\"test\"]": ("/", ["test"], [], 5),
133133
"2[\"test\",\"~~0\"]": ("/", ["test", "~~0"], [], -1),
@@ -145,3 +145,6 @@ class SocketParserTest: XCTestCase {
145145
"4[1, \"hello\"]": ("/", [1, "hello"], [], -1)
146146
]
147147
}
148+
149+
extension NSArray: @retroactive @unchecked Sendable {}
150+
extension NSDictionary: @retroactive @unchecked Sendable {}

Tests/TestSocketIO/SocketSideEffectTest.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
import FoundationNetworking
1515
#endif
1616

17-
class SocketSideEffectTest: XCTestCase {
17+
class SocketSideEffectTest: XCTestCase, @unchecked Sendable {
1818
func testInitialCurrentAck() {
1919
XCTAssertEqual(socket.currentAck, -1)
2020
}
@@ -490,7 +490,7 @@ struct ThrowingData: SocketData {
490490

491491
}
492492

493-
class TestEngine: SocketEngineSpec {
493+
class TestEngine: SocketEngineSpec, @unchecked Sendable {
494494
weak var client: SocketEngineClient?
495495
private(set) var closed = false
496496
private(set) var compress = false

0 commit comments

Comments
 (0)