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:
Swift started using posix_memalign very recently (Jan 2019) so we need
to hook that too to get correct results.
Modifications:
Hook posix_memalign, reallocf & valloc
Result:
alloc tests should pass again
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:
Certain warnings we want to ignore in CI builds but we want to keep
`-warnings-to-errors` on.
Modifications:
define `NIO_CI_BUILD` in the CI builds
Result:
can ignore select warnings in CI
Motivation:
Forgot to introduce the -warnings-as-errors parameter in the `test:`
directive in the docker compose file.
Modifications:
added warnings-to-errors to the docker-compose.yml for 5.0
Result:
warnings to errors
Motivation:
When we write unit tests, we generally like them to actually test the
thing they claim to. This test never ran, and the assertions in place
to verify that it ran also never ran, so we didn't notice the test
not running.
Modifications:
- Moved the assertion that validates the test ran to a place where
it will definitely execute.
- Ensured the EmbeddedChannel gets marked as active, so that we
actually deliver the bytes from the HTTPDecoder.
Result:
This test will run, and actually pass.
Motivation:
SemVer requires us to declare a public API, we should do so for NIO 2.
Modifications:
declare our public API.
Result:
more transparency into our versioning policy.
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"
Motivation:
SwiftPM recently introduced a feature that allows you to link libraries
without special system libraries.
Modifications:
make CNIOZlib link zlib directly
Result:
fewer repositories
Motivation:
BaseSocketChannel used to assert that `channelRead0` is only called when
the channel is active. That's bogus and it's trivial to hit this issue
when calling `fireChannelRead` in the last `ChannelHandler` when the
channel has gone inactive.
Modifications:
remove assertion, add comment
Result:
fewer crashes
Motivation:
We now depend on Swift 5.0, so we can remove all the backporting of
functionality.
Modifications:
deleted all backported Swift functionality
Result:
less code
Motivation:
No code is the best code, let's have the compiler generate more
Equatable instances for us.
Modifications:
remove some hand-written Equatable conformances
Result:
less code, possibly fewer bugs
Motivation:
Now that the stdlib has introduced the Result type, we can use it in the
implementation (and the whenComplete) function of EventLoopFuture
Modifications:
- replace EventLoopValue with Result
- make whenComplete provide the Result
Result:
use the new shiny stuff
Motivation:
DispatchData's APIs are less than optimal and the current one we used
did allocate at least on Linux to copy bytes out.
Modifications:
introduce ByteBuffer.write/read/set/getDispatchData
Result:
when Dispatch gets fixed, lower allocations
Motivation:
We had to disable the allocation test because of a SwiftPM bug which is
now fixed.
Modifications:
re-enable the allocation tests
Result:
more tests == better
BUGFIX: BlockingIOThreadPool not releasing the latest WorkItem
Fix is to clear the latest work item just before waiting for
the next one to be submitted.
Added two tests to validate the fix: submitting only one work item
to an IO thread pool, and submitting two consecutive work items.
Thanks to Gwynne Raskind for help troubleshooting & fix
(cherry picked from commit 8df414b716)
* Use fixed default string to write in response and do not hardcode content length
Motivation:
Improve example code, resolve#714
Modifications:
Move hardcoded "Hello world" string to a constant property and removed hardcoding of content length header value
Result:
In example code content length will be written correctly when default response changes
Motivation:
Swift 5 contains a regression where we get 1 extra allocations for the
ByteBuffer read/write allocation test.
I will track this problem down but for now it's important to unblock
other NIO2 work.
Modifications:
raise the allowed allocations for the ByteBuffer RW test by 1
Result:
allocation tests can be re-enabled again.
Motivation:
Swift 5 contains a regression where we get 2 extra allocations per
HTTP/1.1 request/response pair _only on Linux_. That happens both on
`master` as well as on `nio-1.12`.
I will track this problem down but for now it's important to unblock
12 work.
Modifications:
raise the allowed allocations per HTTP/1.1 req/res pair to 38 (from 36)
for Swift 5.
Result:
allocation tests can be re-enabled again.
Motivation:
that snapshot fixes https://bugs.swift.org/browse/SR-9518 which blocks
the allocation tests and therefore #710 .
Modifications:
made our docker use the 2012-12-28 snapshot.
Result:
allocation tests hopefully work again because Swift doesn't accidentally
forget to decrease some reference count anymore.
Motivation:
Newer versions of SwiftPM for the Swift 5 release have changed the output
format of swift package dump-package. This has broken our
list_topsorted_dependencies script. This script is highly useful, so we'd
like to keep it working.
The discussion on SR-9191 suggests that SwiftPM considers this format
changeable at any time, so we may need to make a change like this in future.
We may want to consider writing tests for this script to ensure its continued good functioning.
Modifications:
- Amended the jq scripts to parse the new JSON format.
Result:
list_topsorted_dependencies will work with Swift 5 development copies of
SwiftPM. Note that this will break this script with earlier copies of SwiftPM,
but as we only support Swift 5 on the master branch this change is safe to
make.
Motivation:
The rest of the code in NIO uses multiline literals.
Modifications:
Converted string concatenations to multiline literals.
Result:
NFC, prettier code.
* Pass `--module-version` and `--root-url` parameters to `jazzy`
### Motivation:
It would be good if the API document was distributed as a docset that can be installed in Dash, like [Yams](https://www.jpsim.com/Yams/).
### Modifications:
Pass `--module-version` and `--root-url` parameters to `jazzy`.
### Result:
Jazzy generates docsets and add "Install in Dash" link to `index.html`.
* Apply review: Avoid appending `args`
Motivation:
We're at the moment devloping NIO 2 and we should tell people.
Modifications:
- changed readme
- document how to develop with the latest Xcode
Result:
- fixes#771
Motivation:
ContiguousCollection is no longer necessary because Sequence gained
withContiguousStorageIfAvailable.
Modifications:
Removed ContiguousCollection and switch to withContiguousStorageIfAvailable.
Result:
less code
Motivation:
A few things are public by accident, this makes those internal for NIO
2.0.0.
Modifications:
internalise a few things
Result:
less public API
* Remove method from ChannelOutboundInvoker protocol that can be extensions.
Motivation:
We should not have methods in the ChannelOutboundInvoker that can easily implemented as extension and that never need to be overriden.
Modifications:
Remove methods that return EventLoopFuture<Void> from the protocol and just implement it in the extension.
Result:
More narrow protocol.
* Address comment
Motivation:
CircularBuffer.replaceSubrange was crazy eager to double the capacity
which is bad.
Modifications:
Made CircularBuffer.replaceSubrange only double if necessary.
Result:
less memory usage
Motivation:
The new shiny Swift 5 gives us fast access to the UTF8 bytes (if
available, which mostly means not bridged from Cocoa), we should use
that.
Modifications:
use UTF8View.withContiguousStorageIfAvailable
Result:
faster String access
Motivation:
ByteBuffer has pretty good string writing APIs, but they're imperfect.
In particular, the methods in ByteBuffer-aux both return optional Int,
which is strange as they cannot fail. We also only have support for writing
strings in UTF-8.
Modifications:
- ByteBuffer.set(string:at:) and ByteBuffer.write(string:) now both
return `Int`, and their return value has been made discardable.
- NIOFoundationCompat has been expanded with two new methods for writing
strings to ByteBuffers in various encodings using Foundation's
encoding support: ByteBuffer.set(string:encoding:at:) and
ByteBuffer.write(string:encoding:).
- NIOFoundationCompat has also been expanded with a companion to the
already existing ByteBuffer.getString(at:length:encoding), namely
ByteBuffer.readString(length:encoding:).
- New error enum for reporting failures to encode.
Result:
Easier to work with strings in a wider variety of cases with
ByteBuffer
Resolves#253.
Motivation:
Modules outside of NIO core must be able to create `EventLoopIterator`s
in order to conform to the `EventLoop` protocol, therefore we need an
initialiser that's available.
Modifications:
add public initialiser to construct EventLoopIterator from [EventLoop]
Result:
others can implement EventLoops again
Motivation:
The latest Swift 5.0s bring us new goodies (hence tools version) and
also more warnings, hence the fixes for them.
Modifications:
- set tools-version to 5.0
- fix warnings
- workaround https://bugs.swift.org/browse/SR-9514
Result:
happier developers
Motivation:
SwiftPM was very outdated on the old Swift snapshots, we should update
the CI.
Modifications:
use swift-5.0-DEVELOPMENT-SNAPSHOT-2018-12-13-a-ubuntu18.04.tar.gz
Result:
can use swift-tools-version: 5.0 and all the goodies from that