Files
swift-nio/Sources
Si Beaumont 03f13fb86c Add socket option API for SO_REUSEPORT (#3741)
### Motivation:

`NIOBSDSocket.Option` provides shorthand API for socket options, e.g.
`.so_reuseaddr` for `SO_REUSEADDR`. We don't have API for
`SO_REUSEPORT`.

`SO_REUSEPORT` is used to bind more than one socket to the same address
and port to spread accepts or datagrams over multiple sockets and
support hot restarts.

Users can already use it today, but must use `init(rawValue:)`, and
import the platform C lib, etc:

```swift
.channelOption(.socketOption(.init(rawValue: SO_REUSEPORT)), value: 1)
```

There's no reason not to provide a convenience for this option, like we
do for many others.

### Modifications:

This PR adds `NIOBSDSocket.Option.so_reuseport`, wrapping
`SO_REUSEPORT`, alongside the other options in `BSDSocketAPI.swift`.

It's not provided on Windows or WASI, which don't have `SO_REUSEPORT`,
but there was already precedent for other options like this, e.g.
`SO_TIMESTAMP`.

### Result:

Users can pass `.socketOption(.so_reuseport)` like other supported
socket options:

```swift
DatagramBootstrap(group: group)
    .channelOption(.socketOption(.so_reuseport), value: 1)
    .bind(host: "127.0.0.1", port: 12345)
```
2026-09-14 15:19:06 +00:00
..
2024-09-12 13:18:25 +01:00
2026-07-07 15:46:28 +01:00
2026-07-07 15:46:28 +01:00
2025-10-06 10:58:33 +01:00
2025-05-07 12:24:44 +00:00
2025-05-07 12:24:44 +00:00