Motivation:
Previously B2MDs didn't really have defined semantics regarding EOFs and
we didn't tell them if there was an EOF. Also `decodeLast` was optional
and all that was bad.
Modifications:
- require `decodeLast`
- add a `seenEOF: Bool` parameter to `decodeLast` which tells the
decoder if an EOF has been seen
Result:
- clearer semantics
- more information
Motivation:
- `ChannelPipeline.add(name:handler:...)` had a strange order of arguments
- `remove(handler:)` and `remove(ctx:)` both remove `ChannelHandler`s
but they read like they remove different things
So let's just fix the argument order and name them `addHandler` and
`removeHandler` making clear what they do.
Modifications:
- rename all `ChannelPipeline.add(name:handler:...)`s to `ChannelPipeline.addHandler(_:name:...)`
- rename all `ChannelPipeline.remove(...)`s to `ChannelPipeline.removeHandler(...)`
Result:
more readable and consistent code
Motivation:
A few shims were missing public access modifiers, and at least one
should have been static but wasn't. These would lead to hard compile
errors.
Modifications:
Threw the words "public" and "static" around. Like Java!
Result:
Fewer compile errors, more compile warnings.
Motivation:
Opaque indices are a good idea for collections, (Marked)CircularBuffer
should use those too.
Modifications:
Cheapest possible implementation for opaque indices, could be much
improved. This is the cheapest possible implementation for opaque
indices and this could be much improved later, see #682 but the
improvements won't be SemVer major :).
Result:
first stab at #682
Motivation:
ChannelOptions used a too complicated mechanism for what they are.
Modifications:
- change the ChannelOptions to a much simpler mechanism
- rename the generic parameters from T to Option
Result:
code easier to read and understand
Motivation:
Collisions with Foundation and other standard libraries is painful.
Modifications:
- rename `FileHandle` to `NIOFileHandle`
- rename `Thread` to `NIOThread` (only exposed in docs)
Result:
fewer collisions
Motivation:
ChannelOptions should've always been Equatable and so far we've hacked
around them not being Equatable when we wanted to compare them.
Modifications:
make all ChannelOptions Equtable
Result:
- ChannelOption comparison actually works
- fixes#598
- make more ChannelOptions stuff inlinable to not regress allocations
Motivation:
public/internal modifiers for `extension`s are confusing as a
`func foo` is public if within a `public extension`.
Modifications:
remove all `internal` (redundant) and `public` (dangerous) modifiers for
`extensions`.
Result:
- code easier to read
- code much easier to review in a small diff
### Motivation:
A convenience/shorthand for developers.
### Modifications:
Add conformance to ExpressibleByDictionaryLiteral along with implementation.
### Result:
The following is would then be legal in Vapor:
```
return HTTPResponse(status: .ok, headers: ["Content-Type": "text/html"],
body: "<table border=1><tr><td><i>Hello</i>, plugin!")
```
Motivation:
As part of NIO2 - much work has been done to round out the API of EventLoopFuture. This finishes existing public API parameters to be more in line with Swift API guidelines.
Modifications:
Methods in EventLoopFuture that had `eventLoop` as a parameter label have been changed to `on`
Results:
EventLoopFuture public API is more "Swifty" with calls such as `future.hop(to: eventLoop)` rather than `future.hopTo(eventLoop: eventLoop)`
Motivation:
Some of the ChannelPipeline removal methods did not go through the
RemovableChannelHandler API.
Modifications:
make all removal APIs go through the RemovableChannelHandler API
Result:
fewer bugs
Motivation:
Previously CircularBuffer.removeAll would always allocate (a new backing
store), even when `keepingCapacity: true`.
Modifications:
Don't make CircularBuffer allocate unnecessarily
Result:
faster CircularBuffer.removeAll
Motivation:
ByteBuffer methods like `set(string:)` never felt very Swift-like and
also didn't look the same as their counterparts like `getString(...)`.
Modifications:
- rename all `ByteBuffer.set/write(<type>:,...)` methods to
`ByteBuffer.set/write<Type>(...)`
- polyfill the old spellings in `_NIO1APIShims`
Result:
code more Swift-like
Motivation:
If ChannelHandler removal worked correctly, it was often either by
accident or by intricate knowledge about the implementation of the
ChannelHandler that is to be removed. Especially when it comes to
re-entrancy it mostly didn't work correctly.
Modifications:
- introduce a `RemovableChannelHandler` API
- raise allocation limit per HTTP connection by 1
(https://bugs.swift.org/browse/SR-9905)
Result:
Make things work by contruction rather than accident
Motivation:
Many users may wish to see the underlying TCP connection state for
important calculations, such as for BDP or RTT numbers. We can make this
available easily enough.
Modifications:
- Added a function to get TCP_INFO on Linux/FreeBSD.
- Added a function to get TCP_CONNECTION_INFO on Darwin.
Result:
Better connection stats
Motivation:
A race condition occurs when a socket is closed from the remote end after `accept()` returns it, but before `fcntl(F_SETFL, F_SETNOSIGPIPE)` is invoked. This causes the `fcntl()` call to fail with `EINVAL` ("The socket has been shut down."). This currently triggers an assertion failure. As the race depends on the remote and can be easily demonstrated (using `nmap` is a good way to set it off), the assertion is semantically invalid (`EINVAL` is not programmer error). Additionally, errors reported by `fcntl()` in general are being ignored when not asserted.
Modifications:
The race is avoided by treating `EINVAL` as a normal error while retaining the existing behavior for all other error cases. Both uses of `fcntl()` to disable `SIGPIPE` now properly report errors.
Result:
`Posix.accept()` and `Posix.socket()` may now potentially throw additional errors. It is no longer possible to crash a debug server by running `nmap` against it.
Motiviation:
After adding `ELF.whenAllComplete` the concept of "fail fast" and "fail slow" for reducing an array of future results together was introduced.
This commit adds that concepts with the `andAll* methods that act as simple completion notifications.
Modifications:
Rename `EventLoopFuture.andAll(_:eventLoop:)` to `andAllSucceed(_🔛)` to denote its "fail fast" nature, and to match Swift API guidelines.
Add new `EventLoopFuture.andAllComplete(_🔛)` for a "fail slow" companion.
Shift implementation of `whenAllComplete(_🔛)` to be usable without unnecessary allocations in `andAllComplete`
Result:
EventLoopFuture now has two methods for "flattening" arrays of EventLoopFuture into a single notification ELF
Motivation:
The `ELF.cascade` methods have a parameter label `promise` that does not match Swift API Guidelines, and a way to cascade just successes is not available - while for failures there is.
Modifications:
`ELF.cascade*` methods that already exist have had their `promise` label renamed to `to`, and a new `ELF.cascadeSuccess` method has been added.
Result:
EventLoopFuture now has the cascade methods `ELF.cascade(to:)`, `ELF.cascadeFailure(to:)`, and `ELF.cascadeSuccess(to:)`
Motivation:
`ELF.whenAllComplete` is a "fail slow" method that returns an `EventLoopFuture` that always succeeds after all provided futures complete - fulfilling with all the results of the futures.
`ELF.whenAllSucceed` is a "fail fast" method that returns an `EventLoopFuture` that succeeds if all of the futures succeed - and returning the fulfilled values.
This new method acts as a counterpart to both `ELF.whenAllComplete` and `andAll`
Modifications:
Add `ELF.whenAllSucceed` that returns an EventLoopFuture with all of the values provided from the futures being awaited.
Rename `ELF.whenAllComplete(_:eventLoop:)` to `ELF.whenAllComplete(_🔛)` to match new `whenAllSucceed` and Swift API guidelines
Result:
New method for flattening multiple futures into a single EventLoopFuture that fulfills with an array of their success values if they all succeed.
Motivation:
For compatibility reasons, we used to disable HTTP1 error handling by
default to not break SemVer.
Modifications:
enable HTTP1 error handling by default
Result:
HTTP1 protocol errors now handled automatically by default
Motivation:
Quick Documentation was not rendering some parameter documentation
correctly as it was over-indented.
Modifications:
Reduced indentation for over-indented parameters.
Result:
Quick Documentation renders correctly.
Motivation:
testCloseInReadTriggeredByDrainingTheReceiveBufferBecauseOfWriteError
expected (without knowing it) that networking on localhost is
synchronous enough that a succeeded write means that it has
simultaneously arrived in the reader's read buffer.
On macOS that's not necessarily true, so this test failed very seldom
seemingly more often if you had more physical cores.
Modifications:
Introduce a nasty blocking `poll` call in the test that waits until we
have bytes in the read buffer.
Result:
- fixes#657
Motivation:
While getting into NIO through the examples I stumbled
accross some chained dropFirst() calls, which can be
simplified by using dropFirst(_:) instead.
Modifications:
I did a quick project-wide search of chained dropFirst()
usage and modified every line to use dropFirst(_:) instead.
Result:
This will only effect the readability of the code,
not its functionality.
Remove EmbeddedChannel restriction to IOData
Motivation:
You should be able to read any type from the outbound buffer.
Modifications:
Change Embedded channel outboundBuffer and pendingOutboundBuffer to store NIOAny instead of IOData and refactor test code accordingly.
Result:
- Users can test what went through the pipeline without serializing everything and using "if case let" syntax everywhere.
- fixes#551
* Add cancel notification to RepeatedTask
Motivation:
When cancelling a RepeatedTask, it is often desirable to
wait until any still in-progress execution of the task is
finished - for example, to know when a periodic state save
is done before shutting down. The current API provides no
easy way to perform such a wait. With this addition,
repeating tasks can report completion of a cancellation
request regardless of in what state the task was in when the
request was issued.
Modifications:
A default-nil parameter is added to EventLoop.scheduleRepeatedTask(),
to which a promise can be provided; the promise will be
fulfilled at the time of the task's cancellation, plus any
time required for the task to complete running if it was
cancelled during execution. The promise is signaled even if
the cancellation is the result of the task throwing an error.
A default-nil paramter is also added to RepeatedTask.cancel(),
to which a second promise can be passed. This promise is
fulfilled under the same conditions as the first, even if the
first was not given; neither of the promises is dependent
upon the other and both are fulfilled at the same time if
provided. Further calls to cancel() with different promises
will result in fulfillment of each of those promises as well.
Result:
The observed behavior of RepeatedTask.cancel() now optionally
includes deterministic knowledge of when the task is no longer
executing or scheduled to be executed. The API changes are
designed to be additive in form, but the function signatures
do change. Source compatibility is maintained; binary
compatibility is not.
Motivation:
initialRingCapacity is not a great name, initialCapacity is much better
Modifications:
rename CircularBuffer(initialRingCapacity:) to initialCapacity
Result:
more consistent code
Motivation:
Newer Swift versions are good and we should test them, this one threw a few curveballs at us:
- started using `posix_memalign` which needed fixing in our alloc tests (fixed in #782)
- the optimiser decided not to inline a function that needs to be inlined
Modifications
- `@inline(__always)` to help the optimiser
- update Swift version
Result:
- fixes#727
- fixes#726
Add deadlines as an alternative to timeouts
Motivation:
Address #603
Modifications:
- Add NIODeadline type
- Add func scheduleTask<T>(deadline: NIODeadline, _ task: @escaping () throws -> T) -> Scheduled<T>
- Reduce the use of DispatchTime in favor of Time
- Replace timeout calls with deadline calls where it makes sense
Result:
Tasks can be scheduled after an amount of time has passed, or at a certain time.
Motivation:
ELFs and the stdlib's Result should be as compatible as possible so a
flatMapResult function which lifts and combines a result into an
EventLoopFuture sounds like a good idea.
Modifications:
add `flatMapResult` which does what it says.
Result:
more interop between `Result` and `EventLoopFuture`.
Motivation:
The name `mapIfError` implied that you can transform the error value but
really that's never what it did. Instead, it allowed you to recover
from a failure.
Modifications:
- rename `mapIfError` to `recover`
Result:
cleaner method names
Motivation:
EventLoopPromise.succeed/fail has extraneous labels that don't add
anything but noise.
Modifications:
remove extraneous labels
Result:
less noise in the code
Motivation:
It's important that in NIO1 API Shims everything that's defined is also
deprecated. Unfortunately I forgot one.
Modifications:
- deprecate thenIfErrorThrowing
Result:
- Xcode will correctly suggest changing thenIfErrorThrowing to flatMapErrorThrowing
Motivation:
Due to https://bugs.swift.org/browse/SR-9604, ByteBuffer.getBytes
seriously regressed (factor 10x) since NIO 1.11 . This works around it
until the issue is fixed.
Modifications:
bind the memory to UInt8s to get an UnsafeBufferPointer<UInt8> rather
than an UnsafeRawBufferPointer.
Result:
- getBytes 10x faster
- make @John-Connolly happy, thanks for reporting!
Motivation:
The switch from `ELF.then*` to `ELF.flatMap*` is pretty big so we should
provide NIO1 API shims.
Modifications:
add API shims for ELF.then*
Result:
easier for people to migrate from NIO1 to NIO2.
Motivation:
ELF's API should be as close as possible to the new Result's API.
Therefore, we should rename `then` to `flatMap`
Modifications:
- renamed `then` to `flatMap`
- renamed `thenIfError` to `flatMapError`
- renamed ELF's generic parameter from `T` to `Value`
Result:
- more like Result
- fixes#688
Motivation:
For package authors, the NIO1 to 2 transition can be taxing because we
keep changing things. So far, the community has done an incredible job
keeping up with our changes but we'd like to make it as easy as possible
continuing to do so.
Modifications:
- add a `_NIO1APIShims` module that when imported tries to provide some
of the NIO1 API in NIO2 with helpful fixup messages
Result:
easier transition from NIO1 to NIO2
Motivation:
While it's really a good idea to keep track of where promises get
allocated, once the promise has been fulfilled we probably don't
need to keep track of it any more.
Happily this leak only affects debug mode.
Modifications:
- Actually removed the element from the promise log when we
said we would.
Result:
Memory usage doesn't get totally out of hand in debug mode.
* Make EventLoopFuture.cascade and cascadeFailure accept an optional promise
Motivation:
fixes#756
Modifications:
Change EventLoopFuture.cascade to func cascade(promise: EventLoopPromise<T>?)
Result:
EventLoopFuture.cascade can be called without needing to check if the promise is nil
Motivation:
Addressing the https://github.com/apple/swift-nio/issues/713
Modifications:
Forward the statusCode from NIOHTTP1Server main handleJustWrite to ctx.writeAndFlush instead of always using "ok"
Result:
ChannelHandlerContext will write the correct status code even when it's not "ok"