Commit Graph
141 Commits
Author SHA1 Message Date
3405691582andRick Newton-Rogers 2bc71a6aff Partial OpenBSD support. (#3394)
### Motivation:

Additional partial platform support.

### Modifications: 

* Create a new CNIOBSD module for OpenBSD, for general cleanliness, and
make use of it throughout. Some of the changes are borrowed directly
from CNIOLinux; some may technically be unnecessary; I am erring
somewhat on expediency to functionality.

* Since `malloc_size` is unavailable on OpenBSD, and some of the helpers
make use of ManagedBufferPointer which makes use of it, mark some of
this as unavailable as well.

* Usual pthread optional typing changes, since pthread types are
pointers on this platform.

* Add conditionals to exclude other functionality not available here,
like IP_RECVPKTINFO or IP_PKTINFO.

* d_ino is a backwards-compatibility macro valued token for dirent, so
instead, just expand with a conditional.

* Use kqueue on OpenBSD. This necessitates adding some conditionals for
type and feature compatibility.

* The vsock API is unavailable on OpenBSD.

### Result:

Tested the NIOTCPEchoClient and NIOTCPEchoServer appears to work and
that swift-nio-ssh (hopefully wlog) builds with a local repository with
these changes.

Because NIOFS/_NIOFileSystem depend on some non-portable components,
such as extended attributes, sendfile, non-portable linkat flags, and
renameat2, this is only just partial OpenBSD support, which means that
`swift build` on the full swift-nio project won't build cleanly, but at
least the portable parts can be used to build servers and clients. This
commit will mark the linked bug as fixed; I will open a new bug for file
system support.

Fixes #3383.

---------

Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
2025-11-26 09:07:02 +00:00
Cory Benfield 88dc99031f Add some spans to ByteBuffer (#3371)
Motivation:

Users would like to be able to access the underlying memory of a
ByteBuffer, as evidenced by the plethora of `withUnsafe*` methods that
ByteBuffer has. As Swift 6.2 has introduced some initial APIs for safe
memory access to underlying storage, we should offer similar APIs on
ByteBuffer to enable users to get safer access to that storage.

For now, the obvious APIs to be able to supplement are:

- withUnsafeReadableBytes
- withUnsafeMutableReadableBytes
- writeWithUnsafeMutableWritableBytes

We can also offer some new APIs to allow initializing a buffer directly
from an OutputSpan.

Note that we can only do this because the Language Steering Group has
pinky promised that they will not break the "Lifetimes" experimental
feature: see

https://forums.swift.org/t/experimental-support-for-lifetime-dependencies-in-swift-6-2-and-beyond/78638
for more details. We are taking them at their word, and so we are
enabling that feature.

Modifications:

Many new methods and tests.

Result:

Safer access.
2025-11-06 11:54:06 -05:00
Fabian FettandCory Benfield a3ed8e10ab Drop Swift 5.10 (#3393)
This PR drops Swift 5.10 and enables Swift 6 language mode.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-10-06 10:58:33 +01:00
George Barnett a18bddb0ac Add back NIOFileSystem (#3380)
Motivation:

We accidentally removed the 'NIOFileSystem' module from the
'_NIOFileSystem' product in the last release.

Modifications:

- Rename 'NIOFileSystem' and 'NIOFileSystemFoundationCompat' to 'NIOFS'
  and 'NIOFSFoundationCompat'
- Add back 'NIOFileSystem' which re-exports '_NIOFileSystem' (there was
  no publicly available 'NIOFileSystemFoundationCompat' module to
  remove, only '_NIOFileSystemFoundationCompat').

Result:

Fewer breaks
2025-09-23 17:29:01 +01:00
George Barnett 2550c9ed48 Remove NIOFileSystem from products (#3370)
Motivation:

NIOFileSystem has a few APIs which expose swift-system. We'll need to
replace those before making this API stable.

Modifications:

- Remove NIOFileSystem product
- Modify snippet so that it still builds

Result:

NIOFileSystem isn't yet public API
2025-09-08 15:31:15 +01:00
George Barnett 66a85ba0e2 Add back _NIOFileSystem (#3367)
Motivation:

In #3363 we converted `_NIOFileSystem` to `NIOFileSystem` and removed
the (unreleased) overloads for FilePath/NIOFilePath. This change adds
back `_NIOFileSystem` such that it matches the API it had at 2.86.0.

Modifications:

- Add back `_NIOFileSystem` and `_NIOFileSystemFoundationCompat` such
that their API is at 2.86.0

Result:

- `NIOFileSystem` uses `NIOFilePath`
- `_NIOFileSystem` uses `FilePath`
2025-09-02 14:56:58 +01:00
George Barnett 7290551b7f Add a NIOFilePath based NIOFileSystem (#3363)
Motivation:

We changed the file path type in `_NIOFileSystem` to use `NIOFilePath`
instead of `FilePath`. Originally we planned to use API shims to avoid
breaking API, however in some cases this was inevitable (i.e. where a
file path is returned to the caller).

To roll over to the new API we will instead introduce the
`NIOFileSystem` module using `NIOFilePath` and have `_NIOFileSystem` use
`FilePath`. Users can then opt-in to the new stable API rather than
having it forced upon them.

The first wave of these changes turns `_NIOFileSystem` into
`NIOFileSystem` and uses `NIOFilePath` for its APIs.

Modifications:

- Remove disfavoured overloads (i.e. `FilePath` APIs)
- Update the `DirectoryEntry` API to use `NIOFilePath`.
- Update tests to use `NIOFilePath` since many were relying on the newly
removed shims
- Remove the underscore from the module names and products
- Remove deprecated methods

A follow up change will re-instate the `_NIOFileSystem` (and compat)
module and products using `FilePath`.

Result:

`NIOFileSystem` has a stable API.
2025-09-01 08:11:14 +01:00
George Barnett cae0a353d1 Remove Foundation import (#3310)
Motivation:

The package manifest imports Foundation.ProcessInfo to read environment
variables ... but doesn't.

Modifications:

- Remove unused import

Result:

- Fewer Foundation imports
2025-07-18 14:46:40 +00:00
Johannes Weiss 0b65385fad improve inEventLoop checks (#3302)
### Motivation:

`inEventLoop` is very much in the performance path of SwiftNIO,
especially these days with Concurrency, `NIOLoopBound` and friends.
Previously, we relied on `pthread_equal(pthread_self(), myPthread)`,
however, this could cause a number of issues.

1. Holding onto a `pthread_t` after `.join` is actually illegal (fixed
in #3297)
2. Potential ABA issues when `pthread_t` pointer are re-used for new
pthreads
3. Fix would require a lock around `myPthread` which makes things (2x
slower, even without contention)

### Modifications:

- New type `SelectableEventLoopUniqueID` which can be packed into a
`UInt`
- Attach them into a C thread local

### Result:

- Even faster than the old, incorrect version
- old: `measuring: el_in_eventloop_100M: 0.257395375, 0.241049208,
0.243188792, 0.259125916, 0.24843225, 0.229690125, 0.244281541,
0.225078834, 0.236395, 0.233305167`
- new: `measuring: el_in_eventloop_100M: 0.175561125, 0.187225625,
0.199269375, 0.19740975, 0.1922695, 0.179850958, 0.177612458,
0.17665125, 0.17897475, 0.18038775`
- More correct
- Groundwork to make #3297 not make things slower
2025-07-14 17:15:10 +01:00
a0c542bff1 Fix NIOAsyncWriter test on concurrency thread pool with single thread (#3135)
### Motivation:

The testSuspendingBufferedYield_whenWriterFinished test fails on the
Android emulator. See also the discussion in #3044.

### Modifications:

The test requires at least two threads in the concurrency thread pool
because it blocks one task, which waits for another task to set a
condition. This PR adds support for running a task executor based on a
NIOThreadPool and uses it for the test. Using a custom task executor
guarantees that at least two threads are available for the test.

Additionally, the test has been renamed to
testWriterFinish_AndSuspendBufferedYield, which is more in line with the
other test names.

### Result:

The test will pass regardless of the width of the global concurrency
thread pool.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-05-12 15:12:53 +01:00
Rick Newton-Rogers 57658e12ff Drop Swift 5.9 (#3228)
Motivation:

Swift 5.9 is no longer supported, we should bump the tools version and
remove it from our CI.

Modifications:

* Bump the Swift tools version to Swift 5.10
* Remove Swift 5.9 jobs where appropriate in main.yml, pull_request.yml

Result:

Code reflects our support window.
2025-05-07 12:24:44 +00:00
George Barnett c420f0d4e6 Enable strict concurrency for NIOPosixTests (#3211) 2025-04-16 13:00:13 +00:00
George BarnettandCory Benfield 81375efead Strict concurrency for NIOTLSTests (#3207)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-16 11:12:57 +01:00
George BarnettandCory Benfield 27a1897914 Strict concurrency for NIOTestUtilsTests (#3206)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-15 16:03:08 +00:00
George Barnett b34052b28b Swift concurrency for NIOWebSocketTests (#3208) 2025-04-15 16:38:21 +01:00
George Barnett 4b7854daaa Strict concurrency for NIOPerformanceTester and NIOCrashTester (#3167) 2025-04-07 14:10:48 +00:00
George BarnettandRick Newton-Rogers 202f987738 Strict concurrency for NIOHTTP1Tests (#3169)
Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
2025-04-07 11:27:05 +01:00
George Barnett 195bca151e Strict concurrency for websocket client/server demo and async demo (#3161) 2025-04-01 16:39:33 +00:00
Rick Newton-Rogers 21429ce692 Only apply standard swift settings on valid targets (#3134)
Only apply standard swift settings on valid targets. The current check
ignores plugins but that is not comprehensive enough.
2025-03-07 15:05:51 +00:00
Rick Newton-Rogers 6adf682d16 Enable strict concurrency checking for NIOTestUtils (#3130)
### Motivation:

To ensure `NIOTestUtils` concurrency safety.

### Modifications:

* Enable strict concurrency checking in the package manifest.
* `NIOHTTP1TestServer` does pipeline configuration as synchronous
operations.

### Result:

`NIOTestUtils` does not warn of concurrency issues, builds will warn and
CI will fail if regressions are introduced.
2025-03-07 10:52:08 +00:00
Rick Newton-Rogers 5fe3d44328 Enable strict concurrency checking for NIOWebSocket (#3127)
Enable strict concurrency checking for NIOWebSocket

### Motivation:

To ensure NIOWebSocket concurrency safety.

### Modifications:

* Enable strict concurrency checking in the package manifest.
* `NIOWebSocketClientUpgrader._upgrade` private function generic return
type is marked as `Sendable` in line with the only method which calls
it.
* `NIOWebSocketServerUpgrader._upgrade` private function generic return
type is marked as `Sendable` in line with the only method which calls
it.
* `WebSocketOpcode.allCases` public computed variable is replaced with a
`let` which manually enumerates the cases instead

### Result:

`NIOWebSocket` does not warn of concurrency issues, builds will warn and
CI will fail if regressions are introduced.
2025-03-07 09:34:06 +00:00
Rick Newton-Rogers 140be96c6b Enable strict concurrency checking for NIOHTTP1Client (#3131)
### Motivation:

To ensure `NIOHTTP1Client` concurrency safety.

### Modifications:

* Enable strict concurrency checking in the package manifest.

### Result:

Builds will warn and CI will fail if regressions are introduced.
2025-03-06 16:55:56 +00:00
Rick Newton-Rogers de47bf8ba5 Enable strict concurrency checking for NIOHTTP1Server (#3132)
### Motivation:

To ensure `NIOHTTP1Server` concurrency safety.

### Modifications:

* Enable strict concurrency checking in the package manifest.
* User synchronous operations in pipeline configurations

### Result:

Builds will warn and CI will fail if regressions are introduced.
2025-03-06 14:58:02 +00:00
Rick Newton-Rogers 5f60ceeca0 Enable strict concurrency checking for NIOHTTP1 (#3115)
### Motivation:

To ensure NIOHTTP1 concurrency safety.

### Modifications:

* Enable strict concurrency checking in the package manifest.
* Mark several objects `Sendable` with `@preconcurrency` annotations
where they are returned in futures which may execute in arbitrary
concurrency domains.
  * `NIOTypedHTTPClientProtocolUpgrader`
  * `NIOTypedHTTPClientUpgradeConfiguration`
  * `NIOUpgradableHTTPServerPipelineConfiguration`
  * `NIOUpgradableHTTPClientPipelineConfiguration`
  * `NIOTypedHTTPServerProtocolUpgrader`
  * `NIOTypedHTTPServerUpgradeConfiguration`
* Mark handlers as explicitly not sendable
  * `NIOTypedHTTPClientUpgradeHandler`
  * `NIOTypedHTTPServerUpgradeHandler`
* Added new Sendable type aliases:
  * `NIOHTTPClientUpgradeSendableConfiguration`
  * `NIOHTTPServerUpgradeSendableConfiguration`

### Result:

No more concurrency warnings. Builds will warn and CI will fail if
regressions are introduced.
2025-02-19 15:04:51 +00:00
Rick Newton-Rogers c51907a839 Enable strict concurrency checking for NIOTLS (#3112)
### Motivation:

To ensure NIOTLS concurrency safety.

### Modifications:

* Enable strict concurrency checking in the package manifest.
* Require `NegotiationResult` to be `Sendable`
* In `NIOTypedApplicationProtocolNegotiationHandler<NegotiationResult>`
the
result is used to fulfil promises and perform hops so we need it to be
sendable when accessed from these other concurrency domains.

### Result:

Builds will warn and CI will fail if regressions are introduced.
2025-02-07 16:52:40 +00:00
Cory Benfield f43b37eb31 Make the FileSystem world strict concurrency clean (#3107)
Motivation:

We have a few other file system modules with a small amount of code, and
a lot of tests. Most of these require no changes for strict concurrency,
so let's tackle them all.

Modifications:

Strict concurrency for filesystem targets enabled. Fixed a few incorrect
test case captures.

Result:

Strict concurrency clean filesystem bits.
2025-02-04 11:01:48 +00:00
Cory Benfield 08b3b4f95e Make _NIOFileSystem strict concurrency compatible (#3098)
Motivation:

We're continuing out Strict Concurrency journey, making sure users of
NIO can write data-race-free code.

Modifications:

- Added some missing Sendable annotations in NIOAsyncSequenceProducer
- Made BufferedStream unconditionally Sendable, and required its Element
type to also be Sendable.

    The prior constraint wasn't actually correct. We always
    behaved as though the element types were Sendable, by passing
    them into continuations. This cleans things up.
- Made AnyAsyncSequence Sendable, which it needs to be.
- Made BufferedOrAnyStream Sendable, which it needs to be.
- Made DirectoryEntries explicitly Sendable, which it was.
- Made DirectoryEntries.Batched explicitly Sendable.

Result:

Better concurrency-safety
2025-02-03 17:56:57 +00:00
Cory Benfield 2f1c7800e4 Strict concurrency for NIOTests (#3106)
Motivation:

NIOTests was already warning free, now we're just going to make sure of
it.

Modifications:

Enable strict concurrency for NIOTests

Result:

Our relentless safety march continues.
2025-02-03 16:57:45 +00:00
Cory Benfield e2bfa2fc75 Strict concurrency enablement for some test targets (#3105)
Motivation:

A few more low-hanging-fruit test targets.

Modifications:

Enable strict concurrency for:

- NIOFoundationCompatTests
- NIOSingletonsTests

Result:

We're knocking down those targets, one by one.
2025-02-03 16:32:55 +00:00
Cory BenfieldandRick Newton-Rogers 8f19d80751 Strict concurrency for the chat examples (#3104)
Motivation:

Our next suite of examples for strict concurrency are the chat ones.
These are very similar to the rest: either no violation at all, or just
a need to use the sync operations on pipeline setup.

Modifications:

- Use sync operations
- Lock in strict concurrency checking

Result:

We continue our march.

Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
2025-02-03 16:04:40 +00:00
Cory Benfield 0bc48ebbc5 Strict concurrency for TCP examples (#3103)
Motivation:

Two more examples with no changes required.

Modifications:

Lock in strict concurrency for NIOTCPEchoClient and NIOTCPEchoServer.

Result:

Even more stricter concurrencier.
2025-02-03 15:20:45 +00:00
Cory Benfield 9a181b3aae Update NIOUDPEchoClient for strict concurrency (#3102)
Motivation:

NIOUDPEchoClient should be strict concurrency clean.

Modifications:

Annotate one closure @Sendable to convince Swift it's ok.

Result:

Strict concurrency clean in NIOUDPEchoClient.
2025-02-03 14:22:56 +00:00
Cory Benfield aa360ab8e8 Lock in strict concurrency in NIOEchoServer (#3100)
Motivation:

Prior patches actually removed all the issues in NIOEchoServer, so let's
bank the win.

Modifications:

Added strict concurrency checking to NIOEchoServer

Result:

More stricter.
2025-02-03 13:55:41 +00:00
Cory Benfield d273f906fe Add strict concurrency to NIOUDPEchoServer (#3101)
Motivation:

Another strict concurrency change, another echo handler.

Modifications:

Move to sync operations.

Result:

Another step on strict concurrency.
2025-02-03 12:56:02 +00:00
Cory BenfieldandGeorge Barnett 8bf3316c37 Clean up concurrency in NIOEchoClient (#3099)
Motivation:

We're getting to the examples now! This patch updates NIOEchoClient to
be clean under strict concurrency.

Modifications:

Use the sync operations to add echo handler.

Result:

Another strict concurrency module.

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-02-03 11:49:56 +00:00
Cory Benfield a849d50ce6 Opt NIO module into Strict Concurrency (#3097)
Motivation:

Honestly these little modules are pretty mechanical now.

Modifications:

Add the strict concurrency flags to a module with nothing in it.

Result:

Become even more automatic from way downtown.
2025-02-03 11:25:02 +00:00
Cory Benfield 29c920d3e6 Opt NIOFoundationCompat into strict concurrency (#3096)
Motivation:

I continue to grab the low-hanging fruit. This time I've opted a purely
data-processing module into strict concurrency. Truly, I am the hero
Gotham deserves.

Modifications:

Set some build flags.

Result:

Stricter concurrency.
2025-02-03 10:51:09 +00:00
Cory Benfield 4ea59742f0 Opt _NIOConcurrency into Strict Concurrency (#3095)
Motivation:

We intend to have this package be completely strict-concurrency clean,
so every target needs to be opted in, even those that currently have no
code.

Modifications:

Opt in this empty target to strict concurrency.

Result:

One more database entry.
2025-02-03 10:22:07 +00:00
Cory Benfield 26d3fb9097 Make NIOPosix strict-concurrency clean (#3090)
Motivation

NIOPosix should be clean under strict concurrency

Modifications

- Fix newly-added issue in GetaddrinfoResolver
- Fix newly-added issue in SEL
- Lock in the win in Package.swift

Result

We did it!
2025-01-27 08:11:08 +00:00
Cory BenfieldandJohannes Weiss 96877aff7f Fix compiling on 6.1 (#3057)
Motivation:

Swift 6.1 nightlies have added many new warnings and errors to NIO. This
patch resolves all of them.

Modifications:

- Clean up missing imports
- Move away from @_implementationOnly where necessary
- Fix a few things where Sendable mismatches were present.

Result:

Clean compile again

---------

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2025-01-14 16:36:17 +00:00
Rick Newton-Rogers 60089114f8 Enable MemberImportVisibility check - attempt 2 (#3029)
Enable MemberImportVisibility check on all targets. Use a standard
string header and footer to bracket the new block for ease of updating
in the future with scripts.

See https://github.com/apple/swift-nio/pull/3021
2024-12-17 11:21:02 +00:00
Cory Benfield 2d72ada999 Get NIOEmbedded clean under strict concurrency (#3030)
Motivation:

NIOEmbedded is used all over NIO-land for testing various pieces of the
infrastructure, and so requires a substantial audit for strict
concurrency.

Modifications:

- Mark a few things Sendable.
- Fix the tests, which actually did have some nasty bugs

Result:

Sendable-clean NIOEmbedded
2024-12-17 09:49:06 +00:00
Rick Newton-Rogers b99b6278e8 Revert "Enable MemberImportVisibility check on all targets" (#3028)
Reverts apple/swift-nio#3021
2024-12-16 13:53:22 +00:00
Rick Newton-RogersandGeorge Barnett 55d0f72b30 Enable MemberImportVisibility check on all targets (#3021)
Enable MemberImportVisibility check on all targets. Use a standard
string header and footer to bracket the new block for ease of updating
in the future with scripts.

Co-authored-by: George Barnett <gbarnett@apple.com>
2024-12-16 11:17:18 +00:00
Michael GechtandCory Benfield 4d2fb577b9 Update documentation comments (#2998)
Updates to documentation comments in `NIOFileSystem`.

### Motivation:

I've been reviewing some parts of `NIOFileSystem` and came across a
variety of formatting of documentation comments.

### Modifications:

I've adopted a stricter 100-character limit (arbitrary, really; it could
be longer or shorter and is totally not consistent with the rest of the
repository). Also updated a bunch of grammar in comments. Fixed a few
typos along the way.

### Result:

- Updated comments have a better flow while reading, and aren't as
abrupt as before.
- Fewer typos in comments

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2024-11-26 14:48:29 +00:00
Cory Benfield 37b31b95c2 Complete NIOCore strict concurrency (#2959)
Motivation:

With our earlier big refactors, NIOCore is now currently strict
concurrency clean. Let's lock in the win by adopting the relevant Swift
settings and fixing up the tests.

Modifications:

- Adopt our strict concurrency settings in NIOCore and NIOCoreTests
- Clean up the tests

Result:

One step closer to a world without warnings.
2024-10-31 20:35:57 +00:00
Ali Ali 9140817010 Issue-2900 - Add VisionOS support (#2947)
Add Vision support

### Motivation:
https://github.com/apple/swift-nio/issues/2900 - close this

### Modifications:
- Bump SystemPackage to 1.4.0 and remove @preconcurrency 
- remove `#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) ||
os(Linux) || os(Android)` to allow for visionOS support
- Remove conditional import for swift system

### Result:

Vision OS support
2024-10-24 10:26:32 +00:00
Clinton NkwochaandGeorge Barnett cc1c57c291 Provide APIs to read file into more data types (#2923)
Motivation:

As requested in issues
[#2875](https://github.com/apple/swift-nio/issues/2875) and
[#2876](https://github.com/apple/swift-nio/issues/2876), it would be
convenient to be able to read the contents of a file into more data
types such as `Array`, `ArraySlice` & Foundation's `Data`.

Modifications:

- Extend `Array`, `ArraySlice` & `Data` to be initialisable with the
contents of a file.

Result:

The contents of a file can be read into more data types.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2024-10-21 08:41:10 +00:00
Franz Busch 2fe3d92cf5 Drop support for Swift 5.8 (#2924)
# Motivation

We only support the last three Swift released versions which are at this
time 5.9, 5.10 and 6.

# Modification

This PR drops anything related to Swift 5.8.

# Result

Version support aligned.
2024-10-17 12:22:10 +00:00
Max DesiatovandFranz Busch 730713e47f Add support for WASILibc (#2671)
Dispatch is not supported on WASI, and only Unix domain sockets are
supported, which means we have to exclude those APIs on this platform.

There's work in progress to enable tests for this on CI, but nothing I
can provide for this PR at the current moment.

---------

Co-authored-by: Franz Busch <f.busch@apple.com>
2024-09-12 13:18:25 +01:00