Skip to content

Commit 30ab6a6

Browse files
committed
Add support for typed throws
1 parent 54beac7 commit 30ab6a6

6 files changed

Lines changed: 23 additions & 19 deletions

File tree

Sources/Socket/System/NetworkInterface.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SystemPackage
99
import CSocket
1010

1111
/// UNIX Network Interface
12-
public struct NetworkInterface <Address: SocketAddress>: Identifiable {
12+
public struct NetworkInterface <Address: SocketAddress>: Identifiable, Sendable {
1313

1414
public typealias ID = NetworkInterfaceID
1515

@@ -26,14 +26,18 @@ public struct NetworkInterface <Address: SocketAddress>: Identifiable {
2626
public let netmask: Address?
2727
}
2828

29+
extension NetworkInterface: Equatable where Address: Equatable { }
30+
31+
extension NetworkInterface: Hashable where Address: Hashable { }
32+
2933
public extension NetworkInterface {
3034

3135
static var interfaces: [Self] {
32-
get throws {
36+
get throws(Errno) {
3337
let interfaceIDs = try NetworkInterfaceID.interfaces
3438
var linkedList: UnsafeMutablePointer<CInterop.InterfaceLinkedList>? = nil
3539
guard system_getifaddrs(&linkedList) == 0 else {
36-
return []
40+
throw Errno.current
3741
}
3842
defer { system_freeifaddrs(linkedList) }
3943
var values = [Self]()
@@ -66,7 +70,7 @@ public extension NetworkInterface {
6670

6771
// MARK: - Supporting Types
6872

69-
public struct NetworkInterfaceID: Equatable, Hashable {
73+
public struct NetworkInterfaceID: Equatable, Hashable, Sendable {
7074

7175
/// Interface index.
7276
public let index: UInt32

Sources/Socket/System/SocketAddress.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ public protocol SocketAddress: Sendable {
77
associatedtype ProtocolID: SocketProtocol
88

99
/// Unsafe pointer closure
10-
func withUnsafePointer<Result>(
11-
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws -> Result
12-
) rethrows -> Result
10+
func withUnsafePointer<Result, Error>(
11+
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws(Error) -> Result
12+
) rethrows -> Result where Error: Swift.Error
1313

1414
static func withUnsafePointer(
1515
_ pointer: UnsafeMutablePointer<CInterop.SocketAddress>

Sources/Socket/System/SocketAddress/IPv4SocketAddress.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public struct IPv4SocketAddress: SocketAddress, Equatable, Hashable {
3131
)
3232
}
3333

34-
public func withUnsafePointer<Result>(
35-
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws -> Result
36-
) rethrows -> Result {
34+
public func withUnsafePointer<Result, Error>(
35+
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws(Error) -> Result
36+
) rethrows -> Result where Error: Swift.Error {
3737

3838
var socketAddress = CInterop.IPv4SocketAddress()
3939
socketAddress.sin_family = numericCast(Self.family.rawValue)

Sources/Socket/System/SocketAddress/IPv6SocketAddress.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public struct IPv6SocketAddress: SocketAddress, Equatable, Hashable {
3131
)
3232
}
3333

34-
public func withUnsafePointer<Result>(
35-
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws -> Result
36-
) rethrows -> Result {
34+
public func withUnsafePointer<Result, Error>(
35+
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws(Error) -> Result
36+
) rethrows -> Result where Error: Swift.Error {
3737

3838
var socketAddress = CInterop.IPv6SocketAddress()
3939
socketAddress.sin6_family = numericCast(Self.family.rawValue)

Sources/Socket/System/SocketAddress/LinkLayerSocketAddress.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public struct LinkLayerSocketAddress: SocketAddress, Equatable, Hashable {
5050
self.address = address
5151
}
5252

53-
public func withUnsafePointer<Result>(
54-
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32
55-
) throws -> Result) rethrows -> Result {
53+
public func withUnsafePointer<Result, Error>(
54+
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws(Error) -> Result
55+
) rethrows -> Result where Error: Swift.Error {
5656

5757
var socketAddress = CSocketAddressType()
5858
#if canImport(Darwin)

Sources/Socket/System/SocketAddress/UnixSocketAddress.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public struct UnixSocketAddress: SocketAddress, Equatable, Hashable {
2525
}
2626
}
2727

28-
public func withUnsafePointer<Result>(
29-
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws -> Result
30-
) rethrows -> Result {
28+
public func withUnsafePointer<Result, Error>(
29+
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws(Error) -> Result
30+
) rethrows -> Result where Error: Swift.Error {
3131
return try path.withPlatformString { platformString in
3232
var socketAddress = CInterop.UnixSocketAddress()
3333
socketAddress.sun_family = numericCast(Self.family.rawValue)

0 commit comments

Comments
 (0)