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>
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>
`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>
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.
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>
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.
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>
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>
Windows does not have a `socklen_t` type, instead using `CInt` for the
value. This adds an explicit type cast to repair the build on Windows.
Co-authored-by: Cory Benfield <lukasa@apple.com>
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>
ByteBuffer is in the same NIOCore module, so no need to classify it (and even if, it should be `NIOCore` instead).
`warning: Topic reference 'ByteBuffer' couldn't be resolved. No local documentation matches this reference.`
Update the callsites for the new labels for the BSDSocketAPI interfaces
that were not updated to reflect the new labels.
Co-authored-by: Cory Benfield <lukasa@apple.com>
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.
* NIOCore: replace `mode_t` with `CInt`
Windows does not have a `mode_t` type alias, instead using the
de-sugared `CInt` type. De-sugar the instances to permit building on
Windows.
* Update Sources/NIOCore/FileHandle.swift
Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
`errno` on Windows cannot be access as a raw name as it goes through a
"complex" macro for the TLS access. Use the `_get_errno` helper instead
of accessing the `errno` through the macro for building on Windows.
* socket: Make destinationPtr param optional in sendmsg(...)
Signed-off-by: Si Beaumont <beaumont@apple.com>
* pdwm: Fixup documentation: scalar writes use sendmsg, not sendto
Signed-off-by: Si Beaumont <beaumont@apple.com>
* pdwm: Make sockaddr pointer param optional in scalarWriteOperation
Signed-off-by: Si Beaumont <beaumont@apple.com>
* pdwm: Add isConnected property to PendingDatagramWritesState
Signed-off-by: Si Beaumont <beaumont@apple.com>
* pdwm: If socket is connected use NULL msg_name in sendmsg(2)
Signed-off-by: Si Beaumont <beaumont@apple.com>
* BaseSocketChannel: Support connect after bind
Signed-off-by: Si Beaumont <beaumont@apple.com>
* DatagramChannel: Implement connectSocket(to:)
Signed-off-by: Si Beaumont <beaumont@apple.com>
* bootstrap: Rename bind0(makeChannel:registerAndBind:) to withNewChannel(makeChannel:bringup:)
Signed-off-by: Si Beaumont <beaumont@apple.com>
* bootstrap: Add set of DatagramBootstrap.connect(...) APIs
Signed-off-by: Si Beaumont <beaumont@apple.com>
* test: Remove DatagramChannelTests.testConnectionFails
Signed-off-by: Si Beaumont <beaumont@apple.com>
* test: Add ConnectedDatagramChannelTests, inheriting from DatagramChannelTests
Signed-off-by: Si Beaumont <beaumont@apple.com>
* NIOUDPEchoClient: Use connected-mode UDP
Signed-off-by: Si Beaumont <beaumont@apple.com>
* soundness: Update copyright notice
Signed-off-by: Si Beaumont <beaumont@apple.com>
* fixup: cleanup bootstrap APIs
Signed-off-by: Si Beaumont <beaumont@apple.com>
* pdwm: Check address of pending write if connected and add test
Signed-off-by: Si Beaumont <beaumont@apple.com>
* Revert "pdwm: Check address of pending write if connected and add test"
This reverts commit a4ee0756d5.
* channel: Fail buffered writes on connect and validate writes when connected
Signed-off-by: Si Beaumont <beaumont@apple.com>
* Run soundness.sh to get linux tests generated
Signed-off-by: Si Beaumont <beaumont@apple.com>
* NIOUDPEchoClient: Connect socket to remote only if --connect is used
Signed-off-by: Si Beaumont <beaumont@apple.com>
* socket: Support ByteBuffer (without AddressedEnvelope) for DatagramChannel
Signed-off-by: Si Beaumont <beaumont@apple.com>
* test: Simplify some test code
Signed-off-by: Si Beaumont <beaumont@apple.com>
* pdwm: Factor out common, private add(_ pendingWrite:)
Signed-off-by: Si Beaumont <beaumont@apple.com>
* channel: Support AddressedEnvelope on connected socket for control messages
Signed-off-by: Si Beaumont <beaumont@apple.com>
* channel: Defer to common unwrapData for error handling
Signed-off-by: Si Beaumont <beaumont@apple.com>
* channel: Throw more specific (new) errors, instead of IOError
Signed-off-by: Si Beaumont <beaumont@apple.com>
* SocketChannelLifecycleManager: Add supportsReconnect boolean property, used in DatagramChannel
Signed-off-by: Si Beaumont <beaumont@apple.com>
`NIOBSDSocket.inet_pton` and `NIOBSDSocket.inet_ntop` altered the label
for the family parameter but failed to update the Windows path. Adjust
the name accordingly.
* Adopt `Sendable` for `EventLoopFuture` and `EventLoopPromise`
* use internal typealias to deduplicate method bodies
* fix `Sendable` warnings for nightly toolchains
* fix compliation for Swift 5.5 & 5.6
* Adopt `Sendable` only in Swift 5.7+
Co-authored-by: Cory Benfield <lukasa@apple.com>
* Adopt `Sendable` in `EventLoop.swift`
* only adopt `Sendable` in Swift 5.6+
* add `@Sendable` only for Swift 5.7
* fix swift 5.5
* use internal typealias to deduplicate method bodies
* wip: Use clock_gettime for NIODeadline.now()
Signed-off-by: Si Beaumont <beaumont@apple.com>
* fixup: Add #if os(Linux) for clock_gettime use
* fixup: Add doc comments
Signed-off-by: Si Beaumont <beaumont@apple.com>
* NIOPerformanceTester: Add DeadlineNowBenchmark for NIODeadline.now()
Signed-off-by: Si Beaumont <beaumont@apple.com>
* fixup: Return counter from benchmark
Signed-off-by: Si Beaumont <beaumont@apple.com>
* Adopt `Sendable` for types in `BSDSocket` namespace
* Adopt `Sendable` for `CircularBuffer` and `MarkedCircularBuffer`
and also `Endianness`
* move `NIOSendable` into its own file and copy it over to syscall integration tests
Motivation
The rise of Swift concurrency has meant that a number of our APIs need
to be recontextualised as async/await capable. While generally this is a
straightforward task, any time those APIs were tested using
EmbeddedChannel we have a testing issue. Swift Concurrency requires the
use of its own cooperative thread pool, which is completely incapable of
safely interoperating with EmbeddedChannel and EmbeddedEventLoop. This
is becuase those two types "embed" into the current thread and are not
thread-safe, but our concurrency-focused APIs want to enable users to
use them from any Task.
To that end we need to develop new types that serve the needs of
EmbeddedChannel and EmbeddedEventLoop (control over I/O and task
scheduling) while remaining fully thread-safe. This is the first of a
series of patches that adds this functionality, starting with the
AsyncEmbeddedEventLoop.
Modifications
- Define AsyncEmbeddedEventLoop
Result
A required building block for AsyncEmbeddedChannel exists.
Co-authored-by: Franz Busch <privat@franz-busch.de>
Stop Sendable related warnings when using types defined inside NIOConcurrencyHelpers. All the code should actually already be thread safe, so no changes needed other than labelling some classes as either Sendable or @unchecked Sendable.
* Use unbuffered IO for stdout in NIOPerformanceTester
Signed-off-by: Si Beaumont <beaumont@apple.com>
* CRASH PERF TESTS: Up task count to 1M to test logging change
* Revert "CRASH PERF TESTS: Up task count to 1M to test logging change"
This reverts commit d8fa50eb15.
Co-authored-by: Cory Benfield <lukasa@apple.com>