### Motivation:
Existing get APIs require passing an explicit index and can be misused,
leading to verbose and error-prone code. Adding peek variants that
automatically use the current readerIndex improves safety and clarity.
This aims to address issue #2034 and issue #2736, and is a continuation
of PR #3157
### Modifications:
Introduced peekSlice(), peekLengthPrefixedSlice(), peekData(),
peekUUIDBytes() and peekWebSocketErrorCode().
Added tests for each peek API covering normal, empty and repeated peek
scenarios.
### Result:
Developers can now use nonmutating peek APIs to inspect ByteBuffer
contents without altering the reader index.
### Motivation:
The current readMultipleIntegers methods are used to consume multiple
integer values at once, but lack an equivalent nonmutating API. This can
lead to unnecessary complexity when users want to inspect values without
advancing readerIndex. THis patch introduces peekMultipleIntegers which
uses the current readerIndex, improving safety. This extends previous
work on peek methods (issue #2034, issue #2736).
### Modifications:
Updated the generation script (.sh file) to produce peekMultipleIntegers
variants for each arity of readMultipleIntegers.
Added new tests mirroring the existing multi-read/write tests
### Result:
Users can now inspect multiple integer values in a ByteBuffer without
consuming them, enabling safer workflows.
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
One of the SelectorTests used an `@unchecked Sendable` box which did
runtime checking of the `EventLoop`. We have a type for this already,
it's called `NIOLoopBoundBox`, we should use it.
Modifications:
- Replace `Box` with `NIOLoopBoundBox`
Result:
Fewer `@unchecked Sendable`s
Motivation:
NIOLoopBound and NIOLoopBoundBox both have a public-but-underscored
event loop property, i.e. the loop to which the value is bound. It's
often very helpful to be able to access the event loop the value is
isolated to. Having access allows you to execute onto the event loop and
safely access the value.
Modifications:
- Make the property public and add a deprecated shim for the
public-but-underscored variant.
Result:
Can access the event loop of a loop bound value
Co-authored-by: Cory Benfield <lukasa@apple.com>
This PR adds two benchmarks:
- Jumping 1k times from the global executor to a NIO EL and back using
`el.execute {}` and an `UncheckedContinuation`
- Jumping 1k times from the global executor to a NIO EL and back using
an actor that has a custom executor
Co-authored-by: Cory Benfield <lukasa@apple.com>
Static SDK installation script improvements
### Motivation:
Make static SDK installation scripts more modular and make
failures easier to diagnose.
### Modifications:
- Allow specification of binaries from outside the installation script
- Remove script dependency installation from the script
- Separate the Swift dependency installation into its own script
- Fatal error explicitly if the installed Swift can't be found
- Make curl operations for downloading artifacts explicitly fail
### Result:
Scripts which are easier to maintain and operate.
An example CI run with this in operation
https://github.com/apple/swift-nio/actions/runs/14329482180/job/40162003318?pr=3186
### Motivation:
Nightly main benchmarks have improved allocations, we should lock in the
win.
### Modifications:
Update nightly main benchmark thresholds
### Result:
Thresholds reflect gains, passing CI.
### Motivation:
These don't work on all versions but we should allow people to opt-in if
they know they do work
### Modifications:
Uncomment the steps and make the step default to off
### Result:
People can choose to run visionOS builds and tests
### Motivation:
Xcode 16.3 has been released, we should cover it in CI
### Modifications:
* Add Xcode 16.3 runs by default
* Disable Xcode 16.0 runs by default (soft deprecation)
Note that the Xcode version offering is still a work in progress.
### Result:
macOS CI will test using Xcode 16.3
An example run with this working
https://github.com/apple/swift-nio/actions/runs/14220724296/job/39876502770?pr=3171
Motivation:
The README mentions indicates the supported Swift versions in a few
places which over time have gotten out of sync.
Modifications:
- Only document the supported Swift version in the 'supported versions'
section of the README
Result:
- Resolves#3158
Add support for macOS CI runner pools
### Motivation:
With new runners coming online we are separating the runners into pools.
* "nightly" runners are to be targeted for asynchronous work which users
aren't waiting on such as overnight work.
* "general" runners can be used for either synchronoous or asynchronous
work.
* At the moment all runers are "general" runners, a subset are "nightly"
runners.
The aim here is to prioritize work which users are waiting for such as
on PRs. Asynchronous work prioritizing the "nightly" runners will likely
end up queuing for the contended runners but synchronous work will claim
any available node.
### Modifications:
* Add a `runner_pool` input for the macOS workflow
* Default the `runner_pool` to `nightly` since the vast majority of
existing workflows are specifying asynchronous work.
* Specify the runner pool in NIO's use of macOS CI.
### Result:
Support for runner pools.
An example of this in action:
https://github.com/apple/swift-nio/actions/runs/14188573697/job/39748250001
Separate build and test steps in `macos_tests.yml`. Test execution can
now also be disabled through an input. This is useful for clarity of
output and also in some cases where test execution may not be supported
yet.
### Motivation:
Existing get APIs require passing an explicit index and can be misused,
leading to verbose and error-prone code. Adding peek variants that
automatically use the current readerIndex improves safety and clarity.
This aims to address https://github.com/apple/swift-nio/issues/2034 and
https://github.com/apple/swift-nio/issues/2736, and is a continuation of
PR https://github.com/apple/swift-nio/pull/3157
### Modifications:
- Introduced peekBytes(), peekString(), peekNullTerminatedString(),
peekUTF8ValidatedString() and peekDispatchData().
- Added tests for each peek API covering normal, empty, repeated, and
partial read scenarios.
### Result:
Developers can now use nonmutating peek APIs to inspect ByteBuffer
contents without altering the reader index.
***PS**: I have focussed on the ByteBuffer-aux get\* implementations, so
I'm not sure if I am missing any other important/error-prone get\*
elsewhere, if so, please point me to them and I'll be happy to add
respective peek\*'s!*
Motivation:
A few tests are failing to compiler on 32-bit platforms with recently
nightly toolchains. These tests are skipped if `Int` is 32 bits wide but
the compiler doesn't know that.
Modifications:
- Use overflow addition to stop the compiler from complaining; the
addition won't ever actually overflow because of the runtime check done
ahead of time.
Result:
- Tests compile again
- Resolves#3154
### Motivation:
The existing getInteger API is often used incorrectly, leading to
verbose or error-prone code as mentioned in
https://github.com/apple/swift-nio/issues/2034 and
https://github.com/apple/swift-nio/issues/2736. Users may
unintentionally access data without correctly managing the reader index.
To address this, I added a peekInteger API that reads integers using the
current readerIndex without modifying it.
### Modifications:
* Added a peekInteger method to ByteBuffer, which provides a nonmutating
way to read integers using the current readerIndex.
* Implemented peekInteger using the existing getInteger function.
* Added comprehensive unit tests to validate correct behavior, including
scenarios for different integer types, insufficient bytes, and
multi-write scenarios.
### Result:
* Users now have access to a safer API for inspecting integers in a
buffer without modifying state.
* Added tests for integer reading scenarios.
---------
Co-authored-by: George Barnett <gbarnett@apple.com>
Fixes NIOCore compiler errors for the `wasm32` architecture.
### Motivation:
When compiling NIOCore for a SwiftWasm target, several compilation
errors such as the following occur:
```
> swift build --swift-sdk wasm32-unknown-wasi --target NIOCore
.../swift-nio/Sources/NIOCore/FileHandle.swift:151:42: error: cannot find type 'TwoUInt32s' in scope
149 | public final class NIOFileHandle: FileDescriptor & Sendable {
150 | private static let descriptorClosed: CInt = CInt.min
151 | private let descriptor: UnsafeAtomic<TwoUInt32s>
| `- error: cannot find type 'TwoUInt32s' in scope
152 |
153 | public var isOpen: Bool {
.../swift-nio/Sources/NIOCore/FileHandle.swift:77:8: error: Unknown architecture
75 | typealias TwoUInt32s = DoubleWord
76 | #else
77 | #error("Unknown architecture")
| `- error: Unknown architecture
78 | #endif
79 |
…
```
The compilation errors were introduced with the following change:
https://github.com/apple/swift-nio/pull/2598/files#diff-a041d0c0d50a8f4fcda2020eeb4450ea994920ef61653cc06014457ccdb3ba0cR70
### Modifications:
The fix is straight-forward and unlikely to affect any existing
compilation targets other than the `wasm32` target.
We simply need to add `arch(wasm32)` to compiler architecture condtions
for a new typedef on line, then NIOCore compiles to wasm32 again.
### Result:
Before: NIOCore wasm build fails ❌
After: NIOCore wasm build succeeds ✅
Co-authored-by: Scott Marchant <scottm@passivelogic.com>
Improve usability of NIOAsyncChannel.executeThenClose function from an
Actor
### Motivation:
When calling executeThenClose from inside an actor, the closure which we
pass is not isolated to the same actor
This makes it hard to use
e.g. the following code won’t compile on Swift 6 because the closure is
`self-isolated` so can’t be passed
```
await withDiscardingTaskGroup { group in
do {
try await serverChannel.executeThenClose { inboundStream, _ in
try await self.handleInboundStream(inboundStream: inboundStream, group: &group)
}
} catch {}
}
```
Making the closure as @Sendable allows it to be passed, but then we
can’t access `group` anymore
### Modifications:
Added actor isolation parameter to the `executeThenClose` function.
### Result:
`executeThenClose` will be able to be asynchronously called from inside
an Actor, as it will now be part of the Actor's isolation domain.
---------
Co-authored-by: Franz Busch <privat@franz-busch.de>
### Motivation:
We have GitHub Actions CI running Swift Package Benchmark benchmarks on
each commit but when the values don't match updating them can be time
consuming. Particularly because you need to may need to exactly match
the running environment in CI to get matching numbers.
### Modifications:
Added a new dev script which pulls the output for the benchmark GitHub
actions runs on a PR and updates your local threshold files
### Result:
Easier benchmark threshold updates
Example interaction (actually on my branch of NIO SSL where I've messed
with the thresholds so they need an update):
```
❯ FETCH_PR_URL=https://github.com/rnro/swift-nio-ssl/pull/5 OUTPUT_DIRECTORY=Benchmarks/Thresholds/ ../swift-nio/dev/thresholds-from-benchmark-output.sh
** Updating: Benchmarks/Thresholds//nightly-main/NIOSSHBenchmarks.SimpleHandshake.p90.json job:39048331461
** Nothing to update: rnro/swift-nio-ssl 5.10 job:39048331486
** Nothing to update: rnro/swift-nio-ssl 5.9 job:39048331454
** Nothing to update: rnro/swift-nio-ssl 6.0 job:39048331469
** Nothing to update: rnro/swift-nio-ssl nightly-next job:39048331466