Commit Graph
2140 Commits
Author SHA1 Message Date
Anish Aggarwal dd3b25449a NIOCore: Implemented all three variants of _failEarlyRangeCheck methods for ByteBufferView (#2226)
* NIOCore: Implemented all three variants of _failEarlyRangeCheck methods for ByteBufferView

* _failEarlyRangeCheck is now no-op
2022-07-25 10:07:40 -07:00
Saleem Abdulrasool 48916a49af NIOCore: handle error description on Windows (#2219)
We would previously attempt to convert an error to a description without
consideration for the provenance on Windows.  This would result in a
failure if the error code was not from `errno`.  Account for the source
of the error and translate it appropriately.  We can not retrieve
descriptions on errors that may originate from Windows or WinSock as
well as the C library.
2022-07-07 13:07:34 +01:00
David Nadoba 8b160c3681 Adopt Sendable for NIOChatServer and MIOMuliticastChat examples (#2220) 2022-07-06 16:30:24 +01:00
David NadobaandCory Benfield f1d62128c4 Adopt Sendable for Closures in NIOWebSocket (#2218)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-07-05 04:07:44 -07:00
David Nadoba fbe7ef484a Adopt Sendable for Types in NIOWebSocket (#2217) 2022-07-05 11:50:55 +01:00
David Nadoba 927b91a1e7 Adopt Sendable for closures in HTTPClientUpgradeHandler.swift and HTTPServerUpgradeHandler.swift (#2216)
* Adopt `Sendable` for closures in `HTTPPipelineSetup.swift`

* make `UnsafeTransfer` and `UnsafeMutableTransferBox` available in Swift 5.4 too

* fix code duplication

* Copy `UnsafeTransfer` to `NIOHTTP1Tests` to be able to remove `@testable` from `NIOCore` import

* Adopt `Sendable` for closures in `HTTPServerUpgradeHandler.swift`

* Adopt `Sendable` for closures in `HTTPClientUpgradeHandler.swift`
2022-07-05 02:42:29 -07:00
David Nadoba 8c922223db Adopt Sendable for closures in HTTPPipelineSetup.swift (#2214)
* Adopt `Sendable` for closures in `HTTPPipelineSetup.swift`

* make `UnsafeTransfer` and `UnsafeMutableTransferBox` available in Swift 5.4 too

* fix code duplication

* Copy `UnsafeTransfer` to `NIOHTTP1Tests` to be able to remove `@testable` from `NIOCore` import
2022-07-05 10:01:04 +01:00
David Nadoba 0abf7eb929 Adopt Sendable for types in NIOHTTP1 (#2213) 2022-07-04 00:37:23 -07:00
Saleem Abdulrasool f4b0d661c1 NIOCore: add missing import on Windows (#2215)
We did not import `WinSDK` which provides the socketing interfaces.
This allows building `NIOCore` on Windows again.
2022-07-01 19:01:04 +01:00
David NadobaandCory Benfield 33fc191001 Adopt Sendable for MultiThreadedEventLoopGroup (#2211)
* Adopt `Sendable` for `MultiThreadedEventLoopGroup`

* remove `@Sendable` from `withCurrentThreadAsEventLoop(_:)`

* Remove trailing whitespace

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-07-01 06:05:54 -07:00
David NadobaandCory Benfield 6c54e11eaa Adopt Sendable in NonBlockingFileIO (#2212)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-07-01 04:06:41 -07:00
David NadobaandCory Benfield d6f5e38af2 Adopt Sendable for Bootstraps (#2209)
* Adopt `Sendable` for Bootstraps

* fix swift nightly

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-07-01 03:45:07 -07:00
YR ChenandCory Benfield a501353ef6 Deprecate NIOAtomics in favor of Atomics (#2204)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-07-01 02:31:14 -07:00
David NadobaandCory Benfield adda7374af Adopt Sendable for NIOThreadPool (#2210)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-30 08:38:09 -07:00
David Nadoba 427d358d03 Adopt Sendable for types in NIOPosix (#2208) 2022-06-30 16:21:50 +01:00
David Nadoba e650ac1279 Adopt noasync for ThreadSpecificVariable (#2206) 2022-06-30 11:11:42 +02:00
David Nadoba e2c7fa4d4b Adopt Sendable in NIOTLS (#2202) 2022-06-21 14:13:06 +01:00
David Nadoba 48f4e2978f Adopt Sendable in NIOFoundationCompat (#2203) 2022-06-21 09:33:04 +01:00
David Nadoba b73fc4e90d Adopt Sendable in NIOTestUtils (#2199)
* Adopting `Sendable` in `NIOTestUtils`

The parameter `decoderFactory` of the static methods `ByteToMessageDecoderVerifier.verifyDecoder` do not need to be `@escaping`. I have made them non-escaping as part of `Sendable` adoption because we would otherwise need to think about if they should be `@Sendable` too.

`VerificationError` is interesting, see the code comment for more information.

* Adopting `Sendable` in `NIOTestUtils`

The parameter `decoderFactory` of the static methods `ByteToMessageDecoderVerifier.verifyDecoder` do not need to be `@escaping`. I have made them non-escaping as part of `Sendable` adoption because we would otherwise need to think about if they should be `@Sendable` too.

`VerificationError` is interesting, see the code comment for more information.

* Clarify the reason `VerificationError` already conforms to `Sendable`
2022-06-20 13:23:14 +01:00
David Nadoba f554552edf Adopt Sendable in NIOEmbedded (#2195)
`EmbeddedChannel` and `EmbeddedEventLoop` should not be `Sendable`. However, they inherit from `Channel` and `EventLoop` respectively. Therfore, they need to be `Sendable` (and are already implcitily `Sendable`. Given these constraints, we can’t mark `EmbeddedChannel` and `EmbeddedEventLoop` as non-Sendable.
2022-06-17 06:38:06 -07:00
Saleem Abdulrasool f7c3c45df4 NIOPosix: disable timespec extension on Windows (#2194)
This extension does not port cleanly to Windows as the time structures
on Windows are different.  This happens to be unused, so simply remove
the extension on Windows.
2022-06-15 10:37:30 +01:00
Si Beaumont 4588691a1a Provide conversion APIs between TimeAmount and Swift.Duration (#2191)
* Provide conversion APIs between TimeAmount and Swift.Duration

Signed-off-by: Si Beaumont <beaumont@apple.com>

* fixup: Remove unnecessary overflow check

Signed-off-by: Si Beaumont <beaumont@apple.com>

* fixup: Move into new _NIOBeta57 module

Signed-off-by: Si Beaumont <beaumont@apple.com>

* fixup: Rename _NIOBeta57 module to _NIOBeta and move tests to own target

Signed-off-by: Si Beaumont <beaumont@apple.com>

* soundness: copyright years for some reason

Signed-off-by: Si Beaumont <beaumont@apple.com>
2022-06-14 14:38:17 +01:00
Si BeaumontandCory Benfield 69bb75df32 Throw fatalError when scheduling on shutdown EL if SWIFTNIO_STRICT is set (#2190)
* Throw fatalError when scheduling on shutdown EL if SWIFTNIO_STRICT is set

Signed-off-by: Si Beaumont <beaumont@apple.com>

* Add CrashTest for SWIFTNIO_STRICT crash

Signed-off-by: Si Beaumont <beaumont@apple.com>

* fixup: Extract env var parsing to static let

Signed-off-by: Si Beaumont <beaumont@apple.com>

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-14 05:43:48 -07:00
Saleem AbdulrasoolandCory Benfield b393d39603 NIOPosix: add missing import for Windows (#2188)
Add an import of `NIOCore` on Windows which mirrors the other platforms.
This greatly reduces the noise in the error list.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-14 04:37:27 -07:00
Saleem Abdulrasool 59cd8ff038 NIOPosix: import additional interfaces from WinSDK (#2189)
Import additional interfaces from WinSDK to enable additional paths to
build for Windows.
2022-06-14 10:56:44 +01:00
Stepan UlyaninandCory Benfield c0911e1b3c Implement the _failEarlyRangeCheck methods as no-ops (#2161)
* implement the _failEarlyRangeCheck methods as no-ops

* mark _failEarlyRangeCheck with @inlinable

* add a comment on why the _failEarlyRangeCheck methods are implemented as no-ops

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-13 06:10:37 -07:00
Saleem AbdulrasoolandCory Benfield 3c3c2b8f41 NIOPosix: add missing CNIOWindows import (#2184)
Add a missing import to match the other platforms.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-13 05:53:07 -07:00
Saleem AbdulrasoolandCory Benfield e0df87c5c1 NIOPosix: adjust precondition for Windows (#2183)
The member names are not identical across platforms.  Add a case to
handle the name difference on Windows.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-10 09:14:27 -07:00
Saleem Abdulrasool 01b13a5675 NIOPosix: reorganise packet info constants (#2182)
Co-locate the packet info constants and add Windows values.
2022-06-10 16:55:51 +01:00
Saleem AbdulrasoolandCory Benfield 03fa431216 NIOPosix: port file validation to Windows (#2179)
Use Win32 APIs to properly validate if a file is a pipe on Windows.
This enables providing the same semantics without leaking additional
Windows specifics.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-09 23:27:14 -07:00
Saleem Abdulrasool 57d41b502c NIOPosix: reorganise ECN constants, define for Windows (#2181)
Reorganise the ECN constants to colocate the definitions for the
different platforms.  Define the constants for Windows as the platform
does not provide them in the system headers.
2022-06-10 07:12:26 +01:00
Saleem Abdulrasool 055043e151 NIOPosix: use internal enumeration for GAI resolver (#2177)
Replace the use of raw constants with the internal enumeration.  This
ensures that the constant names are uniform and don't leak structural
information from the underlying information.
2022-06-09 08:21:24 +01:00
Saleem Abdulrasool 2560725d71 NIOPosix: use typealias instead of C name (#2180)
Switch to the typealias rather than the raw name to support Windows and
make the code homogeneous with the rest of the codebase.
2022-06-08 10:07:32 -07:00
Saleem Abdulrasool e697fd315a NIOPosix: silence some deprecation warnings on Windows (#2171)
Create a wrapper over `strerror` which is considered deprecated due to
the use of a shared global buffer.  Use `strerror_s` which requires a
buffer and size to prevent shared state or a buffer overrun.  This is
documented by Microsoft as requiring at most 94 characters, so we use a
buffer of size 95.
2022-06-08 10:20:52 +01:00
Saleem AbdulrasoolandCory Benfield 4448bb04aa NIOPosix: remove unused alias for function (#2172)
This cleans up a reference to `freeifaddrs` as that is no longer
referenced in the code base.  This avoids an error on Windows as
a side-effect.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-07 10:48:29 -07:00
Saleem Abdulrasool cd70dd3ec1 NIOPosix: shuffle typealias location (#2174)
Move the `sockaddr` typealias for Windows into the `BSDSocketAPIWindows`
file which is a better home for the platform specific typealias.
2022-06-07 10:24:35 -07:00
Saleem AbdulrasoolandCory Benfield 4f20e48a78 NIOPosix: use wrapper function for duplicating file descriptor (#2173)
Use the wrapper function for duplicating the file descriptor.  This
allows us to swap out the implementation for different targets making
the code more portable.  It additionally adds additional error handling
and checking as the wrappers are intended to perform error handling.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-07 10:08:52 -07:00
Saleem Abdulrasool 65c3f576b1 NIOPosix: reduce imports for Windows (#2170)
Reduce unnecessary noise in the files after previous refactoring
shuffled the use of the imported interfaces.  We can centralise most of
the imports and internal typealiases which avoids cluttering the shared
interfaces with compatibility handling for Windows.
2022-06-07 09:37:11 -07:00
Saleem AbdulrasoolandCory Benfield 207e6e0f7e NIOPosix: add additional imports and typealiases on Windows (#2168)
Extend more of the internal interfaces for the BSD API coverage on
Windows to get the same API surface when possible.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-07 07:38:50 -07:00
David Nadoba 0e2818bf86 Remove @preconcurrency from internal EventLoopFuture methods (#2135)
* add @preconcurrency again as it otherwise results in one more allcation in 1000_udpconnections
2022-06-07 07:09:44 -07:00
fae6522f6d NIOCore: adjust the BSDSocketAPI for Windows (#2164)
Windows does not provide a definition for `socklen_t`.  Create an
internal typealias for it to provide source stability to the internal
interfaces.

Co-authored-by: George Barnett <gbarnett@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-07 06:39:48 -07:00
Saleem AbdulrasoolandCory Benfield b4e4f0211f NIOCore: adjust system call helpers for Windows (#2155)
Windows does not provide a 3 parameter `open` and needs to be passed all
the parameters as `_open` is a variadic function (as per the
specification).  This provides a Windows specific path for `open` and
`read` as on Darwin and Linux, `read` uses a non-standard return type
(`ssize_t`).  As it happens, the `size` parameter on Windows also uses
`unsigned int` rather than `size_t` which would break on different
bitnesses.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-07 06:08:32 -07:00
Saleem AbdulrasoolandCory Benfield bb2aae798f NIOCore: extract and modify POSIX flag constants (#2150)
Windows does not have the same set of POSIX flag constants.  In
particular, there is no equivalent to group permissions as the ACL model
on Windows is far richer and requires the full specification of the
DACLs.  Additionally, isolate `O_CLOEXEC` to aid Windows which does not
have this flag.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-07 05:44:36 -07:00
Saleem AbdulrasoolandCory Benfield a8bb008516 NIOPosix: use errno accessor on Windows (#2167)
`errno` is a thread local variable, and as such on many platforms is
accessed indirectly.  This is implemented as macro, but is considered
complex by the clang importer and cannot be directly used.  Resolve this
by using the accessor for the value on Windows.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-07 05:10:12 -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 AbdulrasoolandCory Benfield b883295b0e NIOPosix: re-export C library on Windows to match (#2166)
This matches the behaviour on the non-Windows targets and re-exports the
C library.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-07 04:08:57 -07:00
Saleem AbdulrasoolandCory Benfield d2bd0d03fe NIOCore: duplicate the NIODevice implementation on Windows (#2165)
Windows does not have an `ifaddr` interface, and instead we need to
construct the interface from the adapter and logical interface.
Replicate this for the construction of the deprecated type just for
repairing the build.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-07 01:16:41 -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