Skip to content

Commit

Permalink
refactor reconnection logic, split out into new file
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Nov 27, 2024
1 parent f0fae9e commit 2fd1b39
Show file tree
Hide file tree
Showing 12 changed files with 415 additions and 159 deletions.
1 change: 1 addition & 0 deletions Sources/SwiftOCA/OCF/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum Ocp1Error: Error, Equatable {
case invalidProtocolVersion
case invalidProxyMethodResponse
case invalidSyncValue
case missingKeepalive
case noConnectionDelegate
case noInitialValue
case noMatchingTypeForClass
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftOCA/OCP.1/Backend/Ocp1CFSocketConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,14 @@ public class Ocp1CFSocketConnection: Ocp1Connection {
deviceAddress.family
}

override func connectDevice() async throws {
override public func connectDevice() async throws {
socket = try await _CFSocketWrapper(address: deviceAddress, type: type)
try await super.connectDevice()
}

override public func disconnectDevice(clearObjectCache: Bool) async throws {
override public func disconnectDevice() async throws {
socket = nil
try await super.disconnectDevice(clearObjectCache: clearObjectCache)
try await super.disconnectDevice()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class Ocp1FlyingSocksConnection: Ocp1Connection {
try? asyncSocket?.close()
}

override func connectDevice() async throws {
override public func connectDevice() async throws {
let socket = try Socket(domain: Int32(deviceAddress.family), type: socketType)
try? setSocketOptions(socket)
// also connect UDP sockets to ensure we do not receive unsolicited replies
Expand All @@ -135,13 +135,13 @@ public class Ocp1FlyingSocksConnection: Ocp1Connection {
try await super.connectDevice()
}

override public func disconnectDevice(clearObjectCache: Bool) async throws {
override public func disconnectDevice() async throws {
await AsyncSocketPoolMonitor.shared.stop()
if let asyncSocket {
try asyncSocket.close()
self.asyncSocket = nil
}
try await super.disconnectDevice(clearObjectCache: clearObjectCache)
try await super.disconnectDevice()
}

public convenience init(
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftOCA/OCP.1/Backend/Ocp1IORingConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Ocp1IORingConnection: Ocp1Connection {
)
}

override func connectDevice() async throws {
override public func connectDevice() async throws {
let socket = try Socket(
ring: IORing.shared,
domain: deviceAddress.family,
Expand All @@ -94,9 +94,9 @@ public class Ocp1IORingConnection: Ocp1Connection {
try await super.connectDevice()
}

override public func disconnectDevice(clearObjectCache: Bool) async throws {
override public func disconnectDevice() async throws {
socket = nil
try await super.disconnectDevice(clearObjectCache: clearObjectCache)
try await super.disconnectDevice()
}

fileprivate func withMappedError<T: Sendable>(
Expand Down
Loading

0 comments on commit 2fd1b39

Please sign in to comment.