Motivation:
We left a doc comment on EventLoopFuture.map that caused confusion by
misleadingly claiming that it could handle throwing functions. The
operation that handles throwing functions is flatMapThrowing.
Modifications:
- Removed the misleading comment and pointed users to flatMapThrowing
instead.
Result:
Less user confusion.
Motivation:
In #957 we accidentally broke the API just a little bit. We turned the
`ByteToMessageHandler.init` from
public init(_ decoder: Decoder)
into
public init(_ decoder: Decoder, maximumBufferSize: Int? = nil)
This looks totally benign and in almost all cases because of the default
argument, you wouldn't notice the API breakage. However, it's possible
to write code that works in NIO 2.0.0 but breaks in NIO 2.1.0. For
example
let g: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init
let h: (Dummy) -> ByteToMessageHandler<Dummy> = ByteToMessageHandler<Dummy>.init(_:)
Modifications:
According to SemVer, this releases a patch that unbreaks the public API.
Result:
No API breakages (checked with `swift-api-digester` which also found the
breakage in the first place).
Add an `always` method on EventLoopFuture
Motivation:
https://github.com/apple/swift-nio/issues/665
Modifications:
* Add `always` in EventLoopFuture.swift
* Add tests
Result:
NIO Users will be able to use `.always` to, well, always run an action
wether the future succeed or not.
Motivation:
New public NIO types must be nested in existing ones or `NIO` prefixed.
This wasn't the case for ByteToMessageDecoderPayloadTooLargeError
Modifications:
nest PayloadTooLargeError into ByteToMessageDecoderError
Result:
we stick to our rules.
Motivation:
While CircularBuffer has an inlinable implementation to improve performance, MarkedCircularBuffer
never got enhanced to have it. This harms performance in many core NIO libraries which heavily use
MCB, forcing heap allocations on almost all MCB operations.
Modifications:
- Make basically everything on MarkedCircularBuffer inlinable.
Result:
Faster code.
Motivation:
The new file RW opening facilities didn't have any tests and it didn't
let you specify arbitrary POSIX flags.
Modifications:
- Add tests.
- Let users specify both POSIX flags & mode.
Result:
Better code quality.
Motivation:
Structures that users can't create don't give them much value.
Modifications:
- Make the initializer public.
- Remove that godforsaken @testable import.
Result:
ChannelOptions.Storage sparks joy.
Motivation:
https://github.com/apple/swift-nio/issues/966
Modifications:
- Add a `handler(type:)` method on ChannelPipeline
- Add a test in ChannelPipelineTest
Result:
Provides a nicer way to get a typed handler directly from the pipeline
Closes#966
Motivation:
Because of #600, many users will start leaking Channels because they
don't close on error.
Modifications:
* Add ChannelHandlerError
* Add ChannelHandlerErrorTest
Result:
User will have access to an handler to use to automatically close
the channel in case of unhandled errors
* Add ability to open a file for writing
Motivation:
Users can use NonBlockingFileIO for reading files, but if one wants to
write a file, there is no way to achieve that, apart from opening file
manually. I think having to inits to open files for reading and writing
would be convinient.
Modifications:
Allow to open files for writing.
Result:
Users can now open files for writing and reading in the same way.
Motivation:
CircularBuffer.Index was asserting that its size is the same as a word.
Whilst that's true on 64-bit architectures, the assert itself is bogus
and a left-over from development.
Modifications:
Remove bogus assert.
Result:
Better 32-bit support.
* optional max payload size for ByteToMessageDecoder
Motivation:
ByteToMessageDecoder aggregate data in memory as part of their normal operation. the ability to limit how much they aggregate is critical in many real-life applications
Modifications:
* add optional maximumBufferSize argument to ByteToMessageDecoder initializer
* test for buffer size when maximumBufferSize is set and throw ByteToMessageDecoderError.payloadTooLarge error
Result:
users can limit how much memory ByteToMessageDecoder takes and handle the exception on their end
Motivation:
Our original Heap implementation used a bunch of static functions
in order to make it clear how it related to textbook heap
implementations. This was primarily done to ensure that it was easier
to see the correctness of the code.
However, we've long been satisfied with the correctness of the code,
and the Heap is one of the best tested parts of NIO. For this reason,
we should be free to refactor it.
Given https://bugs.swift.org/browse/SR-10346, we've been given an
incentive to do that refactor right now. This is because the Heap
is causing repeated CoW operations each time we enqueue new work
onto the event loop. That's a substantial performance cost: well
worth fixing with a small rewrite.
Modifications:
- Removed all static funcs from Heap
- Rewrote some into instance funcs
- Merged the implementation of insert into append.
- Added an allocation test to avoid regressing this change.
Result:
Faster Heap, happier users, sadder textbook authors.
Motivation:
As Johannes previously said in (#946), there's no reason not be able to
get a ByteBuffer from a ByteBufferView.
Modifications:
I added a public initializer to ByteBuffer taking a ByteBufferView to
create a slice of the view's buffer from the same range.
Result:
`ByteBuffer` will have a public initializer to create a ByteBuffer from
a ByteBufferView.
Motivation:
The documentation popup for viewBytes did not correctly
show what the method returns.
Modifications:
I added a colon after the return doc-block keyword.
Result:
The documentation popup for viewBytes will now correctly show
what the method returns.
Motivation:
B2MD (in debug mode) has some checking that we never move out of a final
state in the state machine. Both .done and .error are final states.
Previously however, the code set .done in a defer block which meant that
even if the decodeLoop throws (which should bring it to .error), it goes
via .done first. That's an error because .done is already a final state
so we shouldn't move to .error after that.
Modifications:
Only move to .done if there was no error. If there was an error, we
should go straight to .error, not via .done.
Result:
- more correct B2MD
- fewer crashes (in debug mode)
* Significantly improve the performance of `EventLoopFuture.{and,when}AllSucceed`.
* PR improvements.
* Add the fast track for `AllComplete` as well.
* Use `future.inEventLoop` instead of pointer comparison.
Motivation:
Spotted a couple of issues with the documentation and fixed them.
Modifications:
- explicitly marked all `public class`es as `public final class` to get
consistency in the Jazzy documentation.
- removed `public` extension methods of the `internal struct
PriorityQueue` which Jazzy showed in the docs.
- improved the largely missing `EmbeddedChannel` and `EmbeddedEventLoop`
documentation.
- clear up lies in the B2MD docs
- add some other missing docs
Result:
better docs makes happier users
Motivation:
For whatever reason, Scheduled stored the cancellationTask in two
places, one of them it never even used :).
Modifications:
only have the promise have a reference to the cancellationTask
Result:
- don't hold onto things longer than necessary
- shrink Scheduled by one word :)
Motivation:
EmbeddedChannel.finish/writeInbound/writeOutbound returned some mystery
bools. I always had to check the code to remember what they actually
meaned.
Whilst this is technically a breaking change, I couldn't find any users
of the return values on Github that are using the convergence releases.
Modifications:
Replace them by enums giving you all the information.
Result:
- fixes#916
- clearer APIs
Motivation:
Jazzy adds everything that has a `public` modifier to the documentation,
even if a type is `internal` or `private`. So conforming and internal
type to some protocol and making all those functions `public` has the
effect of essentially documenting stuff that you can't call (as it's not
actually public).
Modifications:
- remove `public` from functions in extensions on types that aren't
public
- change one `final public` to `public final` because Jazzy doesn't
normalise that
Result:
better docs
Motivation:
In the new CircularBuffer indices we had 24 spare bits, let's do
something useful with them: If it fits we can store the expected
collection size there and compare when an element is accessed through
that index.
Modifications:
add collection count to CircularBuffer.Index
Result:
we can somewhat validate the correct use of CircularBuffer indices
Motivation:
CircularBuffer and its indices should be small. Also the implementation
of methods like remove/popFirst/Last was suboptimal.
Modifications:
- shrink CircularBuffer and its indices
- improve the conformances to the various collection related protocols
- make CircularBuffer self-slicing
- remove Strideable conformance from the indices
Result:
nicer CircularBuffer
Motivation:
Provide a way for CircularBuffer to directly access underlying buffer with an index instead of needing to calculate depending on current head index and underlying buffer count. Related issue: #682
Modifications:
Added needed properties to circular buffers Index and adjust CircularBuffer code accordingly.
Removed MarkedCircularBuffer assumption that an index into it's underlying buffer will not be invalidated.
Result:
CircularBuffer will have a complete Index implementation
Motivation:
B2MH used to crash a nil variable if re-added to a pipeline.
Modifications:
provide good error message for the crash instead
Result:
- fixes#902
Motivation:
For historic reasons, the get* implementations checked the same indices
repeatedly and the checks were also repetitive.
Modifications:
unify and de-deplicate get* range checks
Result:
fixes#884
Motivation:
ByteBuffer's get* methods are now safe, docs claimed they were unsafe
though.
Modifications:
Document the gets as safe
Result:
More correct docs.
Motivation:
MarkedCircularBuffer was assuming that indices remain stable across
mutations, that's wrong.
Modifications:
Don't store the marked index but rather the offset from the start
instead.
Result:
MarkedCircularBuffer uses indices correctly.
this is a fixup and replacement of #650. We need to get this in because NIO converges.
Support for Interface to report if Multicast is supported. Channel can provide Error if Interface doesn't support Multicast.
Motivation:
Allows for checking if the interface you are setting up for Multicast even supports Multicast in the first place. In multiple projects we have done with Multicast it helps as we still run into some network managers that shutdown multicast support.
Modifications:
Interface exposes a new variable to determine if it supports Multicast.
performGroupOperation0 will check if interface is not nil and supports multicast, otherwise will throw error that the interface doesn't support Multicast
Result:
This should hopefully better inform if the Multicast attempt is going to even work.
Motivation:
scheduleRepeatedTask had two overloads: for synchronous and asynchronous
tasks. They however had the same name so they were pretty much
impossible to use.
Modifications:
rename the asynchronous version of scheduleRepeatedTask to
scheduleRepeatedAsyncTask
Result:
- NIO easier to use
- fixes#882
Motivation:
In the Selector (because of the deregistrationsHappened workaround) we
expect all events to be level triggered. If there are deregistrations,
we just expect epoll/kqueue to deliver the event again. But timerfd was
configured as `EPOLLET`. That means is a timer fires after some
deregistrations, we lose it.
Modifications:
make timerfd level triggered
Result:
- no more timer stalls
- fixes#872
Motivation:
ELFs have loads of generic types and that basically screams allocations
and swift_getGenericMetdata everywhere because nothing was inlinable.
Modifications:
make everything inlinable
Result:
better performance working with ELFs
Motivation:
ByteBuffer.viewBytes would unconditionally return a ByteBufferView even
if the requested bytes were not readable.
Modifications:
- make it return an `Optional<ByteBufferView>`
Result:
safer, better APIs
Motivation:
This should make debugging crashes easier, as knowing the contents of the badly-unwrapped `NIOAny` should make it more clear where exactly it could have been written. Personally I'd prefer this to never cause a fatal error, but I assume that would need more discussion.
Motivation:
The old HTTP parser tried to convert `http_parser` to a one-shot parser
by pausing it constantly. That was done to be resilient against
re-entrancy. But now, we have the new `ByteToMessageDecoder` which
protects against that so HTTP decoder can just become a real
`ByteToMessageDecoder`. It also serves as a great testbed for
`ByteToMessageDecoder`.
Modifications:
- make the HTTP decoder a `ByteToMessageDecoder`
- refactor the implementation
Result:
cleaner code, more use of `ByteToMessageDecoder`
Motivation:
Introduced in #767 we would never interrupt a parsing loop unless the
decoder was removed, that's wrong and we need to interrupt also if we
seen `channelInactive` or inbound half closure.
Modifications:
interrupt the parsing loop on EOF.
Result:
more correct B2MD
Motivation:
Previously, ByteBuffers get* methods would get bytes from anywhere, even
if the bytes were not readable. That can lead to security issues in code
that doesn't expect this. NIO shouldn't contain such unsafe methods
without the word 'unsafe'.
Modifications:
Made all `get*` methods respect reader/writerIndex.
Result:
safer user code
Motivation:
tryAsOther previously only returned the value if it was stored as the
.other case in NIOAny but we should do better.
Modifications:
also return the fastpath cases in tryOther (just slower than in the
actual fast path)
Result:
EmbeddedChannel.readIn/Outbound work properly
Motivation:
If you pick the wrong type for readIn/Outbound in tests, it's better to have an error thrown than a crash.
Modification:
- use `tryAs` rather than `forceAs` when trying to extract the buffer element
Result:
better usability in tests.
Motivation:
Some DatagramChannels are extremely high-throughput. This can occur
when UDP is being used as an encapsulation for a transport protocol
(e.g. QUIC), or when a highly utilized service is being offered on a
single port (e.g. DNS).
In these cases, the syscall overhead of datagram reads is quite high
(one recvfrom call per datagram). It would be helpful to be able to
trade off some memory usage in order to reduce the cost of the syscalls
in this situation.
This patch adds support for transparently using the recvmmsg syscall
to achieve this kind of tradeoff.
Modifications:
- Added support to the DatagramChannel for issuing vector reads.
- Added new ChannelOption: DatagramVectorReadMessageCountOption
- Added UDP echo server example to exercise functionality.
- Tests
Result:
Able to achieve higher read throughput on supported systems.
Motivation:
NIOAny is used extensively across SwiftNIO but can't be reasonably debugged. Users may want to simply call String(describing: CustomStringConvertible) to inspect what is the data they are working with at the moment instead of seeing an output that has no debug value.
Modifications:
Conform NIOAny to CustomStringConvertible, along with other types it currently uses that lacked string representation.
Result:
Users can perform simple debugging by printing their NIOAny object.
Motivation:
There is relatively little benefit in allowing the user to send invalid
data types on a given channel. Currently we tolerate this by simply
failing the promise, but this is not really ideal: if the user never sets
a promise here they never even find out that we bailed on sending their
data. Given that we attempt to be type safe everywhere else, we should
just blow up immediately if the user attempts to write an invalid data
type.
Modifications:
Removed the nice gentle type casts, replaced them with explody ones.
Result:
Faster failure in error cases.
Motivation:
MessageToByteEncoder was a protocol that similar to ByteToMessageDecoder
was pretty hard to hold correctly (override some methods but not
others). This PR brings MessageToByteEncoder more in line with the new
ByteToMessageDecoder.
Modifications:
- refactor `MessageToByteEncoder`
- introduce `MessageToByteHandler`, similar to `ByteToMessageHandler`
Result:
- better API, more similar to ByteToMessageDecoder
- fixes#864
Motivation:
Unhandled outbound user events should be failed but previously they were
succeeded.
Modifications:
Succeeding them is odd because nothing happened to them, so they should
be failed.
Result:
fixes#487