999 Commits
Author SHA1 Message Date
Johannes Weiss d55c582e5c improve documentation (#919)
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
2019-03-25 12:09:16 +02:00
Konrad `ktoso` Malawski ef2f86bb24 Fix minor typo in RemovableChannelHandler api docs (#924) 2019-03-25 09:39:03 +02:00
Johannes Weiss 93646f544c remove unused CompositeError (#918)
Motivation:

CompositeError was completely unused, let's kill it.

Modifications:

remove CompositeError

Result:

fewer unused things
2019-03-23 16:41:17 +00:00
Johannes Weiss e0f8275ce3 Scheduled: Don't hold onto cancellationTask (#913)
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 :)
2019-03-23 15:35:24 +00:00
Johannes Weiss a8fbcf080b EmbeddedChannel: remove mystery bools (#917)
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
2019-03-22 12:34:16 +00:00
Johannes Weiss 164f9b12d6 less confusion for Jazzy (#910)
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
2019-03-19 17:36:27 +00:00
Johannes Weiss cc25ee9a00 CircularBuffer: debug-only index validation (#909)
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
2019-03-19 15:23:17 +00:00
Johannes Weiss 4ffa858ce6 make HTTPMethod.hasRequestBody internal (#908)
* make HTTPMethod.hasRequestBody internal

Motivation:

HTTPMethod.hasRequestBody was unnecessarily public.

Modifications:

make it internal

Result:

fixes #151

* Update public-api-changes-NIO1-to-NIO2.md
2019-03-19 13:02:34 +00:00
Johannes Weiss 0f72b759cf conform ByteBufferView to DataProtocol
Motivation:

ByteBufferView should conform to DataProtocol.

Modifications:

Conform ByteBufferView to DataProtocol.

Result:

ByteBufferView conforms to DataProtocol.
2019-03-18 16:57:55 +00:00
Johannes Weiss 35ed9ff754 CircularBuffer: shrink indices to 1 word on 64-bit archs
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
2019-03-15 21:48:52 +00:00
Jovan Milenkovic 5409acdfb6 Add CircularBuffer Index implementation
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
2019-03-15 21:48:52 +00:00
Johannes Weiss 205f317fd9 B2MH: helpful message if re-added to pipeline (#903)
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
2019-03-14 14:05:54 +00:00
Johannes Weiss ccd386b7db remove deprecated methods (#892)
Motivation:

There were some deprecated methods left on EventLoop.

Modifications:

remove them

Result:

- fixes #779
2019-03-13 18:02:26 +00:00
Johannes Weiss 357b931bda ByteBuffer: improve and simplify get* implementations (#896)
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
2019-03-13 17:35:34 +00:00
Johannes Weiss ae3459aebf HTTPDecoder: remove rawURI (#899)
Motivation:

Before native UTF-8, the rawURI was a performance optimisation but
that's no longer true. Before this patch, we still had the rawURIs but
weren't using them at all.

Modifications:

remove any mention of rawURI

Result:

less clutter
2019-03-13 10:24:49 +00:00
Johannes Weiss 87ee03c4ce ByteBuffer docs: gets are safe (#895)
Motivation:

ByteBuffer's get* methods are now safe, docs claimed they were unsafe
though.

Modifications:

Document the gets as safe

Result:

More correct docs.
2019-03-12 10:19:36 +00:00
Johannes Weiss 36a52e1ea3 remove WebSocketFrameDecoder inline error handling (#885)
Motivation:

Follows on from the work done in #528 for #527: we have moved the the
default error handling out of WebSocketFrameDecoder, but had to leave
the code there for backward compatibility reasons. We can remove that
code now.

Modifications:

Removed automatic error handling code in WebSocketFrameDecoder.

Result:

- fixes #534
2019-03-08 19:11:39 +00:00
Johannes Weiss c6065cc367 MarkedCircularBuffer: don't used indices incorrectly (#890)
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.
2019-03-08 18:44:09 +00:00
Johannes Weiss 577604e850 disable NIO1APIShim's warning (#889)
Motivation:

We shouldn't put warnings in developer's code in the convergence phase.

Modifications:

- remove NIO1APIShims warning
- update Swift

Result:

fewer warnings
2019-03-08 18:10:03 +00:00
Johannes Weiss 15c1522cb4 NIONetworkInterface: Return if multicast is supported (#887)
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.
2019-03-08 16:53:55 +00:00
Johannes Weiss acb37911c0 remove overloading from scheduleRepeatedTask (#886)
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
2019-03-08 15:37:58 +00:00
Johannes Weiss e4774cc6e3 update documentation that EventLoopIterator is no longer optional (#888)
Motivation:

docs were old

Modifications:

update the EventLoopIterator examples
Result:

better docs
2019-03-08 15:21:07 +00:00
Johannes Weiss 3fcc5f9f08 Selector: make sure timerfd is level triggered (#880)
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
2019-03-08 12:07:30 +00:00
Johannes Weiss 549ca82521 ELF: make everything inlinable (#846)
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
2019-03-07 11:29:04 +00:00
Johannes Weiss c6479eb1fc ByteBuffer.viewBytes now returns an Optional (#878)
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
2019-03-07 09:12:53 +00:00
Johannes Weiss 22e6cd3c67 HTTP/1 headers simplification & cleanup (#857)
Motivation:

The HTTP/1 headers were quite complicated, CoW-boxed and exposed their
guts (being a ByteBuffer). In Swift 5 this is no longer necessary
because of native UTF-8 Strings.

Modifications:

- make headers simply `[(String, String)]`
- remove `HTTPHeaderIndex`, `HTTPListHeaderIterator`, etc

Result:

- simpler and more performant code
2019-03-06 18:11:40 +00:00
Daniel Alm 8335074108 Make NIOAny log the contents of its storage when encountering fatal unwrapping errors. (#876)
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.
2019-03-06 16:43:13 +00:00
Johannes Weiss f1efb4a104 new http parser (#814)
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`
2019-03-06 11:51:42 +00:00
Johannes Weiss 5fba8b7def B2MD: Stop parsing loop correctly on EOF (#875)
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
2019-03-06 09:48:53 +00:00
Johannes Weiss 796a7d6d7e ByteBuffer get* now respects reader/writer indexes (#869)
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
2019-03-05 13:52:17 +00:00
Johannes Weiss e654e18644 fix NIOAny.tryAsOther (#870)
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
2019-03-05 12:30:29 +00:00
Ian Partridge aa03d7a385 EmbeddedChannel: use tryAs() not forceAs() (#602)
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.
2019-03-05 11:48:25 +00:00
Cory Benfield b13bc66062 Support using recvmmsg to perform gathering reads. (#743)
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.
2019-03-05 11:25:21 +00:00
JovanMilenkovic 0aee5bb91b Drop HTTPHeaders Sequence conformances in favor of RandomAccessCollection (#784)
Motivation:

Use better protocol instead of Sequence since it doesn't do much. Inspired by #676

Modifications:

Conform HTTPHeaders to RandomAccessCollection

Result:

HTTPHeaders will have RandomAccessCollection functionalities.
2019-03-05 09:41:49 +00:00
JovanMilenkovic 56a72a2a89 Conform NIOAny to CustomStringConvertible (#751)
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.
2019-03-05 09:23:25 +00:00
Cory Benfield fe4327d359 Hard-fail on invalid write types in core channels. (#323)
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.
2019-03-05 09:02:14 +00:00
Johannes Weiss eb524c72ad improve and simplify MessageToByteEncoder (#868)
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
2019-03-04 19:19:53 +00:00
Johannes Weiss cde067e603 fail unhandled outbound user events (#867)
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
2019-03-04 15:43:33 +00:00
Johannes Weiss 47a3e7a7a0 conform ByteBufferView to Foundation's ContiguousBytes protocol (#800)
Motivation:

- Foundation has (on master) introduces a ContiguousBytes protocol and we
  should conform to that.
- Sequence has withContiguousStorageIfAvailable and ByteBufferView
  should conform to that too

Modifications:

add conformance

Result:

more compatibility.
2019-03-04 15:07:29 +00:00
Johannes Weiss 7528ecd374 convert NIOWebSocketUpgradeError from enum to struct (#866)
Motivation:

We need to fix #577 sometime soon and in preparation of that we'll
change convert NIOWebSocketUpgradeError from enum to struct.

Modifications:

convert NIOWebSocketUpgradeError from enum to struct

Result:

- NIOWebSocketUpgradeError can be adjusted without SemVer major breaking
  changes
- fixes #839
2019-03-04 14:19:18 +00:00
Johannes Weiss baa3390b15 remove HTTPResponseCompressor (#865)
Motivation:

We're not happy with HTTPResponseCompressor's API and it needs to
incubate a little more, hence moving to
[`swift-nio-extras`](https://github.com/apple/swift-nio-extras).

Modifications:

- removed HTTPResponseDecoder
- removed the zlib dependency

Result:

- no more HTTPResponseDecoder
2019-03-04 13:52:30 +00:00
Johannes Weiss a1981eb0fd prepare tests for throwing readIn/Outbound (#861)
Motivation:

readInbound/Outbound will soon throw errors if the type isn't right.

Modifications:

prepare tests for throwing readIn/Outbound

Result:

@ianpartridge's PR should pretty much merge after this.
2019-03-04 09:40:59 +00:00
Tanner 49659664c2 fix camel case for 418 status (#860)
The status phrase is "I'm a teapot". Removing the apostrophe and camel casing should result in the string `imATeapot`, not `imaTeapot`.
2019-03-02 11:25:05 +00:00
Shaun Hubbard 347886f55f add 418 error code, and moved unprocessable entity(422) from 500 to 400 section (#327) 2019-03-01 18:53:56 +00:00
Cory Benfield 9c07f89ec7 Allow delaying HTTP upgrade decisions. (#844)
Motivation:

While the HTTPServerUpgrader and WebSocketUpgrader allowed users to take
their time when reconfiguring the pipeline after they decided to upgrade,
users had to synchronously decide if they wanted to upgrade. This is a bit
inconvenient.

A particular limitation here is that some routes may want to upgrade
only if the upgrading user is authenticated. Checking authentication
credentials is almost always an I/O operation, and so cannot safely be done
on the event loop. Our original design made this impossible.

Modifications:

- Changed the shouldUpgrade callback to return a Future.
- Passed the shouldUpgrade callback the Channel that is upgrading, in
    no small part so that it has an EventLoop it can create Futures
    on.
- Rewrote the upgrader to handle this new state.

Result:

Users can delay decisions about when to upgrade.
2019-03-01 18:24:59 +00:00
Tanner 56669eabd2 improve ChannelPipeline debug print (#851)
Motivation:

ChannelPipeline layout helps understanding NIO and debugging

Modifications:

improved the ChannelPipeline `debugDescription`

Result:

NIO better
2019-02-28 18:01:55 +00:00
Johannes Weiss b1f62f71a6 EmbeddedChannel: expose EmbeddedEventLoop (#855)
Motivation:

There's just too much test code that has

(channel.eventLoop as! EmbeddedEventLoop).run()

Modifications:

have EmbeddedChannel expose its EmbeddedEventLoop

Result:

easier test code
2019-02-28 16:30:36 +00:00
Johannes Weiss da52b59ced fix/improve some NIO1APIShims (#856)
Motivation:

We had wrong/suboptimal API shims.

Modifications:

improve them

Result:

easier porting from NIO1 to NIO2
2019-02-28 16:16:17 +00:00
Johannes Weiss 66b00ec637 B2MD: fast-path to reduce allocations (#854)
Motivation:

B2MD has an important fast path:
- everything was consumed
- no buffers collected during re-entrancy

In this case we should short-circuit and move on as quickly as possible.

Modifications:

If everything was consumed in `decode` and no buffers were collected in
re-entrancy, returning a buffer isn't actually useful, we should just
drop it and not risk taking an allocation for a useless `clear`.

Result:

faster & fewer allocs
2019-02-28 15:04:43 +00:00
Johannes Weiss d3862c0ecc B2MD: actually call decoderRemoved (#853)
Motivation:

decoderRemoved was never actually called...

Modifications:

call decoderRemoved on removal

Result:

more correct B2MD
2019-02-28 13:21:32 +00:00