Skip to content

Commit 3fc1932

Browse files
committed
add unsafelyUnwrappedPresentationAddress helpr
1 parent 1ef53eb commit 3fc1932

10 files changed

+48
-14
lines changed

Sources/SwiftOCA/OCA/Helpers/SocketAddressHelpers.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,37 @@ package extension Data {
1111
return try? socketAddress.presentationAddress
1212
}
1313
}
14+
15+
#if canImport(FlyingSocks)
16+
// this is really here to deal with the fact we can't import SocketAddress and
17+
// FlyingSocks at the same time
18+
package extension sockaddr {
19+
var unsafelyUnwrappedPresentationAddress: String {
20+
try! presentationAddress
21+
}
22+
}
23+
24+
package extension sockaddr_in {
25+
var unsafelyUnwrappedPresentationAddress: String {
26+
try! presentationAddress
27+
}
28+
}
29+
30+
package extension sockaddr_in6 {
31+
var unsafelyUnwrappedPresentationAddress: String {
32+
try! presentationAddress
33+
}
34+
}
35+
36+
package extension sockaddr_un {
37+
var unsafelyUnwrappedPresentationAddress: String {
38+
try! presentationAddress
39+
}
40+
}
41+
#endif
42+
43+
package extension SocketAddress {
44+
var unsafelyUnwrappedPresentationAddress: String {
45+
try! presentationAddress
46+
}
47+
}

Sources/SwiftOCA/OCP.1/Backend/Ocp1CFSocketConnection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ public class Ocp1CFSocketConnection: Ocp1Connection, Ocp1MutableConnection {
415415
}
416416

417417
fileprivate nonisolated var _presentationAddress: String {
418-
try! _deviceAddress.criticalState.presentationAddress
418+
_deviceAddress.criticalState.unsafelyUnwrappedPresentationAddress
419419
}
420420

421421
private var family: sa_family_t {

Sources/SwiftOCA/OCP.1/Backend/Ocp1IORingConnection.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public final class Ocp1IORingDatagramConnection: Ocp1IORingConnection {
172172
}
173173

174174
override public var connectionPrefix: String {
175-
"\(OcaUdpConnectionPrefix)/\(try! _deviceAddress.criticalState.presentationAddress)"
175+
"\(OcaUdpConnectionPrefix)/\(_deviceAddress.criticalState.unsafelyUnwrappedPresentationAddress)"
176176
}
177177

178178
override public var isDatagram: Bool { true }
@@ -249,7 +249,7 @@ public final class Ocp1IORingDomainSocketDatagramConnection: Ocp1IORingConnectio
249249
}
250250

251251
override public var connectionPrefix: String {
252-
"\(OcaLocalConnectionPrefix)/\(try! _deviceAddress.criticalState.presentationAddress)"
252+
"\(OcaLocalConnectionPrefix)/\(_deviceAddress.criticalState.unsafelyUnwrappedPresentationAddress)"
253253
}
254254

255255
override public var isDatagram: Bool { true }
@@ -293,7 +293,7 @@ public final class Ocp1IORingStreamConnection: Ocp1IORingConnection {
293293
_deviceAddress.withCriticalRegion { deviceAddress in
294294
let prefix = deviceAddress
295295
.family == AF_LOCAL ? OcaLocalConnectionPrefix : OcaTcpConnectionPrefix
296-
return "\(prefix)/\(try! deviceAddress.presentationAddress)"
296+
return "\(prefix)/\(deviceAddress.unsafelyUnwrappedPresentationAddress)"
297297
}
298298
}
299299

Sources/SwiftOCA/OCP.1/Backend/Ocp1NWConnection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public class Ocp1NWConnection: Ocp1Connection, Ocp1MutableConnection {
170170
}
171171

172172
fileprivate nonisolated var presentationAddress: String {
173-
try! _deviceAddress.criticalState.presentationAddress
173+
_deviceAddress.criticalState.unsafelyUnwrappedPresentationAddress
174174
}
175175
}
176176

Sources/SwiftOCADevice/OCP.1/Backend/CF/Ocp1CFDeviceEndpoint.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public final class Ocp1CFStreamDeviceEndpoint: Ocp1CFDeviceEndpoint,
148148
}
149149

150150
override public func run() async throws {
151-
logger.info("starting \(type(of: self)) on \(try! address.presentationAddress)")
151+
logger.info("starting \(type(of: self)) on \(address.unsafelyUnwrappedPresentationAddress)")
152152
try await super.run()
153153
socket = try await makeSocketAndListen()
154154
notificationSocket = try await makeNotificationSocket()
@@ -231,7 +231,7 @@ public class Ocp1CFDatagramDeviceEndpoint: Ocp1CFDeviceEndpoint,
231231
}
232232

233233
override public func run() async throws {
234-
logger.info("starting \(type(of: self)) on \(try! address.presentationAddress)")
234+
logger.info("starting \(type(of: self)) on \(address.unsafelyUnwrappedPresentationAddress)")
235235
try await super.run()
236236
socket = try await makeSocket()
237237
repeat {

Sources/SwiftOCADevice/OCP.1/Backend/FlyingSocks/Ocp1FlyingFoxDeviceEndpoint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public final class Ocp1FlyingFoxDeviceEndpoint: OcaDeviceEndpointPrivate,
129129
}
130130

131131
public nonisolated var description: String {
132-
"\(type(of: self))(address: \(try! address.presentationAddress), timeout: \(timeout))"
132+
"\(type(of: self))(address: \(address.unsafelyUnwrappedPresentationAddress), timeout: \(timeout))"
133133
}
134134

135135
public func run() async throws {

Sources/SwiftOCADevice/OCP.1/Backend/FlyingSocks/Ocp1FlyingSocksDatagramController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ actor Ocp1FlyingSocksDatagramController: Ocp1ControllerInternal {
9393

9494
nonisolated var identifier: String {
9595
peerAddress.withSockAddr {
96-
try! $0.pointee.presentationAddress
96+
$0.pointee.unsafelyUnwrappedPresentationAddress
9797
}
9898
}
9999

Sources/SwiftOCADevice/OCP.1/Backend/FlyingSocks/Ocp1FlyingSocksDatagramDeviceEndpoint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public final class Ocp1FlyingSocksDatagramDeviceEndpoint: OcaDeviceEndpointPriva
111111

112112
private nonisolated var presentationAddress: String {
113113
address.withSockAddr {
114-
try! $0.pointee.presentationAddress
114+
$0.pointee.unsafelyUnwrappedPresentationAddress
115115
}
116116
}
117117

Sources/SwiftOCADevice/OCP.1/Backend/FlyingSocks/Ocp1FlyingSocksStreamDeviceEndpoint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public final class Ocp1FlyingSocksStreamDeviceEndpoint: OcaDeviceEndpointPrivate
115115

116116
private nonisolated var presentationAddress: String {
117117
address.withSockAddr {
118-
try! $0.pointee.presentationAddress
118+
$0.pointee.unsafelyUnwrappedPresentationAddress
119119
}
120120
}
121121

Sources/SwiftOCADevice/OCP.1/Backend/IORing/Ocp1IORingDeviceEndpoint.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public final class Ocp1IORingStreamDeviceEndpoint: Ocp1IORingDeviceEndpoint,
156156
}
157157

158158
override public func run() async throws {
159-
logger.info("starting \(type(of: self)) on \(try! address.presentationAddress)")
159+
logger.info("starting \(type(of: self)) on \(address.unsafelyUnwrappedPresentationAddress)")
160160
try await super.run()
161161
let socket = try makeSocketAndListen()
162162
self.socket = socket
@@ -276,7 +276,7 @@ public class Ocp1IORingDatagramDeviceEndpoint: Ocp1IORingDeviceEndpoint,
276276
}
277277

278278
override public func run() async throws {
279-
logger.info("starting \(type(of: self)) on \(try! address.presentationAddress)")
279+
logger.info("starting \(type(of: self)) on \(address.unsafelyUnwrappedPresentationAddress)")
280280
try await super.run()
281281

282282
let socket = try makeSocket()
@@ -313,7 +313,7 @@ public class Ocp1IORingDatagramDeviceEndpoint: Ocp1IORingDeviceEndpoint,
313313
} catch {
314314
logger
315315
.error(
316-
"unexpected error \(error) running \(type(of: self)) event loop on \(try! address.presentationAddress); no longer servicing requests"
316+
"unexpected error \(error) running \(type(of: self)) event loop on \(address.unsafelyUnwrappedPresentationAddress); no longer servicing requests"
317317
)
318318
throw error
319319
}

0 commit comments

Comments
 (0)