Commit Graph
2009 Commits
Author SHA1 Message Date
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
Saleem AbdulrasoolandCory Benfield 38d8c7105c NIOCore: add explicit type cast for Windows compatibility (#2156)
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>
2022-06-06 05:28:23 -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
Konrad `ktoso` Malawski b94a0696df Fix docc warning about missing symbol (#2162)
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.`
2022-06-06 11:26:06 +01: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
David Nadoba 9c60117db0 Adopt Sendable in ChannelPipeline.swift and ChannelInvoker.swift (#2143) 2022-06-01 08:42:24 -07:00
David NadobaandCory Benfield 4574bdde82 Adopt Sendable in Codec.swift and SingleStepByteToMessageDecoder.swift (#2149)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-01 08:24:21 -07:00
David NadobaandCory Benfield 97a568ac61 Adopt Sendable in RecvByteBufferAllocator.swift (#2148)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-01 16:08:04 +01:00
David NadobaandCory Benfield 6f119c2995 Adopt Sendable in ChannelHandlers.swift (#2144)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-01 06:32:17 -07:00
David NadobaandCory Benfield 2f8d5408ae Adopt Sendable in ConvenienceOptionSupport.swift (#2145)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-01 05:58:16 -07:00
David NadobaandCory Benfield 6178126298 Adopt Sendable in NIOCloseOnErrorHandler.swift (#2146)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-01 05:28:43 -07:00
Saleem AbdulrasoolandCory Benfield 13a32273f7 NIOCore: adjust labels for inet_{ntop,pton} on Windows (#2141)
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>
2022-06-01 05:05:50 -07:00
Cory Benfield 32f62a89d9 Fix flake AsyncEmbeddedEventLoopTest (#2147)
Motivation:

Flaky tests are really annoying.

Modifications:

- Stop assuming that the item is not immediately nil

Result:

Test now passes consistently.
2022-06-01 03:44:59 -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 AbdulrasoolandCory Benfield 15aaf884b4 NIOCore: replace mode_t with CInt (#2132)
* 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>
2022-05-31 14:15:47 -07:00
Saleem Abdulrasool 4d4c942c35 NIOCore: use errno accessor on Windows (#2139)
`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.
2022-05-31 10:30: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
Si Beaumont 9bf5075241 Add initial support for connected datagram sockets (#2084)
* 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>
2022-05-31 13:21:41 +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
Saleem Abdulrasool e109615309 NIOCore: import WSAGetLastError, GetLastError (#2131)
We use these functions to report errors from WinSock.  This was likely
excluded accidentally from previous commits.
2022-05-30 11:00:34 -07:00
Saleem Abdulrasool 0f93ed145b NIOCore: adjust for label change on Windows (#2130)
`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.
2022-05-30 10:32:30 -07:00
Saleem Abdulrasool 78c97a3cda NIOCore: add missing import for IO (#2129)
Import `ucrt` for access to `strerror` on Windows.
2022-05-30 18:15:24 +01:00
Saleem Abdulrasool 5f8608bf0b _NIODataStructures: repair the build on Windows (#2128)
Import `ucrt` which is the MSVC C library to match the behaviour of the
other platforms.  This allows building `_NIODataStructures` on Windows.
2022-05-30 09:51:13 -07:00
Saleem AbdulrasoolandCory Benfield 78da9a1799 build: correct dependencies for NIOCore (#2127)
The `NIOCore` depends on the platform specific implementation but the
dependency for the Windows platform content was missing.  Adjust this
to repair the build graph for Windows.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-05-30 09:33:04 -07:00
Si BeaumontandCory Benfield b7308b1cd0 DatagramChannelTests: Handle receiving datagrams out-of-order in ECN tests (#2123)
* DatagramChannelTests: Handle receiving datagrams out-of-order in ECN tests

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

* fixup: Simplify calls to write and read integer in payload

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

* fixup: Iterate through expected reads, not actual reads

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

* fixup: Order reads by seq payload and use array equality

* Update Tests/NIOPosixTests/DatagramChannelTests.swift

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-05-30 03:51:52 -07:00
David NadobaandCory Benfield e16a340c57 Adopt Sendable for EventLoopFuture and EventLoopPromise (#2107)
* 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>
2022-05-30 11:35:23 +01:00
David Nadoba 94969e7280 Adopt Sendable in EventLoop.swift (#2101)
* 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
2022-05-30 10:41:18 +01:00
Si Beaumont 8b25ba9761 readme: Fix API docs link following NIO core refactoring (#2126)
Signed-off-by: Si Beaumont <beaumont@apple.com>
2022-05-30 01:03:30 -07:00
Si Beaumont 92d20d92b0 wip: Use clock_gettime for NIODeadline.now() (#2119)
* 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>
2022-05-19 09:28:31 +01:00
Si Beaumont 9294f8da3b NIOPerformanceTester: Increase operations used in lock benchmarks from 1M to 10M (#2121) 2022-05-18 10:53:51 +01:00
David Nadoba 3dcb0f5e9b Introduce internal UnsafeTransfer type (#2115)
Motivation:

Soon we will need to silence some `Sendable` warnings. 
The recommended way is to use a wrapper type that is unconditionally 
`Sendable`. 

https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md#adaptor-types-for-legacy-codebases

Modifications:

- add internal `UnsafeTransfer` type

Result:

We can silence `Sendable` warnings and errors by using `UnsafeTransfer` to pass non-`Sendable` values around.
2022-05-17 08:58:11 +01:00
Si Beaumont 771257cc23 NIOPerformanceTester: Add DeadlineNowBenchmark for NIODeadline.now() (#2117)
* 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>
2022-05-16 19:21:31 +01:00
David Nadoba 391ab9122c Reduce the alloc limits for main (#2118)
The nightly builds have improved, so the alloc limits can drop slightly
2022-05-16 09:56:45 -07:00
David Nadoba 14ffe73e1b Reduce the alloc limits of 1000_tcpconnections for main (#2116)
The nightly builds have improved, so the alloc limits can drop slightly
2022-05-16 02:48:31 -07:00
David Nadoba 4fb931da3f Deprecate unsafe ChannelPipeline.context(handler:) methods (#2109)
`ChannelHandlerContext` is not `Sendable` and can not safly be used outside of its  EventLoop.
2022-05-13 12:39:03 +02:00
David Nadoba bd4366b32c Adopt Sendable for Channel (#2104) 2022-05-11 09:59:51 +01:00
David NadobaandCory Benfield 291143d83d Adopt Sendable for NIONetworkDevice (#2103)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-05-10 09:01:56 -07:00
David Nadoba 54aadfaf38 Adopt Sendable for NIOFileHandle.Mode and NIOFileHandle.Flags (#2102)
`NIOFileHandler` and `FileRegion` are not thread-safe and can not conform to `Sendable`
2022-05-10 16:42:19 +01:00
David Nadoba 45b90b9506 Adopt Sendable for SocketOptionProvider (#2100) 2022-05-10 09:19:54 +01:00
David Nadoba dbbdabb24a Adopt Sendable for Types in ChannelOptions Namespace (#2098)
* Adopt `Sendable` for Types in `ChannelOptions` Namespace

* mark `ChannelOption` as @preconcurrecy Sendable

and introduce `NIOPreconcurrencySendable`
2022-05-09 15:31:36 +01:00
David Nadoba 4fb6bf135b Adopt Sendable for CircularBuffer, MarkedCircularBuffer and types in NIOBSDSocket namespace (#2097)
* 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
2022-05-06 12:34:31 +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