Commit Graph
27 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
Fabian Fett 5679824930 [Windows] Ensure WSAStartup is correctly called. (#3366)
### Motivation

- `WSAStartup` isn't called

### Changes

- Change stuff that I have very little idea about until it works

### Result

WSAStartup is now emitted at the correct location for the linker to be
picked up.
2025-09-03 16:16:21 +00:00
Johannes Weiss 40ee44c6b9 always @preconcurrency import Glibc/Musl/Android/Bionic/WASILibc (#3153)
### Motivation:

The non-`Darwin` libcs don't have the correct concurrency annotations.
But due to these Swift bugs, it's important that the _first_ importer
uses `@preconcurrency`:

- https://github.com/swiftlang/swift/issues/79414
- https://github.com/swiftlang/swift/issues/77866

### Modifications:

Much like the Foundation (& corelibs) PRs such as
https://github.com/swiftlang/swift-foundation/pull/1175 , use
`@preconcurrency import` for the non-`Darwin` libcs.

### Result:

Fewer bad warnings/errors in user code.
2025-03-21 15:35:05 +00:00
Tim Condon 6c44e2d605 Hashable SocketAddressError (#3119)
Make `SocketAddressError` `Equatable` and `Hashable`. This is useful when running tests
that you expect to throw this error as it allows you to write for
example
```swift
await #expect(throws: SocketAddressError.unknown(host: "127.0.0.1", port: Int.max)) {
    try await app.startup()
}
```
2025-02-23 21:23:06 +00:00
Rick Newton-Rogers adfd61adc5 Use Swift 6.0 docs pipeline (#2966)
### Motivation:

Documentation checking catches more issues in Swift 6.0.

### Modifications:

Adopt the Swift 6.0 image and fix the errors.

### Result:

More accurate docs.
2024-11-07 13:03:47 +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
finagolfin 4feff3c2f6 Use the new Android overlay and Bionic module from Swift 6 (#2784)
Motivation:

Get this repo building again for Android with the new overlay

Modifications:

- Import the new module or overlay wherever `Glibc` is used
- Keep this repo building with Swift 5 by duplicating some declarations

Result:

All the same tests keep passing on my Android CI, finagolfin/swift-android-sdk#158
2024-07-22 09:58:09 +00:00
Franz Busch c9756e1083 Adopt swift-format (#2794)
* Apply formatting

* Apply no block comments rule

* Apply OmitExplicitReturns

* Apple OnlyOneTrailingClosureArgument

* Apply NoAssignmentInExpressions

* Fix up DontRepeatTypeInStaticProperties lint errors

* Apply `OrderedImports`

* Apply `ReplaceForEachWithForLoop`

* format file

* Enable the formatting pipeline

* Adopt `AmbiguousTrailingClosureOverload`

* Fix license header

* Fix format check

* Fix `EndOfLineComment`

* Fix CI

* Adapt CI script to check if changes when running formatting

* Separate lint and format into to steps

* Fix format

* Adopt `UseEarlyExits`

* Revert "Adopt `UseEarlyExits`"

This reverts commit d1ac5bbe12.
2024-07-19 11:48:17 +02:00
finagolfin 231902a295 Correct a few Musl additions from #2449 for Android, plus error if libc not found (#2451)
Motivation

Fix build errors on Android

Modifications

- Fix previous Musl modifications that assumed Glibc wasn't imported on Android
- Add errors for all libc imports, so new platform ports error out early

Result

NIO builds natively on Android again, with all the same tests passing
2023-06-26 02:52:18 -07:00
Max Desiatov 43b1f59fde Add support for Musl libc (#2449)
* Add support for Musl libc

Since Musl is sufficiently different from Glibc (see https://wiki.musl-libc.org/functional-differences-from-glibc.html), it requires a different import, which now should be applied to files that have `import Glibc` in them.

* Fix `msghdr` initialization

* Fix msghdr mutability

* Fix `UnsafeMutableRawPointer` type conversions
2023-06-23 08:20:14 +01:00
Franz Busch e865f6163f Use #if canImport(Darwin) where possible (#2446) 2023-06-22 10:12:01 +01:00
David Nadoba 16b5b2b793 Replace NIOSendable with Sendable (#2291) 2022-10-13 15:56:27 +01:00
David Nadoba c7b4989b02 Remove #if compiler(>=5.5) (#2292)
### Motivation
We only support Swift 5.5.2+.

### Modification
Remove all `#if swift(>=5.5)` conditional compilation blocks.

### Result
less branching
2022-10-13 07:17:46 -07:00
David Nadoba b4e0a274f7 Fix compilation with Swift 5.5.0 and 5.5.1 (#2234) 2022-08-04 02:22:47 -07:00
Cory Benfield 67c0fd36d3 Add support for translating subnet prefixes to masks (#2169)
Motivation:

On Windows we have a need to transform a subnet prefix into a subnet
mask when enumerating devices. This is a straightforward transformation
that we can easily do in pure-Swift, so let's do that. Additionally, the
functions have small enough domains that we can just exhaustively test
them.

Modifications:

- Added functions to create SocketAddress objects from subnet prefixes.
- Added exhaustive tests for those functions.
- Use these functions in Windows code.

Result:

Correct transformations of prefixes into masks on Windows.
2022-06-07 04:49:19 -07:00
Saleem Abdulrasool c73c4d60f8 NIOCore: remove reference to in_addr_t on Windows (#2163)
This type does not exist in the current SDK (and previous iterations
also did not use the `in_addr_t` type).  Remove the type and use the
de-sugared `UInt` type instead on Windows.
2022-06-07 08:31:13 +01:00
Saleem AbdulrasoolandCory Benfield b5a185b62b NIOCore: import the C library interfaces (#2158)
The socket address handling logic depends on multiple C library
interfaces which requires the import of the C library.  Add that on
Windows.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-06 06:23:21 -07:00
Saleem AbdulrasoolandCory Benfield 544742cb5e NIOCore: import and alias some BSD socket types on Windows (#2157)
Although WinSock conceptually supports many of the BSD Socket APIs, it
does not provide source compatibility.  This adds a few type aliases for
adjusting towards source compatibility.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-06 05:50:32 -07:00
Saleem AbdulrasoolandCory Benfield 9f9a0b2bc0 NIOCore: adjust socket address handling on Windows (#2152)
Match the non-Windows path and unwrap the address pointer before use.
The two paths had diverged, and now converge in behaviour even if not in
spelling.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-06 03:40:59 -07:00
Saleem AbdulrasoolandCory Benfield eff9c964fe NIOCore: import additional socket types on Windows (#2151)
Add imports for additional socket types to enable building more of
NIOCore on Windows.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-01 13:08:22 -07:00
Saleem Abdulrasool afbf7566d5 NIOCore: handle structural differences on Windows (#2140)
The `sockaddr_t` type on Windows is not laid out identically to the Unix
counterpart (due to pedantically correct reasons).  There exist an inner
union type for the reinterpretation of the storage which requires naming
the union type.
2022-05-31 16:07:32 -07:00
Saleem Abdulrasool 8b3acb66b4 NIOCore: import INET{,6}_ADDRSTRLEN constants (#2138)
This imports the address string length constants from WinSock for
Windows.
2022-05-31 17:50:08 +01:00
Saleem Abdulrasool 083eba3652 NIOCore: correct typo in error namespace on Windows (#2133)
There was a missing `r` in the error type which caused a build failure
on Windows.  Correct the spelling for the error on Windows.
2022-05-31 10:52:07 +01:00
David NadobaandCory Benfield 788ade1cc3 Adopt Sendable for SocketAddress, AddressedEnvelope and friends (#2096)
* Box: Sendable

* SocketAdress: Sendable and friends

* AddressEnvelop: Sendable and friends

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-05-04 09:33:57 -07:00
Cory BenfieldandGuillaume Lessard b2195f7973 Rebind less load more (#2055)
* rebind less, load more.

* Rebind even less, load even more

* Remove the mutatings

Co-authored-by: Guillaume Lessard <guillaume.lessard@apple.com>
2022-03-07 03:20:16 -08:00
Cory Benfield 19403414ba Get unit tests running again on nightly builds. (#1961)
Motivation:

In February, @weissi noticed that the nightly builds of Swift could no
longer compile the unit tests. We disabled them at that time and
reported an upstream bug, https://bugs.swift.org/browse/SR-14268. This
is not an ideal situation, but the Swift core team has provided a
workaround we can use to re-enable the tests.

Modifications:

Provide free functions that wrap some specific extension methods that
are called in unit tests, and amend the call sites to use them.

Result:

We can re-enable the nightly tests.
2021-09-17 20:50:29 +01:00
Cory Benfield 4bb6acf57d Move SocketAddress and NIOBSDSocket to NIOCore (#1907)
Motivation:

This is the next stage of our move of common interchange objects to
NIOCore and out of the NIO module. This time around we need
SocketAddress, which is part of the Channel API. Sadly, SocketAddress is
not as clean as some of the other ports, because it leaks a number of
POSIX-y concepts. This also forces us to bring along NIOBSDSocket, which
ideally we would not move, but we foolishly exposed as API on
SocketAddress.

Modifications:

- Move NIOBSDSocket API components into NIOCore.
- Split out the internal abstractions for NIOBSDSocket and leave those
  in NIO.
- Move SocketAddress into NIOCore.

Result:

SocketAddress will be sitting in NIOCore.
2021-07-22 17:48:14 +01:00