Skip to content

Commit 97c1683

Browse files
committed
Add support for typed throws
1 parent 3e64960 commit 97c1683

13 files changed

Lines changed: 94 additions & 78 deletions

Sources/Socket/System/CInternetAddress.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal extension CInternetAddress {
3333
internal extension String {
3434

3535
@usableFromInline
36-
init<T: CInternetAddress>(_ cInternetAddress: T) throws {
36+
init<T: CInternetAddress>(_ cInternetAddress: T) throws(Errno) {
3737
let cString = UnsafeMutablePointer<CChar>.allocate(capacity: T.stringLength)
3838
defer { cString.deallocate() }
3939
let success = withUnsafePointer(to: cInternetAddress) {

Sources/Socket/System/CInterop.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SystemPackage
22

3-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
3+
#if canImport(Darwin)
44
import Darwin
55
#elseif os(Linux) || os(FreeBSD) || os(Android)
66
import Glibc
@@ -65,7 +65,7 @@ public extension CInterop {
6565
/// The C `sockaddr_in6` type
6666
typealias IPv6SocketAddress = sockaddr_in6
6767

68-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
68+
#if canImport(Darwin)
6969
/// The C `sockaddr_dl` type
7070
typealias LinkLayerAddress = sockaddr_dl
7171
#elseif os(Linux)

Sources/Socket/System/Constants.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SystemPackage
22

3-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
3+
#if canImport(Darwin)
44
import Darwin
55
#elseif os(Linux) || os(FreeBSD) || os(Android)
66
import Glibc
@@ -34,7 +34,7 @@ internal var _O_NONBLOCK: CInt { O_NONBLOCK }
3434
@_alwaysEmitIntoClient
3535
internal var _O_APPEND: CInt { O_APPEND }
3636

37-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
37+
#if canImport(Darwin)
3838
@_alwaysEmitIntoClient
3939
internal var _O_SHLOCK: CInt { O_SHLOCK }
4040

@@ -60,7 +60,7 @@ internal var _O_TRUNC: CInt { O_TRUNC }
6060
@_alwaysEmitIntoClient
6161
internal var _O_EXCL: CInt { O_EXCL }
6262

63-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
63+
#if canImport(Darwin)
6464
@_alwaysEmitIntoClient
6565
internal var _O_EVTONLY: CInt { O_EVTONLY }
6666
#endif
@@ -74,7 +74,7 @@ internal var _O_NOCTTY: CInt { O_NOCTTY }
7474
internal var _O_DIRECTORY: CInt { O_DIRECTORY }
7575
#endif
7676

77-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
77+
#if canImport(Darwin)
7878
@_alwaysEmitIntoClient
7979
internal var _O_SYMLINK: CInt { O_SYMLINK }
8080
#endif
@@ -93,7 +93,7 @@ internal var _SEEK_CUR: CInt { SEEK_CUR }
9393
@_alwaysEmitIntoClient
9494
internal var _SEEK_END: CInt { SEEK_END }
9595

96-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
96+
#if canImport(Darwin)
9797
@_alwaysEmitIntoClient
9898
internal var _SEEK_HOLE: CInt { SEEK_HOLE }
9999

@@ -196,7 +196,7 @@ internal var _AF_VSOCK: CInt { AF_VSOCK }
196196
internal var _AF_ISDN: CInt { AF_ISDN }
197197
#endif
198198

199-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
199+
#if canImport(Darwin)
200200
@_alwaysEmitIntoClient
201201
internal var _AF_IMPLINK: CInt { AF_IMPLINK }
202202

@@ -341,7 +341,7 @@ internal var _SO_DONTROUTE: CInt { SO_DONTROUTE }
341341
@_alwaysEmitIntoClient
342342
internal var _SO_BROADCAST: CInt { SO_BROADCAST }
343343

344-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
344+
#if canImport(Darwin)
345345
@_alwaysEmitIntoClient
346346
internal var _SO_USELOOPBACK: CInt { SO_USELOOPBACK }
347347
#endif
@@ -381,7 +381,7 @@ internal var _MSG_WAITALL: CInt { numericCast(MSG_WAITALL) } /* wait for full re
381381
@_alwaysEmitIntoClient
382382
internal var _MSG_DONTWAIT: CInt { numericCast(MSG_DONTWAIT) } /* this message should be nonblocking */
383383

384-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
384+
#if canImport(Darwin)
385385
@_alwaysEmitIntoClient
386386
internal var _MSG_EOF: CInt { numericCast(MSG_EOF) } /* data completes connection */
387387

@@ -416,7 +416,7 @@ internal var _MSG_MORE: CInt { numericCast(MSG_MORE) }
416416

417417
@_alwaysEmitIntoClient
418418
internal var _fd_set_count: Int {
419-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
419+
#if canImport(Darwin)
420420
// __DARWIN_FD_SETSIZE is number of *bits*, so divide by number bits in each element to get element count
421421
// at present this is 1024 / 32 == 32
422422
return Int(__DARWIN_FD_SETSIZE) / 32

Sources/Socket/System/FileChange.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public extension SocketDescriptor {
77
func duplicate(
88
closeOnExec: Bool,
99
retryOnInterrupt: Bool = true
10-
) throws -> FileDescriptor {
10+
) throws(Errno) -> FileDescriptor {
1111
let fileDescriptor = try _change(
1212
closeOnExec ? .duplicateCloseOnExec : .duplicate,
1313
self.rawValue,
@@ -18,7 +18,7 @@ public extension SocketDescriptor {
1818

1919
/// Get Flags
2020
@_alwaysEmitIntoClient
21-
func getFlags(retryOnInterrupt: Bool = true) throws -> FileDescriptor.Flags {
21+
func getFlags(retryOnInterrupt: Bool = true) throws(Errno) -> FileDescriptor.Flags {
2222
let rawValue = try _change(
2323
.getFileDescriptorFlags,
2424
retryOnInterrupt: retryOnInterrupt
@@ -31,7 +31,7 @@ public extension SocketDescriptor {
3131
func setFlags(
3232
_ newValue: FileDescriptor.Flags,
3333
retryOnInterrupt: Bool = true
34-
) throws {
34+
) throws(Errno) {
3535
let _ = try _change(
3636
.setFileDescriptorFlags,
3737
newValue.rawValue,
@@ -41,7 +41,7 @@ public extension SocketDescriptor {
4141

4242
/// Get Status
4343
@_alwaysEmitIntoClient
44-
func getStatus(retryOnInterrupt: Bool = true) throws -> FileDescriptor.OpenOptions {
44+
func getStatus(retryOnInterrupt: Bool = true) throws(Errno) -> FileDescriptor.OpenOptions {
4545
let rawValue = try _change(
4646
.getStatusFlags,
4747
retryOnInterrupt: retryOnInterrupt
@@ -54,7 +54,7 @@ public extension SocketDescriptor {
5454
func setStatus(
5555
_ newValue: FileDescriptor.OpenOptions,
5656
retryOnInterrupt: Bool = true
57-
) throws {
57+
) throws(Errno) {
5858
let _ = try _change(
5959
.setStatusFlags,
6060
newValue.rawValue,

Sources/Socket/System/InputOutput/IOOperations.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension SocketDescriptor {
77
public func inputOutput<T: IOControlID>(
88
_ request: T,
99
retryOnInterrupt: Bool = true
10-
) throws {
10+
) throws(Errno) {
1111
try _inputOutput(request, retryOnInterrupt: true).get()
1212
}
1313

@@ -27,7 +27,7 @@ extension SocketDescriptor {
2727
public func inputOutput<T: IOControlInteger>(
2828
_ request: T,
2929
retryOnInterrupt: Bool = true
30-
) throws {
30+
) throws(Errno) {
3131
try _inputOutput(request, retryOnInterrupt: retryOnInterrupt).get()
3232
}
3333

@@ -47,7 +47,7 @@ extension SocketDescriptor {
4747
public func inputOutput<T: IOControlValue>(
4848
_ request: inout T,
4949
retryOnInterrupt: Bool = true
50-
) throws {
50+
) throws(Errno) {
5151
try _inputOutput(&request, retryOnInterrupt: retryOnInterrupt).get()
5252
}
5353

Sources/Socket/System/NetworkInterface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public struct NetworkInterfaceID: Equatable, Hashable {
7878
public extension NetworkInterfaceID {
7979

8080
static var interfaces: [NetworkInterfaceID] {
81-
get throws {
81+
get throws(Errno) {
8282
// get null terminated list
8383
guard let pointer = system_if_nameindex() else {
8484
throw Errno.current

Sources/Socket/System/Poll.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extension SocketDescriptor {
5757
for events: FileEvents,
5858
timeout: Int = 0,
5959
retryOnInterrupt: Bool = true
60-
) throws -> FileEvents {
60+
) throws(Errno) -> FileEvents {
6161
try _poll(
6262
events: events,
6363
timeout: CInt(timeout),
@@ -128,7 +128,7 @@ extension Array where Element == SocketDescriptor.Poll {
128128
public mutating func poll(
129129
timeout: Int = 0,
130130
retryOnInterrupt: Bool = true
131-
) throws {
131+
) throws(Errno) {
132132
guard isEmpty == false else { return }
133133
try SocketDescriptor._poll(&self, timeout: CInt(timeout), retryOnInterrupt: retryOnInterrupt).get()
134134
}

Sources/Socket/System/SocketAddress/LinkLayerSocketAddress.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Alsey Coleman Miller on 10/1/22.
66
//
77

8-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Linux)
8+
#if canImport(Darwin) || os(Linux)
99
import Foundation
1010
import SystemPackage
1111
@_implementationOnly import CSocket
@@ -15,7 +15,7 @@ public struct LinkLayerSocketAddress: SocketAddress, Equatable, Hashable {
1515

1616
public typealias ProtocolID = LinkLayerProtocol
1717

18-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
18+
#if canImport(Darwin)
1919
/// Index type
2020
public typealias Index = UInt16
2121

@@ -34,7 +34,7 @@ public struct LinkLayerSocketAddress: SocketAddress, Equatable, Hashable {
3434
public let address: String
3535

3636
internal init(_ cValue: CSocketAddressType) {
37-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
37+
#if canImport(Darwin)
3838
let index = cValue.sdl_index
3939
let address = Swift.withUnsafePointer(to: cValue) {
4040
String(cString: system_link_ntoa($0))
@@ -57,7 +57,7 @@ public struct LinkLayerSocketAddress: SocketAddress, Equatable, Hashable {
5757
) throws -> Result) rethrows -> Result {
5858

5959
var socketAddress = CSocketAddressType()
60-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
60+
#if canImport(Darwin)
6161
socketAddress.sdl_index = index
6262
self.address.withCString {
6363
system_link_addr($0, &socketAddress)

Sources/Socket/System/SocketAddressFamily.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public extension SocketAddressFamily {
5555
}
5656
#endif
5757

58-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
58+
#if canImport(Darwin)
5959
public extension SocketAddressFamily {
6060

6161
/// NetBIOS protocol

0 commit comments

Comments
 (0)