Skip to content

Commit

Permalink
Add Sendable conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 14, 2024
1 parent 30ab6a6 commit 253aef8
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Sources/Socket/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public struct Socket: Sendable {
}

/// Listen for connections on a socket.
public func listen(backlog: Int = Self.maxSocketBacklog) async throws {
public func listen(backlog: Int = Self.maxBacklog) async throws {
try await manager.listen(backlog: backlog, for: fileDescriptor)
}

Expand Down Expand Up @@ -168,7 +168,7 @@ public struct Socket: Sendable {
public extension Socket {

/// Maximum queue length specifiable by listen.
static var maxSocketBacklog: Int {
static var maxBacklog: Int {
Int(_SOMAXCONN)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/SocketContinuation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import SystemPackage

#if DEBUG
internal struct SocketContinuation<T, E> where E: Error, T: Sendable {
internal struct SocketContinuation<T, E>: Sendable where E: Error, T: Sendable {

private let function: String

Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/SocketManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public protocol SocketManager: AnyObject, Sendable {
}

/// Socket Manager Configuration
public protocol SocketManagerConfiguration {
public protocol SocketManagerConfiguration: Sendable {

associatedtype Manager: SocketManager

Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/System/FileChange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public extension SocketDescriptor {
}

@usableFromInline
internal struct FileChangeID: RawRepresentable, Hashable, Codable {
internal struct FileChangeID: RawRepresentable, Hashable, Codable, Sendable {

/// The raw C file handle.
@_alwaysEmitIntoClient
Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/System/FileEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SystemPackage
/// File Events bitmask
@frozen
// @available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
public struct FileEvents: OptionSet, Hashable, Codable {
public struct FileEvents: OptionSet, Hashable, Codable, Sendable {

/// The raw C file events.
@_alwaysEmitIntoClient
Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/System/FileFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public extension FileDescriptor {

/// Options that specify behavior for file descriptors.
@frozen
struct Flags: OptionSet, Hashable, Codable {
struct Flags: OptionSet, Hashable, Codable, Sendable {

/// The raw C options.
@_alwaysEmitIntoClient
Expand Down
6 changes: 3 additions & 3 deletions Sources/Socket/System/InternetProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SystemPackage

/// Internet Protocol Address
@frozen
public enum IPAddress: Equatable, Hashable, Codable {
public enum IPAddress: Equatable, Hashable, Codable, Sendable {

/// IPv4
case v4(IPv4Address)
Expand Down Expand Up @@ -58,7 +58,7 @@ extension IPAddress: CustomStringConvertible, CustomDebugStringConvertible {

/// IPv4 Socket Address
@frozen
public struct IPv4Address: Equatable, Hashable, Codable {
public struct IPv4Address: Equatable, Hashable, Codable, Sendable {

@usableFromInline
internal let bytes: CInterop.IPv4Address
Expand Down Expand Up @@ -128,7 +128,7 @@ extension IPv4Address: CustomStringConvertible, CustomDebugStringConvertible {

/// IPv6 Socket Address
@frozen
public struct IPv6Address: Equatable, Hashable, Codable {
public struct IPv6Address: Equatable, Hashable, Codable, Sendable {

@usableFromInline
internal let bytes: CInterop.IPv6Address
Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/System/MessageFlags.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/// Message Flags
@frozen
public struct MessageFlags: OptionSet, Hashable, Codable {
public struct MessageFlags: OptionSet, Hashable, Codable, Sendable {

/// The raw C file permissions.
@_alwaysEmitIntoClient
Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/System/SocketAddressFamily.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/// POSIX Socket Address Family
@frozen
public struct SocketAddressFamily: RawRepresentable, Hashable, Codable {
public struct SocketAddressFamily: RawRepresentable, Hashable, Codable, Sendable {

/// The raw socket address family identifier.
@_alwaysEmitIntoClient
Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/System/SocketFlags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CSocket

/// Flags when opening sockets.
@frozen
public struct SocketFlags: OptionSet, Hashable, Codable {
public struct SocketFlags: OptionSet, Hashable, Codable, Sendable {

/// The raw C file events.
@_alwaysEmitIntoClient
Expand Down
6 changes: 3 additions & 3 deletions Sources/Socket/System/SocketOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public extension GenericSocketOption {

/// Enable socket debugging.
@frozen
struct Debug: BooleanSocketOption, Equatable, Hashable, ExpressibleByBooleanLiteral {
struct Debug: BooleanSocketOption, Equatable, Hashable, ExpressibleByBooleanLiteral, Sendable {

@_alwaysEmitIntoClient
public static var id: GenericSocketOption { .debug }
Expand All @@ -63,7 +63,7 @@ public extension GenericSocketOption {

/// Enable sending of keep-alive messages on connection-oriented sockets.
@frozen
struct KeepAlive: BooleanSocketOption, Equatable, Hashable, ExpressibleByBooleanLiteral {
struct KeepAlive: BooleanSocketOption, Equatable, Hashable, ExpressibleByBooleanLiteral, Sendable {

@_alwaysEmitIntoClient
public static var id: GenericSocketOption { .keepAlive }
Expand All @@ -78,7 +78,7 @@ public extension GenericSocketOption {

// Allow reuse of local addresses when binding.
@frozen
struct ReuseAddress: BooleanSocketOption, Equatable, Hashable, ExpressibleByBooleanLiteral {
struct ReuseAddress: BooleanSocketOption, Equatable, Hashable, ExpressibleByBooleanLiteral, Sendable {

@_alwaysEmitIntoClient
public static var id: GenericSocketOption { .reuseAddress }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/System/SocketOptionID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public protocol SocketOptionID: RawRepresentable {
}

@frozen
public struct GenericSocketOption: RawRepresentable, Equatable, Hashable, SocketOptionID {
public struct GenericSocketOption: RawRepresentable, Equatable, Hashable, SocketOptionID, Sendable {

@_alwaysEmitIntoClient
public static var optionLevel: SocketOptionLevel { .default }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/System/SocketOptionLevel.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// POSIX Socket Option Level
@frozen
public struct SocketOptionLevel: RawRepresentable, Hashable, Codable {
public struct SocketOptionLevel: RawRepresentable, Hashable, Codable, Sendable {

/// The raw socket address family identifier.
@_alwaysEmitIntoClient
Expand Down
2 changes: 1 addition & 1 deletion Sources/Socket/System/SocketProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/// POSIX Socket Protocol
public protocol SocketProtocol: RawRepresentable {
public protocol SocketProtocol: RawRepresentable, Sendable {

static var family: SocketAddressFamily { get }

Expand Down
13 changes: 9 additions & 4 deletions Sources/Socket/System/SocketType.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#if canImport(Darwin)
import Darwin
#endif
import SystemPackage

/// POSIX Socket Type
@frozen
public struct SocketType: RawRepresentable, Hashable, Codable {
public struct SocketType: RawRepresentable, Hashable, Sendable {

/// The raw socket type identifier.
@_alwaysEmitIntoClient
Expand All @@ -24,6 +21,14 @@ public struct SocketType: RawRepresentable, Hashable, Codable {
}
}

// MARK: - Codable

#if !hasFeature(Embedded)
extension SocketType: Codable { }
#endif

// MARK: - Constants

public extension SocketType {

/// Stream socket
Expand Down

0 comments on commit 253aef8

Please sign in to comment.