# Pitch: SocketDescriptor

**URL:** <https://forums.swift.org/t/pitch-socketdescriptor/90148>\
**Category:** System\
**Created:** [October 19, 2026, 3:50pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148 "2026-10-19T15:50:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [October 19, 2026, 3:50pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/1 "2026-10-19T15:50:09Z")

</div>

Hello, I'd like to pitch the start of socket support for \*nix-like platforms in System. [gist](https://gist.github.com/milseman/c482e9b8584a1ac596b700bac8500da6).

# Socket Descriptors for Swift System

- Proposal: SYS-NNNN
- Authors: [Michael Ilseman](https://github.com/milseman), [Karoy Lorentey](https://github.com/lorentey), [Franz Busch](https://github.com/FranzBusch)
- Review Manager: TBD
- Status: **Draft**
- Implementation: TBD
- Review: TBD

#### Revision history

- **v1** Initial version

## Introduction

We propose adding support for socket programming to Swift System, allowing systems-level Swift programs to create, configure, and communicate over network and local sockets on Darwin, Linux, and other Unix-ish platforms.

This proposal is the first step: `SocketDescriptor` and nested types for the constants that socket calls take.

Future proposals will pitch more types, more constants, and more syscalls related to sockets.

## Motivation

Socket programming is essential for building networked applications, servers, and systems software. Currently, this functionality is accessed through imported C APIs, which are error-prone and unwieldy.

### More portable constant spellings

This pitch is just focused on a handful of the essential socket types and their corresponding constants, with other types, constants, and actual socket operations coming in a future pitch. Even with this limited subset, we can see potential for cleanup.

[swift-corelibs-foundation plays an import dance](https://github.com/swiftlang/swift-corelibs-foundation/blob/4b9721131c9845ab393f9fa63289c7a106e4594d/Sources/Foundation/Port.swift#L103-L134) to define a couple of constants:

```swift
#if canImport(Darwin)
import Darwin
fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM
fileprivate let FOUNDATION_IPPROTO_TCP = IPPROTO_TCP
#endif

#if canImport(Glibc) && !os(OpenBSD) && !os(FreeBSD)
@preconcurrency import Glibc
fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue)
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
#endif

#if canImport(Musl)
@preconcurrency import Musl
fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
#endif

#if canImport(Glibc) && (os(OpenBSD) || os(FreeBSD))
@preconcurrency import Glibc
fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
fileprivate let INADDR_ANY: in_addr_t = 0
fileprivate let INADDR_LOOPBACK = 0x7f000001
#endif

#if canImport(Android)
@preconcurrency import Android
fileprivate let FOUNDATION_SOCK_STREAM = Int32(Android.SOCK_STREAM)
fileprivate let FOUNDATION_IPPROTO_TCP = Int32(Android.IPPROTO_TCP)
fileprivate let INADDR_ANY: in_addr_t = 0
#endif

```

With this proposal, that can be simplified to:

```swift
import SystemPackage

fileprivate let FOUNDATION_SOCK_STREAM = SocketDescriptor.ConnectionType.stream.rawValue
fileprivate let FOUNDATION_IPPROTO_TCP = SocketDescriptor.ProtocolID.tcp.rawValue

```

(The `INADDR_ANY` and `INADDR_LOOPBACK` definitions remain until socket addresses are pitched.)

Similarly, [in swift-nio we find](https://github.com/apple/swift-nio/blob/48554ed8a998e9a23ad436e59d1703c69462278c/Sources/NIOPosix/Linux.swift#L182-L191):

```swift
#if os(Android)
static let SOCK_CLOEXEC = Android.SOCK_CLOEXEC
static let SOCK_NONBLOCK = Android.SOCK_NONBLOCK
#elseif canImport(Musl)
static let SOCK_CLOEXEC = Musl.SOCK_CLOEXEC
static let SOCK_NONBLOCK = Musl.SOCK_NONBLOCK
#else
static let SOCK_CLOEXEC = CInt(bitPattern: Glibc.SOCK_CLOEXEC.rawValue)
static let SOCK_NONBLOCK = CInt(bitPattern: Glibc.SOCK_NONBLOCK.rawValue)
#endif

```

With this proposal:

```swift
static let SOCK_CLOEXEC = SocketDescriptor.OpenOptions.closeOnExec.rawValue
static let SOCK_NONBLOCK = SocketDescriptor.OpenOptions.nonBlocking.rawValue

```

[swift-nio also defines the `shutdown` constants](https://github.com/apple/swift-nio/blob/9cb66c6d7a636fef586a93a15827eb247f1c12e9/Sources/NIOPosix/System.swift#L456-L512) once per C library (excerpt):

```swift
#if canImport(Darwin)
static let SHUT_RD: CInt = CInt(Darwin.SHUT_RD)
static let SHUT_WR: CInt = CInt(Darwin.SHUT_WR)
static let SHUT_RDWR: CInt = CInt(Darwin.SHUT_RDWR)
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(OpenBSD)
#if canImport(Glibc)
static let SHUT_RD: CInt = CInt(Glibc.SHUT_RD)
static let SHUT_WR: CInt = CInt(Glibc.SHUT_WR)
static let SHUT_RDWR: CInt = CInt(Glibc.SHUT_RDWR)
#elseif canImport(Musl)
static let SHUT_RD: CInt = CInt(Musl.SHUT_RD)
static let SHUT_WR: CInt = CInt(Musl.SHUT_WR)
static let SHUT_RDWR: CInt = CInt(Musl.SHUT_RDWR)
#elseif canImport(Android)
static let SHUT_RD: CInt = CInt(Android.SHUT_RD)
static let SHUT_WR: CInt = CInt(Android.SHUT_WR)
static let SHUT_RDWR: CInt = CInt(Android.SHUT_RDWR)
#endif
#else
// Windows
#endif

```

With this proposal, the Unix branches become:

```swift
static let SHUT_RD = SocketDescriptor.ShutdownKind.read.rawValue
static let SHUT_WR = SocketDescriptor.ShutdownKind.write.rawValue
static let SHUT_RDWR = SocketDescriptor.ShutdownKind.readWrite.rawValue

```

And of course, as more socket API is added, the use sites of these constants will improve (and we can drop the `.rawValue` at that point).

### Checking that a descriptor is a socket

One operation that we do pitch here is testing if a file descriptor is a socket.

Today, System can tell whether a file descriptor refers to a socket, using `stat` ([SYS-0006](https://github.com/apple/swift-system/blob/main/Proposals/0006-system-stat.md)):

```swift
guard try fd.stat().type == .socket else { throw Errno.notSocket }
// `fd` is still a `FileDescriptor`; nothing in its type says it's a socket

```

With this proposal, the check produces a value whose type says it's a socket:

```swift
let socket = try SocketDescriptor(fd) // throws Errno.notSocket or Errno.badFileDescriptor

```

## Proposed solution

We introduce `SocketDescriptor`, a descriptor type that is known to refer to a socket, and six nested types for the constants that socket calls take: `Domain`, `ConnectionType` and `ProtocolID` (the arguments to `socket()`), `OpenOptions` (flags applied when a socket is created or accepted), `MessageFlags` (flags for sending and receiving) and `ShutdownKind` (the argument to `shutdown()`). Socket operations, addresses and options come in future pitches (see **Future directions** ).

## Detailed design

See the **Appendix** for a table of Swift API to C mappings.

All API is `@_alwaysEmitIntoClient`, except `SocketDescriptor.init(_:)`, which calls `getsockopt`, and the `description` properties, which follow `FileDescriptor.OpenOptions` and are ordinary `public` API.

### SocketDescriptor

```swift
/// A socket descriptor.
///
/// A `SocketDescriptor` is a type-safe wrapper around an operating system
/// socket handle.
///
/// Unlike `FileDescriptor`, a `SocketDescriptor` explicitly represents a
/// socket rather than a general file descriptor.
@frozen
public struct SocketDescriptor: RawRepresentable, Sendable, Hashable, Codable {
  /// The raw C socket handle.
  public let rawValue: CInt

  /// Creates a strongly-typed socket descriptor from a raw C socket handle.
  public init(rawValue: CInt)

  /// The file descriptor for this socket.
  public var fileDescriptor: FileDescriptor { get }

  /// Creates a socket descriptor from a file descriptor, verifying that the
  /// file descriptor refers to a socket.
  ///
  /// If `fd` is open but doesn't refer to a socket, this initializer throws
  /// `Errno.notSocket`. If `fd` isn't open, it throws `Errno.badFileDescriptor`.
  ///
  /// The corresponding C function is `getsockopt` with the `SO_TYPE` option.
  public init(_ fd: FileDescriptor) throws(Errno)

  /// Creates a socket descriptor from a file descriptor without verification.
  ///
  /// This initializer does not verify that the file descriptor actually
  /// refers to a socket.
  public init(unchecked fd: FileDescriptor)
}

```

### Domain

```swift
extension SocketDescriptor {
  /// Communications domain, identifying the protocol family.
  ///
  /// The domain specifies the protocol family to be used for communication.
  /// Common domains include `.ipv4` for IPv4, `.ipv6` for IPv6, and `.local`
  /// for Unix domain sockets.
  @frozen
  public struct Domain: RawRepresentable, Sendable, Hashable, Codable {
    public var rawValue: CInt
    public init(rawValue: CInt)

    /// Unspecified domain.
    ///
    /// The corresponding C constants are `AF_UNSPEC` and `PF_UNSPEC`.
    public static var unspecified: Domain { get }

    /// Local (Unix domain) communication.
    ///
    /// The corresponding C constants are `AF_LOCAL` and `PF_LOCAL`.
    public static var local: Domain { get }

    /// Local (Unix domain) communication; the same value as `local`.
    ///
    /// The corresponding C constants are `AF_UNIX` and `PF_UNIX`.
    public static var unix: Domain { get }

    /// Internet Protocol version 4.
    ///
    /// The corresponding C constants are `AF_INET` and `PF_INET`.
    public static var ipv4: Domain { get }

    /// Internet Protocol version 6.
    ///
    /// The corresponding C constants are `AF_INET6` and `PF_INET6`.
    public static var ipv6: Domain { get }

    #if !os(Linux) && !os(Android)
    /// Internal routing protocol.
    ///
    /// The corresponding C constants are `AF_ROUTE` and `PF_ROUTE`.
    public static var routing: Domain { get }
    #endif

    /// Internal key-management function.
    ///
    /// The corresponding C constant is `PF_KEY`.
    public static var keyManagement: Domain { get }

    #if SYSTEM_PACKAGE_DARWIN || os(Linux) || os(Android)
    /// Communication between a virtual machine and its host.
    ///
    /// The corresponding C constants are `AF_VSOCK` and `PF_VSOCK`.
    public static var vsock: Domain { get }
    #endif

    #if os(Linux) || os(Android)
    /// Raw packets at the device-driver level.
    ///
    /// The corresponding C constants are `AF_PACKET` and `PF_PACKET`.
    public static var packet: Domain { get }
    #endif

    #if SYSTEM_PACKAGE_DARWIN
    /// Kernel event and kernel control messages.
    ///
    /// The corresponding C constants are `AF_SYSTEM` and `PF_SYSTEM`.
    public static var system: Domain { get }

    /// Raw access to network device.
    ///
    /// The corresponding C constants are `AF_NDRV` and `PF_NDRV`.
    public static var networkDevice: Domain { get }
    #endif
  }
}

```

### ConnectionType

```swift
extension SocketDescriptor {
  /// The socket type, specifying the semantics of communication.
  ///
  /// The connection type determines how data is transmitted. Stream sockets
  /// provide reliable, ordered byte streams, while datagram sockets provide
  /// connectionless, unreliable messages.
  @frozen
  public struct ConnectionType: RawRepresentable, Sendable, Hashable, Codable {
    public var rawValue: CInt
    public init(rawValue: CInt)

    /// Sequenced, reliable, two-way, connection-based byte streams.
    ///
    /// The corresponding C constant is `SOCK_STREAM`.
    public static var stream: ConnectionType { get }

    /// Connectionless, unreliable datagrams of a fixed maximum length.
    ///
    /// The corresponding C constant is `SOCK_DGRAM`.
    public static var datagram: ConnectionType { get }

    /// Raw network protocol access.
    ///
    /// The corresponding C constant is `SOCK_RAW`.
    public static var raw: ConnectionType { get }

    #if os(Linux) || os(Android)
    /// Reliably-delivered message.
    ///
    /// The corresponding C constant is `SOCK_RDM`.
    public static var reliablyDeliveredMessage: ConnectionType { get }
    #endif

    #if !SYSTEM_PACKAGE_DARWIN
    /// Sequenced packet stream.
    ///
    /// The corresponding C constant is `SOCK_SEQPACKET`.
    public static var sequencedPacketStream: ConnectionType { get }
    #endif
  }
}

```

### ProtocolID

```swift
extension SocketDescriptor {
  /// Identifies a particular protocol to use for communication.
  ///
  /// Protocol numbers are specific to the communication domain.
  @frozen
  public struct ProtocolID: RawRepresentable, Sendable, Hashable, Codable {
    public var rawValue: CInt
    public init(rawValue: CInt)

    /// Default protocol for the domain and socket type.
    public static var `default`: ProtocolID { get }

    /// Internet Protocol (IP).
    ///
    /// The corresponding C constant is `IPPROTO_IP`.
    public static var ip: ProtocolID { get }

    /// IPv4 encapsulation.
    ///
    /// The corresponding C constant is `IPPROTO_IPV4`, or `IPPROTO_IPIP` on
    /// Linux and Android.
    public static var ipv4: ProtocolID { get }

    /// IPv6 header.
    ///
    /// The corresponding C constant is `IPPROTO_IPV6`.
    public static var ipv6: ProtocolID { get }

    /// Internet Control Message Protocol.
    ///
    /// The corresponding C constant is `IPPROTO_ICMP`.
    public static var icmp: ProtocolID { get }

    /// Transmission Control Protocol (TCP).
    ///
    /// The corresponding C constant is `IPPROTO_TCP`.
    public static var tcp: ProtocolID { get }

    /// User Datagram Protocol (UDP).
    ///
    /// The corresponding C constant is `IPPROTO_UDP`.
    public static var udp: ProtocolID { get }

    /// Raw IP packet.
    ///
    /// The corresponding C constant is `IPPROTO_RAW`.
    public static var raw: ProtocolID { get }

    #if os(Linux) || os(Android)
    /// Multipath TCP.
    ///
    /// The corresponding C constant is `IPPROTO_MPTCP`.
    public static var mptcp: ProtocolID { get }
    #endif
  }
}

```

### MessageFlags

```swift
extension SocketDescriptor {
  /// Flags for send and receive operations.
  @frozen
  public struct MessageFlags: OptionSet, Sendable, Hashable, Codable {
    public var rawValue: CInt
    public init(rawValue: CInt)

    /// Process out-of-band data.
    ///
    /// The corresponding C constant is `MSG_OOB`.
    public static var outOfBand: MessageFlags { get }

    #if !os(OpenBSD)
    /// Bypass routing, use direct interface.
    ///
    /// The corresponding C constant is `MSG_DONTROUTE`.
    public static var doNotRoute: MessageFlags { get }
    #endif

    /// Peek at incoming message without removing it.
    ///
    /// The corresponding C constant is `MSG_PEEK`.
    public static var peek: MessageFlags { get }

    /// Wait for full request or error.
    ///
    /// The corresponding C constant is `MSG_WAITALL`.
    public static var waitForAll: MessageFlags { get }

    /// End-of-record marker.
    ///
    /// The corresponding C constant is `MSG_EOR`.
    public static var endOfRecord: MessageFlags { get }

    /// Data was truncated.
    ///
    /// The corresponding C constant is `MSG_TRUNC`.
    public static var dataTruncated: MessageFlags { get }

    /// Control data was truncated.
    ///
    /// The corresponding C constant is `MSG_CTRUNC`.
    public static var controlTruncated: MessageFlags { get }

    /// Do not generate `SIGPIPE` on broken pipe; the operation fails with
    /// `Errno.brokenPipe` instead.
    ///
    /// The corresponding C constant is `MSG_NOSIGNAL`.
    public static var noSignal: MessageFlags { get }

    #if os(Linux) || os(Android) || os(FreeBSD) || os(OpenBSD)
    /// Set close-on-exec on file descriptors received in ancillary data.
    ///
    /// The corresponding C constant is `MSG_CMSG_CLOEXEC`.
    public static var receivedDescriptorsCloseOnExec: MessageFlags { get }
    #endif

    #if os(FreeBSD) || os(OpenBSD)
    /// Set close-on-fork on file descriptors received in ancillary data.
    ///
    /// The corresponding C constant is `MSG_CMSG_CLOFORK`.
    public static var receivedDescriptorsCloseOnFork: MessageFlags { get }
    #endif
  }
}

```

### ShutdownKind

```swift
extension SocketDescriptor {
  /// Specifies which parts of a full-duplex connection to shut down.
  @frozen
  public struct ShutdownKind: RawRepresentable, Sendable, Hashable, Codable {
    public var rawValue: CInt
    public init(rawValue: CInt)

    /// Disallow further receives.
    ///
    /// The corresponding C constant is `SHUT_RD`.
    public static var read: ShutdownKind { get }

    /// Disallow further sends.
    ///
    /// The corresponding C constant is `SHUT_WR`.
    public static var write: ShutdownKind { get }

    /// Disallow further sends and receives.
    ///
    /// The corresponding C constant is `SHUT_RDWR`.
    public static var readWrite: ShutdownKind { get }
  }
}

```

### OpenOptions

```swift
extension SocketDescriptor {
  /// Options that specify behavior for a newly created or accepted socket,
  /// applied atomically when the socket is created or accepted.
  @frozen
  public struct OpenOptions: OptionSet, Sendable, Hashable, Codable {
    public var rawValue: CInt
    public init(rawValue: CInt)

    #if !SYSTEM_PACKAGE_DARWIN
    /// Indicates that all subsequent input and output operations on the
    /// socket will be nonblocking.
    ///
    /// The corresponding C constant is `SOCK_NONBLOCK`.
    public static var nonBlocking: OpenOptions { get }

    /// Indicates that executing a program closes the socket.
    ///
    /// The corresponding C constant is `SOCK_CLOEXEC`.
    public static var closeOnExec: OpenOptions { get }
    #endif

    #if os(FreeBSD) || os(OpenBSD)
    /// Indicates that forking a program closes the socket.
    ///
    /// The corresponding C constant is `SOCK_CLOFORK`.
    public static var closeOnFork: OpenOptions { get }
    #endif
  }
}

```

### Descriptions

Each of the six constant types conforms to `CustomStringConvertible` and `CustomDebugStringConvertible`, as `FileDescriptor.AccessMode` and `FileDescriptor.OpenOptions` do. A value prints as its constant's name (`stream`); an option set prints as a list (`[.peek, .waitForAll]`); bits or values with no named constant print as the type and raw value (`ConnectionType(rawValue: 10)`). Where two names share a value, the description uses `local` and `default`.

### Platform availability

Constants not available on every platform, either because the platform's C library doesn't define them or because its kernel doesn't support them:

| Constant | Darwin | Linux | Android | FreeBSD | OpenBSD |
| --- | --- | --- | --- | --- | --- |
| `routing` | yes | no | no | yes | yes |
| `vsock` | yes | yes | yes | no | no |
| `packet` | no | yes | yes | no | no |
| `system`, `networkDevice` | yes | no | no | no | no |
| `reliablyDeliveredMessage` | no | yes | yes | no | no |
| `sequencedPacketStream` | no | yes | yes | yes | yes |
| `doNotRoute` | yes | yes | yes | yes | no |
| `mptcp` | no | yes | yes | no | no |
| `receivedDescriptorsCloseOnExec` | no | yes | yes | yes | yes |
| `receivedDescriptorsCloseOnFork` | no | no | no | yes | yes |
| `nonBlocking`, `closeOnExec` | no | yes | yes | yes | yes |
| `closeOnFork` | no | no | no | yes | yes |

On Darwin, `OpenOptions` has no members: Darwin doesn't support creating or accepting a socket with these options atomically.

## Source compatibility

This proposal is additive and source-compatible with existing code. It adds one top-level name, `SocketDescriptor`; the other types are nested in it.

## ABI compatibility

This proposal is additive and ABI-compatible with existing code.

## Implications on adoption

This feature can be freely adopted and un-adopted in source code without affecting source or ABI compatibility.

Constants are available only on the platforms whose C libraries define them and whose kernels support them (see **Platform availability** ). Cross-platform code guards those uses with `#if`, as it already does for `FileDescriptor.PipeOptions.closeOnFork`.

## Future directions

### Socket operations, addresses, and options

Here's a rough breakdown of what socket functionality could come in future pitches:

| Proposal | Contents |
| --- | --- |
| Socket addresses | `SocketAddress` and its IPv4, IPv6 and Unix-domain forms |
| Socket operations | `open`, `close`, `bind`, `listen`, `accept`, `connect`, `send`, `receive`, `shutdown`, local and peer address, socket pairs |
| Socket options | `getsockopt` and `setsockopt`: settings on an existing socket, such as `SO_REUSEADDR`, `SO_RCVBUF`, `TCP_NODELAY` and `IP_TTL` |
| Address resolution | `getaddrinfo`, `getnameinfo` |
| Messages | `sendmsg`, `recvmsg`, ancillary data |
| `IORing` socket requests | Linux |
| Windows sockets | Winsock, alongside the `Win32` proposals |

### WASI

Supporting WASI is future work. wasi-libc defines a subset of these constants, and what sockets can do on WASI depends on its version: WASI 0.2 and later can create IPv4 and IPv6 sockets, while preview 1 can only use sockets provided by the host.

## Alternatives considered

### Extension on FileDescriptor

We considered adding socket operations directly to `FileDescriptor`:

```swift
extension FileDescriptor {
    public func bind(to address: SocketAddress) throws
    public func listen(backlog: Int) throws
    // ...
}

```

This approach has drawbacks:

- **Namespace pollution** : Socket operations would clutter `FileDescriptor`'s API for non-socket uses
- **Type safety** : Nothing prevents calling `listen()` on a regular file
- **Intent documentation** : A separate type makes socket usage explicit

We chose `SocketDescriptor` for cleaner namespacing, better type safety, and clearer documentation of intent.

### Noncopyable `SocketDescriptor`

We considered making `SocketDescriptor` `~Copyable`. We instead propose a copyable `SocketDescriptor`, following `FileDescriptor`.

The benefit of a noncopyable descriptor is that the compiler prevents double close and use-after-close. These bugs are dangerous because a closed descriptor's number can be reused immediately by an unrelated `open`, `socket`, or `accept`, so a stale descriptor silently refers to the wrong resource.

However, descriptors in the general case do not have lifetimes that can be statically modeled with non-copyable types. The OS manages descriptor lifetimes dynamically, through explicit calls such as `dup` and `close` and by passing descriptors between processes. A noncopyable type can express only a subset of these lifetimes: it defines out some bugs, but it also defines out important and plausible uses. For example, I/O code may keep the same descriptor in several places at once, such as an event loop's registry and a connection object. Some descriptors (e.g. received by C code), may have no clear owner in the program at all.

System's lifetime support facilities should be an opt-in to greater-but-constrained safety, not an opt-out that removes all the other guards. With only a noncopyable `SocketDescriptor`, code that doesn't fit a statically-linear lifetime model would drop down to the raw `CInt`, giving up System's strong types, `Errno` errors, and `EINTR` retry along with lifetime checking.

This is especially important for incremental adoption: a copyable type can be adopted one call site at a time. A noncopyable one potentially requires rearchitecting major portions of code. If incremental adoption entails frequent use of escape hatches, it can create a situation where the net result is less safe (akin to ["Cross-Language Attacks," NDSS 2022](https://www.ndss-symposium.org/wp-content/uploads/2022-78-paper.pdf)).

System is a strongly typed, error-throwing, but faithful representation of low-level OS concepts. It is not a end-developer-facing library for I/O. Libraries built on System, which typically present their own (sometimes cross-platform) I/O abstractions, are better placed to define their common path and the lifetime model that fits those abstractions, as well as their escape hatches.

Future work could include an additional higher-level owned type, owning wrappers, etc. For example, System today has the opt-in `FileDescriptor.closeAfter(_:)`, which predates non-copyable types. Furthermore, dependent-lifetime types in Swift (still under development) could provide an even better model for opt-in facilities in System and/or for those future I/O libraries to use.

### Other names for `OpenOptions`

Some alternative names could be: `SocketFlags`, `CreationOptions`, `TypeFlags`, etc.

`OpenOptions` follows `FileDescriptor.OpenOptions`, `PipeOptions` and `DuplicateOptions`, named for the call that takes them.

### `OpenOptions` unavailable on Darwin

Since `OpenOptions` has no members on Darwin, it could be unavailable there instead. This proposal keeps the type available on every platform so that API taking `options:`, such as a future `open` or `accept`, has the same signature everywhere: cross-platform code can pass `[]`, or options built under `#if`, without guarding the call itself. Platform differences live in which members exist, as with `FileDescriptor.PipeOptions`, whose `closeOnFork` is unavailable on Linux.

### Other names for `ConnectionType`

`datagram` and `raw` are connectionless, so the name `ConnectionType` fits only some of its members. C and POSIX call this argument the socket _type_, and the GNU C Library manual calls it the _communication style_. Alternatives include `Style`, `Semantics` and `Kind`; `SocketType` would repeat `Socket` inside `SocketDescriptor`. This proposal keeps `ConnectionType`, the name used by earlier drafts of this API.

### `routing` on Linux

On Darwin and the BSDs, `PF_ROUTE` is the routing socket. On Linux, `PF_ROUTE` is defined as `PF_NETLINK`, a general kernel messaging family whose routing protocol uses a different message format, so code written for the routing socket wouldn't work there. This proposal makes `routing` unavailable on Linux and Android. Alternatives were to keep `routing` available everywhere with a note, or to add a separate `netlink` constant for Linux.

## Open questions

1. The name `OpenOptions` ( **Other names for `OpenOptions`** ).
2. Names for `MSG_CMSG_CLOEXEC` and `MSG_CMSG_CLOFORK`, which set close-on-exec or close-on-fork on file descriptors received over a Unix-domain socket. Candidates: `receivedDescriptorsCloseOnExec` (this proposal), `closeOnExecForReceivedDescriptors` (groups with `OpenOptions.closeOnExec` in completion), `controlMessageCloseOnExec` (follows the C name).

## Appendix

### Swift API to C mappings

| Swift | C |
| --- | --- |
| `SocketDescriptor.init(_:)` | `getsockopt(fd, SOL_SOCKET, SO_TYPE, ...)` |
| `Domain` | `AF_*` and `PF_*` |
| `ConnectionType` | `SOCK_STREAM`, `SOCK_DGRAM`, `SOCK_RAW`, `SOCK_RDM`, `SOCK_SEQPACKET` |
| `ProtocolID` | `IPPROTO_*` |
| `MessageFlags` | `MSG_*` |
| `ShutdownKind` | `SHUT_*` |
| `OpenOptions` | `SOCK_NONBLOCK`, `SOCK_CLOEXEC`, `SOCK_CLOFORK` |

### Other descriptor kinds

We are not yet pitching these, but for illustration purposes here are some other descriptor-like types in System's future:

```swift
/// A descriptor that refers to a terminal.
@frozen
public struct TerminalDescriptor: RawRepresentable, Sendable, Hashable, Codable {
  public let rawValue: CInt
  public init(rawValue: CInt)

  /// The file descriptor for this terminal.
  public var fileDescriptor: FileDescriptor { get }

  /// Throws `Errno.inappropriateIOCTLForDevice` if `fd` isn't a terminal.
  ///
  /// The corresponding C function is `isatty`.
  public init(_ fd: FileDescriptor) throws(Errno)

  public init(unchecked fd: FileDescriptor)
}

/// A descriptor that refers to an open directory.
@frozen
public struct DirectoryDescriptor: RawRepresentable, Sendable, Hashable, Codable {
  public let rawValue: CInt
  public init(rawValue: CInt)

  /// The file descriptor for this directory.
  public var fileDescriptor: FileDescriptor { get }

  /// Throws `Errno.notDirectory` if `fd` isn't a directory.
  ///
  /// The corresponding C function is `fstat`.
  public init(_ fd: FileDescriptor) throws(Errno)

  public init(unchecked fd: FileDescriptor)
}

```

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [October 19, 2026, 6:57pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/2 "2026-10-19T18:57:19Z")

</div>

From a quick glance, there are some things about this that confuse me.

Is this meant to be for a specific API set or host set? That is, it seems that the API surface is pretty much BSD Sockets API. As such, why limit it to Unix platforms? Why not make it generic to BSD Sockets? Is there a more comprehensive plan here that is not mentioned?

Is there an implicit requirement here that is not being made explicit about the expectations of the socket descriptor? i.e. that it should be freely convertible between a file descriptor and a socket descriptor?

WinSock is a pure user space library that provides a BSD Sockets API, so the API surface it provides is similar even though the implementation is not. One of the more interesting aspects with WinSock that matters here is that the type mapping is not identical and was the primary source of friction for NIO. As such, I think that it would be better for portability to ensure that WinSock is covered in the initial draft rather than as a "future direction".

---

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [October 24, 2026, 5:41pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/3 "2026-10-24T17:41:45Z")

</div>

You're right that I should have been more explicit about what platforms we're supporting now vs deferring as future work.

From a technical and design perspective, I think that Windows is severable. However, it makes sense to talk a little about as it could inform some naming decisions. Windows shares a lot of similar surface area and there would be a lot of benefit to unify across them, especially for the constants. However, Windows sockets are different and pull in potentially different design decisions that I don't think have to be answered for SocketDescriptor on Unix-like platforms to be designed and even shipped. E.g. Windows sockets are not backed by file descriptors, not even through UCRT.

There are multiple possible directions here. One might be that `SocketDescriptor` holds a `SOCKET` for Windows so that the shared calls between platforms have a shared API. Another direction could be that it deserves a different design and treatment inside the `Win32` namespace the way file handles are. Either way, there's opportunity to eliminate a lot of `#if` dance through shared constants.

If we defer Windows for now and later decide to have `SocketDescriptor` hold a `SOCKET`, then we haven't lost anything from the deferral. Similarly, if we defer and later decide that Windows is better served from a different approach more akin to file handles under `Win32` namespace, we can still host constants and options in the `SocketDescriptor` namespace by having `SocketDescriptor` be a caseless enum on Windows.

I do want to get the constants and options and such reviewed and avaible for Windows ASAP. I'm not sure the best route to unblock this without pulling in a lot of other unrelated concerns and decisions.

---

<div class="post-metadata">

**Author:** ![ksluder](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@ksluder](https://forums.swift.org/u/ksluder)\
**Post date:** [October 24, 2026, 6:29pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/4 "2026-10-24T18:29:15Z")

</div>

Isn’t the recommended path on Darwin to [use Network.framework instead of BSD sockets](https://developer.apple.com/videos/play/wwdc2018/715)?

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [October 24, 2026, 7:29pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/5 "2026-10-24T19:29:12Z")

</div>

Yes, but Network.framework still uses sockets under the hood, it just also does a bunch of extra work to automatically support things like multi path TCP and Network Extension integration. If Apple wanted to rewrite it in Swift natively, they'd need core Swift primitives like this.

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [October 25, 2026, 12:02am UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/6 "2026-10-25T00:02:21Z")

</div>

> [@Michael\_Ilseman](#):
>
> E.g. Windows sockets are not backed by file descriptors, not even through UCRT.

Sure, but then I would ask what is special about a file descriptor? What makes it truly unique? Ultimately, the concept is the same - `SOCKET` is a spelling for a descriptor. What makes `int` (or if you prefer `CInt`) so special that it should be deemed to be the only viable answer for the descriptor?

I think that there might be some value in changing `SocketDescriptor` to use an `associatedtype` to a protocol for `DescriptorType` and replace the `fileDescriptor` to `descriptor` which then makes it agnostic to the implementation.

In fact, I think that this design is much more interesting - consider embedded systems where there may be interest in using lwIP instead of an OS provided networking stack. The same questions that Windows raises would be present there. Ultimately, the difference is simply that Windows provides a user space library that provides networking support.

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [October 25, 2026, 1:03am UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/7 "2026-10-25T01:03:52Z")

</div>

> [@Jon\_Shier](#):
>
> Yes, but Network.framework still uses sockets under the hood

Very rarely (if ever) these days; normally it's user space networking instead of sockets.

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [October 25, 2026, 3:36am UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/8 "2026-10-25T03:36:32Z")

</div>

Network.framework goes through the user-space networking, but everything leaves the device either through a socket or a kernel channel (shared memory tx/rx ring, zero copy, minimal syscalls).

> **Here's a generated diagram based on disassembly, macOS 27.0.1**
>
> ![Screenshot 2026-10-24 at 11.33.43 PM](https://global.discourse-cdn.com/swift/original/3X/4/d/4d1aca6d7bd9d9896b5333c22d7b9ae0abd73f99.jpeg)

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [October 25, 2026, 8:23pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/9 "2026-10-25T20:23:38Z")

</div>

Nice! But on your diagram BSD sockets path is labelled as "default-data carrying path". I don't think this is the case in the recent years (since ~macOS 12 / 2021).

> **Corrected and simplified diagram**
>
> ![image](https://global.discourse-cdn.com/swift/original/3X/b/4/b49e2f3384d8fe0bdb37f7ac966f6fc9a67fdf7b.jpeg)

---

<div class="post-metadata">

**Author:** ![jrflat](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrflat/32/31407_2.png) [@jrflat](https://forums.swift.org/u/jrflat)\
**Post date:** [October 26, 2026, 2:20am UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/10 "2026-10-26T02:20:43Z")

</div>

Very excited to see this work! The constants look great.

I believe `SocketDescriptor`, and future descriptor types in `swift-system`, should be noncopyable.

> [@Michael\_Ilseman](#):
>
> The benefit of a noncopyable descriptor is that the compiler prevents double close and use-after-close. These bugs are dangerous because a closed descriptor's number can be reused immediately by an unrelated `open`, `socket`, or `accept`, so a stale descriptor silently refers to the wrong resource.

I'd argue the danger of a stale descriptor is too great not to provide lifetime safety from the start. A use-after-close could send one client's data to another, so we should use every compile-time tool we have to prevent it. We should also give the noncopyable type the simple name so clients reach for it first. I don't think the arguments for a copyable type outweigh this:

> [@Michael\_Ilseman](#):
>
> However, descriptors in the general case do not have lifetimes that can be statically modeled with non-copyable types. The OS manages descriptor lifetimes dynamically, through explicit calls such as `dup` and `close` and by passing descriptors between processes.

I think this mixes up the descriptor with the kernel object (open file description) it points to. `dup` and `SCM_RIGHTS` both create a _new_ descriptor, which is just a new owner. As Rust's [I/O Safety docs](https://doc.rust-lang.org/std/io/index.html#io-safety) note, "exclusive ownership of a file descriptor does not imply exclusive ownership of the underlying kernel object that the file descriptor references."

> [@Michael\_Ilseman](#):
>
> it also defines out important and plausible uses. For example, I/O code may keep the same descriptor in several places at once, such as an event loop's registry and a connection object.

Doesn't the registry just need a key, not something to do I/O through? For a connection, `final class Connection: Sendable { let socket: SocketDescriptor }` works for reading and writing. Am I missing something?

> [@Michael\_Ilseman](#):
>
> Some descriptors (e.g. received by C code), may have no clear owner in the program at all.

I think this is the strongest argument. If we receive a socket we don't own from C or another API boundary, we need a way to use it without closing it. The best answer to me is a lending closure on `FileDescriptor`:

```swift
extension FileDescriptor {
  /// For sockets this code doesn't own
  public func withSocketDescriptor<R: ~Copyable, E: Error>(
    _ body: (borrowing SocketDescriptor) throws(E) -> R
  ) throws(E) -> R
}

```

This lets code adopt the noncopyable type one call site at a time, and the compiler stops the body from accidentally closing a socket it doesn't own.

> [@Michael\_Ilseman](#):
>
> With only a noncopyable `SocketDescriptor`, code that doesn't fit a statically-linear lifetime model would drop down to the raw `CInt`, giving up System's strong types, `Errno` errors, and `EINTR` retry along with lifetime checking.

The escape hatch doesn't have to be `CInt`. If it's `FileDescriptor`, code outside the owned model keeps System's strong types, `Errno` errors, and `EINTR` retry:

```swift
@frozen
public struct SocketDescriptor: ~Copyable, Sendable {
  public init(unsafelyAdopting fd: FileDescriptor) throws(Errno)
  public var unsafeFileDescriptor: FileDescriptor { get }
  public consuming func close() throws(Errno)
  public consuming func relinquish() -> FileDescriptor
  // deinit: same policy as Win32.FileHandle
}

```

It makes sense for escape hatches to vend the type that outside code already uses: `FileDescriptor` on POSIX, which is common across the ecosystem, and `SOCKET` on Windows for interacting with Winsock APIs (where there's no existing strong type).

Being noncopyable does bring up the `deinit` question. Whatever we decide in the [`deinit` thread](https://forums.swift.org/t/90120) for `Win32.FileHandle` should apply here, too.

On Windows, I was originally thinking we could wait for a `Win32.SocketHandle`, too, but @compnerd makes a good point: Winsock provides the BSD sockets API, so `SocketDescriptor` can be portable and use it on Windows. But a `SocketDescriptor` **must not** convert to a `FileDescriptor` there. Windows sockets are overlapped by default, so the UCRT `read` and `write` used in `FileDescriptor` can report that I/O finished while the kernel still owns the buffer, which is memory-unsafe. Closing also needs `closesocket`, not `close`. The Windows side could look like this, though the error type still needs discussing:

```swift
@frozen
public struct SocketDescriptor: ~Copyable, Sendable {
  public init(unsafelyAdopting socket: SOCKET) throws(Errno)
  public var unsafeSocket: SOCKET { get }
  // No conversion to `FileDescriptor`
  public consuming func close() throws(Errno) // Calls `closesocket`
  public consuming func relinquish() -> SOCKET
  // deinit: same policy as Win32.FileHandle
}

```

> [@Michael\_Ilseman](#):
>
> Future work could include an additional higher-level owned type, owning wrappers, etc.

I see the argument, but whichever type introduces `open`/`accept` and gets adopted by other libraries first essentially becomes the default. A later owned type would always be opt-in. Lifetime safety is a major way System can add value for higher-level libraries, and making the noncopyable type the default aligns with Swift's safety goals.

---

<div class="post-metadata">

**Author:** ![FranzBusch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/franzbusch/32/19447_2.png) [@FranzBusch](https://forums.swift.org/u/FranzBusch)\
**Post date:** [October 28, 2026, 11:00am UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/11 "2026-10-28T11:00:30Z")

</div>

Thanks for opening this pitch. I think this is an important and long-standing gap that we should fill in `swift-system`. I agree with @jrflat that this should be `~Copyable` similar to the pitched `Win32` types. I wish we could go back and make `FileDescriptor` `~Copyable` as well. Jonathan already explained it well which benefits we get from `~Copyable` usage here and from personal experience I have modeled those types with `~Copyable` for the past two years and it has saved me multiple times from forgetting to `close` a file descriptor. Having said that I continue to believe the currently best model is to make them `~Copyable` with a trapping `deinit`.

`OpenOptions` feels like a weird name to me and I personally prefer `SocketFlags` instead. I think we also need to add `fcntl()` operations on those sockets so that we can create non-blocking sockets on Darwin. This is very common and if we don't have these capabilities we won't be able to use these APIs in NIO or other places that work with non-blocking I/O.

---

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [October 29, 2026, 7:19pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/12 "2026-10-29T19:19:37Z")

</div>

> [@compnerd](#):
>
> I think that there might be some value in changing `SocketDescriptor` to use an `associatedtype` to a protocol for `DescriptorType` and replace the `fileDescriptor` to `descriptor` which then makes it agnostic to the implementation.

Is this `RawRepresentable` or some other protocol? If it's something else, I think it would be severable and should be deferred as future work. We also have other overlapping needs for protocols in this area (e.g. enabling ownership).

> [@jrflat](#):
>
> It makes sense for escape hatches to vend the type that outside code already uses: `FileDescriptor` on POSIX, which is common across the ecosystem, and `SOCKET` on Windows for interacting with Winsock APIs (where there's no existing strong type).

This is an example of potentially dropping down to raw typealiases. Is the plan to have a copyable `RawRepresentable` struct for `SOCKET` or a typealias?

> [@jrflat](#):
>
> Winsock provides the BSD sockets API, so `SocketDescriptor` can be portable and use it on Windows. But a `SocketDescriptor` **must not** convert to a `FileDescriptor` there.

Agreed, it won't. Windows sockets aren't file descriptors.

> [@jrflat](#):
>
> Closing also needs `closesocket`, not `close`. The Windows side could look like this, though the error type still needs discussing

Windows has a completely separate error model and trying to lossily convert to Errno is a potential disaster. Windows also brings in additional linkage concerns, initialization concerns, etc. To me, these are more reasons to sever Windows support from the pitch, or at least discuss it separately and holistically.

> [@compnerd](#):
>
> Ultimately, the concept is the same - `SOCKET` is a spelling for a descriptor. What makes `int` (or if you prefer `CInt`) so special that it should be deemed to be the only viable answer for the descriptor?

They are special on Unix-style platforms that model socket descriptors as file descriptors (and model file descriptors as `int`/`CInt`) because that's how the platform models them. It's not System's role to try to shoehorn one platform into another platform's model.

Perhaps `SocketDescriptor` holds that platform's representation of socket descriptors, which on Windows is `SOCKET`.

I've been hesitant to prematurely lock in a platform that I'm not very familiar with, especially as System is just now growing Win32 interfaces.

Is a Windows treatment something you'd be interested in collaborating on?

---

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [October 29, 2026, 7:39pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/13 "2026-10-29T19:39:38Z")

</div>

I'll write up more on ownership and potential landing places for a future reply (and probably separate thread).

Some brief responses:

> [@jrflat](#):
>
> I believe `SocketDescriptor`, and future descriptor types in `swift-system`, should be noncopyable.

There are multiple valid places System could land here. I mostly care that we land in a consistent place. Having a copyable type named `FileDescriptor` and a non-copyable type named `SocketDescriptor` would not be consistent.

> [@jrflat](#):
>
> I think this mixes up the descriptor with the kernel object (open file description) it points to.

I'm referring to file descriptors. A file descriptor is a strong reference to an open file description (OFD). Systems-level code uses, in effect, failable manual init/retain/release calls (`open`/`dup`/`close`) to establish a lifetime that is checked at run time. These calls can model a superset of what statically checked ownership (noncopyable types) can model.

They also share analogous issues we face with things like `Collection.Index` misuse or invalidation as well. I very much want tools to manage their lifetimes statically. There are tradeoffs though to _only_ having interfaces with statically managed lifetimes, and it could be the role of the libraries built on top of System to pick from a given set of tradeoffs.

> [@jrflat](#):
>
> Doesn't the registry just need a key, not something to do I/O through? For a connection, `final class Connection: Sendable { let socket: SocketDescriptor }` works for reading and writing. Am I missing something?

From the kernel's view, that key is a copyable file descriptor (on Unix-like platforms).

> [@FranzBusch](#):
>
> `OpenOptions` feels like a weird name to me and I personally prefer `SocketFlags` instead

That's the leading alternative in the alternatives considered section on the name. Could you say more?

> [@FranzBusch](#):
>
> I think we also need to add `fcntl()`

Yes, it's on the docket. [old pitch](https://gist.github.com/milseman/2e59c10299f04c682c4090c4d2ecc0e0#detailed-description)

> [@FranzBusch](#):
>
> This is very common and if we don't have these capabilities we won't be able to use these APIs in NIO or other places that work with non-blocking I/O.

I'm interested in incremental adoption within NIO. Just to verify my understanding, NIO could incrementally adopt either pitch without the other, correct?

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [October 29, 2026, 10:50pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/14 "2026-10-29T22:50:16Z")

</div>

> [@Michael\_Ilseman](#):
>
> Is this RawRepresentable or some other protocol? If it's something else, I think it would be severable and should be deferred as future work. We also have other overlapping needs for protocols in this area (e.g. enabling ownership).

I don't think that `RawRepresentable` is really the right thing to use to model this, though, the `DescriptorType` certainly could be raw representable. I'm not following the needs here - the `DescriptorType` is some sort of opaque integral type, it shouldn't have any ownership associated with it - that is what the `SocketDescriptor` type does.

> [@Michael\_Ilseman](#):
>
> This is an example of potentially dropping down to raw typealiases. Is the plan to have a copyable RawRepresentable struct for SOCKET or a typealias?

Interesting idea - I don't see any downsides to a RR struct as a newtype alias for SOCKET. That effectively becomes `DescriptorType`.

> [@Michael\_Ilseman](#):
>
> Windows also brings in additional linkage concerns, initialization concerns, etc.

Could you please elaborate on this? I don't see why this doesn't apply to all platforms. Many embedded systems/RTOS environments require a separate library to linked in (e.g. lwIP), which immediately requires the initialization concern.

> [@Michael\_Ilseman](#):
>
> It's not System's role to try to shoehorn one platform into another platform's model.

Perhaps a compromise could be on the naming, could you consider a different name like `NonPortableBSDSocket` for Unix platforms (or `_SocketDescriptor` if you really want to use that name)? This should make it clear that this isn't a general purpose socket type that people should be using. The current model feels like its modelling BSD sockets APIs, not the platform, and so the Windows or RTOS like approach to BSD sockets fits into the model already modulo spellings. This would allow a platform specific abstraction while leaving the generic name for a layer that provides a generic BSD socket layer across platforms.

> [@Michael\_Ilseman](#):
>
> Is a Windows treatment something you'd be interested in collaborating on?

Sure, happy to collaborate on that.

> [@Michael\_Ilseman](#):
>
> I'm interested in incremental adoption within NIO. Just to verify my understanding, NIO could incrementally adopt either pitch without the other, correct?

I think that this should be **VERY STRONGLY discouraged** , and perhaps actively prevented. Because system does not wish to create a shared vocabulary across platforms, adoption causes continued friction for portability (and has been the source of trouble for the windows port of NIO).

---

<div class="post-metadata">

**Author:** ![jrflat](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrflat/32/31407_2.png) [@jrflat](https://forums.swift.org/u/jrflat)\
**Post date:** [November 10, 2026, 6:53pm UTC](https://forums.swift.org/t/pitch-socketdescriptor/90148/15 "2026-11-10T18:53:19Z")

</div>

Discussed with @Michael_Ilseman, @glessard, and @scanon offline, and I've come around to having `SocketDescriptor` be copyable. We can plan for owned or linear types in the future, but System shouldn't limit use cases based on lifetime model, and the open questions on how to treat the owned type's `deinit` shouldn't block this work. These future types can wrap the copyable type and call its implementations.

Making `SocketDescriptor` available on Windows as a copyable wrapper over `SOCKET` using the BSD Winsock APIs still seems like the best path forward.
