Commit Graph
2140 Commits
Author SHA1 Message Date
George Barnett 7e1ca33bc9 Add performance and allocation tests for canonical form headers (#1953)
Motivation:

To justify performance changes we need to measure the code being
changed. We believe that `HTTPHeaders.subscript(canonicalForm:)` is a
little slow.

Modifications:

- Add allocation and performance tests for fetching header values in
  their canonical form

Results:

More benchmarks!
2021-09-13 16:28:07 +01:00
Cory BenfieldandGeorge Barnett a4a932e95f Add safer abstraction for kqueue filter set. (#1951)
Motivation:

Our kqueue filter set differ logic attempted to stack allocate some
kevent objects and then treat them as a fixed size array by creating a
tuple and then grabbing a pointer to it. That's fairly gratuitously
unsafe, and we should shrink the amount of code that can touch unsafe
stuff.

Modifications:

- Defined KeventTriple, a value type that encapsulates a fixed-size
  array and a length.
- Rewrote calculateKQueueFilterSetChanges to use the new type.

Result:

Safer code in the NIO core

Co-authored-by: George Barnett <gbarnett@apple.com>
2021-09-06 14:59:30 +01:00
Fabian FettandGeorge Barnett 389cd9de57 Update NIOAsyncAwaitDemo to use correct @available checks (post WWDC '21) (#1941)
- Use correct @available checks in `NIOAsyncAwaitDemo` (post WWDC '21)
- Remove `import _Concurrency` statements

Result:
- Cleaner imports
- static-stdlib linking works again on 5.5 (it does not if we explicitly `import _Concurrency`)

Co-authored-by: George Barnett <gbarnett@apple.com>
2021-08-19 16:16:38 +02:00
Fabian Fett 94f41c4121 [Concurrency] completeWithTask expects to receive a @Sendable closure (#1943) 2021-08-19 12:03:46 +02:00
Cory Benfield b05c6f2206 Move NIO to NIOPosix, make NIO a shell. (#1936)
Motivation:

The remaining NIO code really conceptually belongs in a module called
NIOPosix, and NIOCore should really be called NIO. We can't really do
that last step, but we can prepare by pushing the bulk of the remaining
code into a module called NIOPosix.

Modifications:

- Move NIO to NIOPosix
- Make NIO an umbrella module.

Result:

NIOPosix exists.
2021-08-16 16:50:40 +01:00
Cory BenfieldandGeorge Barnett 64285cbff2 Clean up dependencies and imports. (#1935)
Motivation:

As we've largely completed our move to split out our core abstractions,
we now have an opportunity to clean up our dependencies and imports. We
should arrange for everything to only import NIO if it actually needs
it, and to correctly express dependencies on NIOCore and NIOEmbedded
where they exist.

We aren't yet splitting out tests that only test functionality in
NIOCore, that will follow in a separate patch.

Modifications:

- Fixed up imports
- Made sure our protocols only require NIOCore.

Result:

Better expression of dependencies.

Co-authored-by: George Barnett <gbarnett@apple.com>
2021-08-12 13:49:46 +01:00
Cory Benfield f2ab9ab422 Move EmbeddedChannel to its own library. (#1933)
Motivation:

EmbeddedChannel is an important testing tool, and we want to use it
without needing to bring along the POSIX layer. They are not tightly
coupled. However, it also doesn't belong naturally in NIOCore, so we
should probably put it in its own place.

Modifications:

- Moved EmbeddedChannel and EmbeddedEventLoop to NIOEmbedded.
- Moved the tests to NIOEmbeddedTests
- Duplicated some test helpers

Result:

Easy to use EmbeddedChannel without the POSIX layer.
2021-08-11 10:50:32 +01:00
Cory Benfield d62c733653 Extract PriorityQueue to its own module. (#1932)
Motivation:

I'd like to move EmbeddedChannel and friends out of the main NIO
repository and into their own module. Unfortunately, EmbeddedChannel
shares the PriorityQueue implementation we wrote with the various POSIX
channels. To avoid duplicating the code, we should pull it out to its
own module.

However, we've never wanted to commit to the API of this data structure,
and the same is true now. To that end, I'm pulling it into an
underscored module that is not a product of the package.

We could have used the `@_spi` annotation here but honestly I'm a bit
nervous about doing that at the low-level of NIO itself, as if the Swift
team does change the spelling of it at any point in the future we'll be
in real trouble. This way works almost as well, and makes our intent a
lot clearer.

Modifications:

- Extracted Heap and PriorityQueue to a new module.
- Made everything @inlinable to do our best to make performance
  acceptable.

Result:

We can re-use PriorityQueue.
2021-08-09 11:00:03 +01:00
Cory Benfield c1e2f093e8 Move MulticastChannel and NIONetworkDevice to NIOCore (#1931)
Motivation:

MultcastChannel is a general abstraction for expressing multicast
capabilities on a given Channel. This abstraction doesn't have any
particularly tight tie to the POSIX layer, so it belongs in NIOCore.

This is also expressed in terms of NIONetworkDevice, so we need to move
that over. That also encourages us to bring over
System.enumerateDevices, and given that System.coreCount is also fairly
general-purpose we may as well bring it along too.

Modifications:

- Move MulticastChannel to NIOCore
- Move NIONetworkDevice to NIOCore
- Move System to NIOCore

Result:

More general-purpose abstractions in NIOCore.
2021-08-06 13:42:29 +01:00
Cory Benfield a7e064d185 Split and move SocketOptionProvider (#1930)
Motivation:

SocketOptionProvider is a general interface for setting socket options
that are "wider" than a single platform Int. There is nothing inherent
in NIO to require the definition of this protocol to be there, so we
can move it to NIOCore.

Modifications:

- Move the definition of SocketOptionProvider to NIOCore.

Result:

SocketOptionProvider is generally available.
2021-08-05 17:37:05 +01:00
Cory Benfield cdf27b6160 Move the first-party ChannelHandlers to NIOCore. (#1929)
Motivation:

NIO supplies a number of first-party ChannelHandlers that cover specific
use-cases. These aren't tied to the POSIX IO layer and so they should
come out.

Modifications:

- Move ChannelHandlers.swift to NIOCore
- Move NIOCloseOnErrorHandler.swift to NIOCore

Result:

Helper handlers in NIOCore
2021-08-05 10:09:08 +01:00
Cory Benfield 8d3d0e901c Move the Codecs to NIOCore (#1927)
Motivation:

Our basic Channel Handlers don't need to be in NIO anymore: they aren't
realistically tied to that code. So we can move them to NIOCore.

Modifications:

- Move Codecs to NIOCore
- Move SingleStepByteToMessageDecoder to NIOCore.

Result:

Even more stuff in NIOCore
2021-08-05 08:59:01 +01:00
Cory Benfield 670ce76713 Move Marked Circular Buffer to NIOCore (#1923)
Motivation:

MCB is a companion part of circular buffer, and should also be a core
component of NIO.

Modifications:

Move MarkedCircularBuffer to NIOCore

Result:

MCB is in the common code.
2021-08-05 08:07:18 +01:00
Guillaume Lessard 5b1f0c6e91 add setters to complete implementations of MutableCollection (#1925)
- for `CircularBuffer` and `MarkedCircularBuffer`.
- with tests.
2021-08-04 20:02:05 +01:00
buttaface 74b3a8d6a0 Copy Android constants needed by Channel over to NIOCore too (#1924)
Motivation:

Unbreak Android build from NIOCore not having these constants defined.

Modifications:

Copy the same constants that Channel was using in NIO over.

Result:

Android compiles again and the same tests pass.
2021-08-03 20:12:21 +01:00
Si Beaumont e66b64e4e3 _NIOConcurrency: Rename completeWithAsync(_:) to completeWithTask(_:) and return task (#1911)
Return `Task` from `EventLoopPromise.completeWithAsync(_:)` wrapper.

Motivation:

Bridging an `async` function into NIO is done by calling `completeWithAsync(_ body:)` on an `EventLoopPromise`. This spins up a `Task` and `await`s the result of the `async` closure that was passed in and uses the result to fulfil the promise with the value of the function, if it was successful, or with the error, if the function threw.

In some cases we may want to cancel this operation from the outside.

Modifications:

This patch adds a discardable return value to `EventLoopPromise.completeWithAsync(_:)` which is the `Task` it creates.

Result:

Users of `EventLoopPromise.completeWithAsync(_:)` are now able to explicitly cancel the `Task` that is being used to fulfil the promise.
2021-08-03 09:31:08 +01:00
Cory Benfield 12ce699d88 Move UniversalBootstrap to NIOCore. (#1922)
Motivation:

The UniversalBootstrap abstraction allows you to write code that is
agnostic to the specific event loop and channel implementation. This is
likely to be used in places that don't want to have to express a
concrete requirement for a specific channel or loop, and so properly
belongs in NIOCore.

Modifications:

- Move Universal Bootstrap
- Move TCP convenience options, which are required by the universal
  bootstrap.

Result:

Universal Bootstrap will be in NIOCore.
2021-08-03 08:56:45 +01:00
Cory Benfield ca136e8f80 Move Channel abstractions to NIOCore. (#1920)
Motivation:

The most important API surface area in NIO are the Channel abstractions.
These are shared in all NIO programs, and are also used by several
projects to implement their I/O abstraction. There are several moving
parts to this abstraction, all of which are moving:

- Channel itself
- ChannelPipeline
- ChannelHandler

As these all move, they force several other pieces of API to move with
them. Most notably they force us to move NIOAny, which also forces us to
move FileHandle and FileRegion. That also forces us to bring over part
of our syscall abstraction. This duplication is acceptable due to its
minimal surface area, but it is definitely a flaw in our abstraction
design that we had to do that at all.

We also need to move the channel option abstraction, AddressedEnvelope,
and the DeadChannel.

Modifications:

- Moved a bunch of the Channel abstraction over.
- Moved Channel-associated types.

Result:

Channel will be part of NIOCore.
2021-08-02 12:39:28 +01:00
Cory Benfield 2a65f2b4be Add ChannelCore.tryUnwrapAs (#1919)
Motivation:

For Channel implementations, we implemented ChannelCore.unwrapData to
allow them to unwrap a NIOAny into their expected data type. This
remains our recommended flow, as Channels are supposed to know what data
type they can send. However, in a few cases the Channel has a runtime
type: in particular, EmbeddedChannel is capable of tolerating nearly
anything.

As we're coming to split the code apart, we'll likely want
EmbeddedChannel to live in a different module than NIOCore. To that end,
we need to add new API to ChannelCore to allow the specific
EmbeddedChannel use-case.

Modifications:

- Implement ChannelCore.tryUnwrapData.
- Use this within EmbeddedChannel.

Result:

EmbeddedChannel can attempt to unwrap things.
2021-07-26 18:18:46 +01:00
Cory Benfield 8b06e8f996 Fix the missing socket options for 32-bit. (#1918)
Motivation:

When pulling out the NIOBSDSocket later in #1907 we dropped some of the
socket option fixes for 32 bit platforms, which broke them.

Modifications:

Restore the socket options.

Result:

32-bit build should be working again.
2021-07-26 17:24:18 +01:00
Matt EatonandCory Benfield 4c0c5e555c issue-1891: API Addition for JSONSerialization in NIOFoundationCompat (#1906)
Motivation:

Issue for #1891 to add JSONSerialization in NIOFoundationCompat.

Modifications:

Adds:
JSONSerialization+ByteBuffer.swift
JSONSerialization+ByteBufferTest.swift
JSONSerialization+ByteBufferTest+XCTest.swift

Result:

Support for transforming byteBuffer data to a Foundation object.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-07-26 14:21:42 +01:00
Cory BenfieldandGeorge Barnett dc9edbb976 Create ChannelCore.removeHandlers(pipeline:) and use it (#1916)
Motivation:

A while back we added a ChannelCore extension method that would allow
removing handlers from a channel pipeline, in order to implement
Channels outside of NIO. This extension worked well, but it did assume
that you had a Channel to give it. There's no reason it needed a Channel
instead of just a ChannelPipeline, but it was based on the assumption
that Self would conform to Channel. Of course, this is usually true, but
it turns out not to always be true, and EmbeddedChannel is one example
where the Channel and ChannelCore are separate.

To that end, we shouldn't require using the Channel here, just the
ChannelPipeline. This will also let us force our NIO channels onto the
public API, which will make migrating to NIOCore easier.

Modifications:

- Deprecate ChannelCore.removeHandlers(channel:)
- Implement ChannelCore.removeHandlers(pipeline:)
- Swap existing Channel implementations to use the new method.

Result:

More consistent usage of our APIs.

Co-authored-by: George Barnett <gbarnett@apple.com>
2021-07-26 11:03:43 +01:00
David Nadoba 906d5c554b Add ByteBuffer.writeLengthPrefixed (#1902)
A convenience method to write a message and prepend its length in front of it.

### Motivation:
Many protocols use a length field to split a byte stream into multiple separate messages. `swift-nio-extras` supports these kind of protocols through `LengthFieldPrepender` and friends. However, sometimes a channel handler is not the right tool, especially if the a message itself contains multiple dynamic length fields. One example is [RSocket Routing Metadata Extensions](https://github.com/rsocket/rsocket/blob/master/Extensions/Routing.md). 

A `ByteBuffer` is probably a better tool to create this message. This can be tricky to get right if strings are part of the message. A naive solution like the following has two issues:
```swift
func add(tag: String, to buffer: inout ByteBuffer) {
    let length = tag.count
    buffer.writeInteger(UInt8(length))
    buffer.writeString(tag)
}
```
The `count` property in Swift is different than in most other languages. It does **not** return the number of UTF-8 code points and can result in incorrect behavior if multi-byte characters are used (e.g. Emojis). Furthermore, the size of the string could be larger than `UInt8` can represent.
### Modifications:

This PR introduces a new method on `ByteBuffer` called `writeLengthPrefix(endianness:as:writeMessage:)`. It solves both problems mentioned above. It first reserves space for the length prefix and delegates the actually writing of the message to `writeMessage`. Afterwards, it counts how many bytes were written during the call to `writeMessage` and then sets it on the previously reserved space in front of the actually message.

### Result:
We can now write arbitrary content to a buffer and prefix it with the number of bytes written.
```swift
func add(tag: String, to buffer: inout ByteBuffer) {
    buffer.writeLengthPrefix(as: UInt8.self) { buffer in
        buffer.writeString(tag)
    }
}
```
2021-07-22 18:22:08 +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
Cory BenfieldandGeorge Barnett 9f7f17ade9 Add more synchronous pipeline operations. (#1908)
Motivation:

NIO provides some scope for performing "synchronous" ChannelPipeline
operations. These are only safe to perform from the event loop to which
the pipeline is bound, and they avoid the need to check what thread
context you're running on in release mode.

Several of the built-in channels currently skip the public, thread-safe
API to ChannelPipeline in favour of directly calling into the
synchronous pipeline interface. This is going to cause us some trouble
when we pull ChannelPipeline out into NIOCore.

To that end, we should add the rest of the ChannelPipeline API surface
area to the SyncOperations structure and convert ourselves over to using
them.

Modifications:

- Implemented the pipeline operations on SyncOperations
- Added a test
- Swapped our channels to use the new APIs.

Result:

Better abstraction between ChannelPipeline and the Channels

Co-authored-by: George Barnett <gbarnett@apple.com>
2021-07-22 15:28:14 +01:00
40a3794de3 GetaddrinfoResolver: don't block EventLoops (#1887)
Motivation:

GetaddrinfoResolver is blocking the calling thread for anything that
uses a `ClientBootstrap`. Often, `ClientBootstrap`s are used on
EventLoops which obviously creates a problem because you mustn't block
EventLoops.

Modifications:

- Offload the `getaddrinfo` call to a `DispatchQueue`.
- Keep the semantics:
  * only do one concurrent `getaddrinfo` call per SelectableEventLoop
  * prevent thread explosion on `SelectableEventLoop`

Result:

Less EL blocking.

Co-authored-by: George Barnett <gbarnett@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-07-21 10:22:18 +01:00
Cory Benfield 25da619b78 Extract EventLoop protocols and EventLoopFuture to Core (#1898)
Motivation:

The next step on extracting the base abstractions is to pull out
EventLoop, EventLoopGroup and related types, and also EventLoopPromise
and EventLoopFuture. These types are fundamental to the API.

Modifications:

- Extract EventLoop, EventLoopGroup, and related types.
- Extract EventLoopPromise and EventLoopFuture.
- Add new @testable imports.
- Split MultiThreadedEventLoopGroup into new file, appropriately named.

Result:

Better separation.
2021-07-21 07:56:11 +01:00
Cory Benfield 5b56f012e8 Better default for safe loop shutdown. (#1905)
Motivation:

In #1904 we included a change to add a debugging hook to confirm a group
could safely be shut down. Sadly, the default behaviour was too
aggressive, and would cause failures in downstream projects.

Modifications:

- Change the default behaviour of _preconditionSafeToSyncShutdown to be
  a no-op, as it currently is in NIO programs today.

Result:

Downstream projects won't break.
2021-07-20 16:24:59 +01:00
Cory Benfield c9fb1c23a1 Avoid syncShutdownGracefully knowing about MTELG. (#1904)
Motivation:

As part of the ongoing split of NIO into two components, we need to
decouple EventLoopGroup from MultiThreadedEventLoopGroup. This is
largely straightforward, but EventLoopGroup.syncShutdownGracefully uses
a hook on MTELG to try to provide debugging help.

That hook cannot stand, so we must break it. Unfortunately this slightly
reduces our ability to detect possible blocks of a SelectableEventLoop,
but in return we get to increase our ability to detect blocks of other
event loop groups.

Modifications:

- Added a debugging hook to detect possible blocking of event loops.

Result:

Less coupling.
2021-07-20 13:22:41 +01:00
Cory Benfield 3e94fb4504 Enable all EventLoops to track promise creation. (#1899)
Motivation:

EventLoopFuture is capable of tracking where it was allocated from in
debug mode, to enable high-fidelity tracking of leaked promises.
Currently this behaviour is limited to SelectableEventLoop, but there is
no good reason to tie it so specifically to that loop.

Modifications:

- Extend `EventLoop` to allow all event loops to track promise
  allocation and destruction.
- Add helpers to `EmbeddedEventLoop` to let it participate.
- Add new type to express a future ID.

Result:

Wider support for diagnostics.
2021-07-16 13:26:28 +01:00
Cory Benfield 58ae43e99f Avoid EventLoopFuture.wait knowing about specific implementations. (#1900)
Motivation:

As we break apart NIO, it's a bit awkward that EventLoopFuture.wait
knows about two specific EventLoop implementations. It does this in
order to detect deadlocks, so we should try to preserve the capability
as best as possible.

Modifications:

- Add EventLoop._preconditionSafeToWait, which can reproduce much of the
  logic currently in EventLoopFuture.wait().
- Provide implementations for SelectableEventLoop and EmbeddedEventLoop.

Result:

Partial reproduction of the current behaviour of EventLoopFuture.wait().
Unfortunately this cannot completely reimplement this behaviour, as we
cannot safely call MultiThreadedEventLoopGroup.currentEventLoop for all
event loops. This is as close as we can safely get without breaking the
abstraction boundary, sadly.
2021-07-16 10:18:34 +01:00
Cory Benfield f607e5a47c Extract basic data structures to NIOCore. (#1895)
Motivation:

Currently the "core" NIO module (currently called NIO) contains two
fairly distinct kinds of things. The first is the core abstractions and
data structures: the things that all NIO programs must necessarily deal
with. This includes our base abstraction protocols (e.g. `EventLoop`,
`Channel`, and `ChannelHandler`), as well as our base data types (e.g.
`ByteBuffer`, `SocketAddress`, `EventLoopFuture`).

The second thing the core NIO module contains is the default POSIX
sockets event-loop and channels. These are the mainline production loops
for NIO programs, and are supported in the various BSD-like OSes to
varying extents. These can be thought of as a baseline implementation of
the core abstraction protocols that form the first part of NIO.

These two fairly distinct use-cases have no particular reason to be
glued together, and in fact in gluing them together we have done a bit
of a disservice to our adopters. The biggest issue is that it has become
impossible to write a NIO program or library that does not bring along
the POSIX layer of NIO. This has made porting NIO to other platforms
difficult (Windows has been painful, and Webassembly is coming down the
road as well), and has also bloated the size of iOS/macOS applications
that use NIO via NIOTransportServices, as all of these applications must
bring along an event loop and several Channels they will not use.

To that end, we plan to begin a scope of work to split the core NIO
module in two. Specifically, we intend to extract the baseline protocols
and data types into a new module, called `NIOCore`, which will be able
to be the baseline NIO module.

The end goal is that libraries that implement protocols on top of
SwiftNIO should be able to depend solely on `NIOCore`, not `NIO`. This
will allow NIO applications to bring along only the event loops they
want or need, without needing to pay for the POSIX sockets
implementation. This should also make porting easier, as there will be
no pressure to bring the existing `NIO` module to new platforms if it
does not fit well.

Modifications:

This is the first in a series of patches, which extracts some of the
low-hanging fruit. In particular, it extracts:

- `ByteBuffer` (and associated types)
- `RecvByteBufferAllocator`
- `CircularBuffer`

This also adds in the backwards compatibility shim: the `NIO` package
performs an exported import of `NIOCore`. This will allow this change to
avoid breaking API.

However, to make a clean break we intend not to release a new NIO minor
version until we have completed our extraction. If we fail to do this it
won't be the end of the world, we can release subsequent minor versions
that continue to extract new types. However, as much as possible should
go at once.

This patch also duplicates a few methods and files. At the end of the
patch series we need to reconcile this duplication. In many cases the
duplication will no longer be necessary, but in some cases we may have
necessary duplicates.

Result:

The first step along the road to better platform citizenship is taken.
2021-07-14 09:58:25 +01:00
Johannes Weiss 87c532383a remove NIO1 API shims (#1897)
Motivation:

The lastest NIO versions require Swift 5.2+ to compile. Given that
hopefully nobody ever created a NIO1 application for Swift 5.2+, I'd say
it's about time to remove the NIO1 API shims (and related docs).

Modification:

- remove the NIO1 API shims
- remove the migration docs

Result:

Less code.
2021-07-13 12:36:28 +01:00
Guillaume LessardandGuillaume Lessard 69f1f2d29c add a missing subscript(bounds:) implementation (#1893)
- an older version of the standard library supplied a bogus implementation
  by error. Calling *that* would have been a crashing bug.

Co-authored-by: Guillaume Lessard <guillaume.l@apple.com>
2021-07-10 06:48:29 +01:00
Austin ffa6a871f7 Feature: Datagram Packet Info (#1888)
* Break out control message parsing by IP version

* Add shims for Darwin packet info

* Add shims for Linux packet info

* Add channel option for receiving datagram packet info

* Add NIOPacketInfo to AddressedEnvelope.Metadata

* Pipe up packet info channel option to receive path

* Add NIOPacketInfo info and fix backwards compatability

* Document packet info socket options

* Cleanup packet info control message parsing

* Add packet info and ECN combined tests

* Find real interface index during NIOPacketInfo tests

* Add PacketInfo tests to Linux tests
2021-07-08 11:04:53 +01:00
Peter Tolsma 3f33ef369f Make ByteBuffer unconditionally use zero-copy for JSON Decoding (#1889) 2021-07-05 08:05:16 +01:00
d1b7c07883 Adds Equatable and ExpressibleByArrayLiteral conformance to ByteBufferView (#1886)
* Adds Equatable and ExpressibleByArrayLiteral conformance to ByteBufferView

* Adds linux test

* Equatable conformance compares slices of buffers

* Adds Hashable conformance to ByteBufferView

* Runs script for linux tests

* Force unwrap slicing the buffer in ByteBufferView equatable conformance implementation

* Adds Hashable conformance tests

* Addresses comments on test-related changes

* Minor grammar change

* Generates linux tests

Co-authored-by: Matteo Comisso <matteocomisso@skyscanner.net>
Co-authored-by: Matteo Comisso <matteo.comisso@me.copm>
2021-06-30 10:26:40 +01:00
Antoine CœurandAntoine Cœur d79e33308b docs: formatting comments with double slash (#1881)
Motivation:

Triple slashes should be for exportable documentation (like functions declarations).

Modification:

Replaced `///` with `//`.

Result:

Better looking code comments.

Co-authored-by: Antoine Cœur <acoeur@apple.com>
2021-06-21 11:58:10 +01:00
Si Beaumont 7f3a2f56b0 Add async implementation of EventLoopGroup.shutdownGracefully to _NIOConcurrency (#1879)
* Add async implementation of EventLoopGroup.shutdownGracefully to _NIOConcurrency

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

* fixup: Move elg lifecycle into async function in async demo

* fixup: Ensure continuation is run exactly once

* fixup: Shutdown event loop group in catch in async demo
2021-06-14 10:51:42 +01:00
buttaface a1f405285a Fix tests for 32-bit platforms, tested for Android armv7 (#1877)
Motivation:

Get the tests passing on 32-bit platforms again.

Modifications:

- Change the way _UInt56.max is initialized.
- Set the proper max capacity for AdaptiveRecvByteBufferAllocator
  and change the test to match it.
- Add a cmsghdrExample for Android armv7.

Result:

All the same tests pass on Android armv7 as Android AArch64.
2021-06-11 12:20:19 +01:00
Cory Benfield 67f0843653 Concurrency features are runtime-specific. (#1876)
Motivation:

The Swift concurrency features are only available in specific releases
of platforms where the Swift runtime ships with the platform. We need to
add availability guards to reflect that.

Modifications:

- Added appropriate availability guards for the async/await methods.

Result:

More likely to compile on Apple platforms.
2021-06-10 11:23:53 +01:00
akash-55andCory Benfield 7688cf712f #1714 Update Codec.swift (#1873)
* Update Codec.swift

* Update Sources/NIO/Codec.swift

Co-authored-by: Cory Benfield <lukasa@apple.com>

Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-06-09 15:57:47 +01:00
Tim Condon 6d05b4f64b Update _NIOConcurrency for Swift 5.5 latest changes (#1872) 2021-06-09 10:41:47 +01:00
Maxim ZaksandCory Benfield c776f6e539 Improving performance of base64 encoding by about 10% (#1862)
* Improving performance of base64 encoding by about 10%

* revert alphabet change and use String(customUnsafeUninitializedCapacity:initializingUTF8With:)

* Add performance test for random request key generation

* use reduce

* fix indentation

* add `@inlinable` on custom unsefe inializer for older Swift version

* fix issues mentioned in review

Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-06-07 11:12:06 +01:00
Bastian Inuk ChristensenandCory Benfield 93a40323d0 Made the externs const in CNIOLinux (#1869)
* Made the extern to const in CNIODarwin ##1867

* Added const to LNX

Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-06-03 12:32:40 +01:00
Bastian Inuk Christensen 7db25900ab Made the extern to const in CNIODarwin ##1867 (#1868) 2021-06-03 12:04:37 +01:00
Cory Benfield 0b3a8e4e34 Work around awkward SO_TIMESTAMP definition. (#1866)
Motivation:

On some Linux platforms the definition of SO_TIMESTAMP is too complex
for the clang importer to handle. Delegate to C to find out what it
should be. The same problem applies to SO_RCVTIMEO.

Modifications:

- Define SO_TIMESTAMP in CNIOLinux instead.
- Define SO_RCVTIMEO in CNIOLinux instead.

Result:

Should build on the awkward Linux platforms.
2021-06-02 11:15:58 +01:00
Johannes Weiss b23f40b4fa add Swift 5.5 job (#1845) 2021-06-01 18:58:56 +01:00
Johannes WeissandCory Benfield e1aebf76e8 http_parser: update vendored copy (#1822)
Motivation:

It's good to update vendored deps.

Modification:

Update http_parser

Result:

newer code.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-06-01 15:26:10 +01:00
Maxim ZaksandCory Benfield cf054f27b5 Add performance test for web socket client random request key (#1863)
* Add performance test for web socket client random request key

* use `reduce` function to minimise memory consumption of the test

Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-06-01 11:08:13 +01:00