Commit Graph
1096 Commits
Author SHA1 Message Date
Cory Benfield c3e2359c55 Minor cleanups of Windows compatability code. (#1663)
Motivation:

Cleanup some noise that came in with some previous Windows compat
patches.

Modifications:

- Move INVALID_SOCKET to NIOBSDSocket, and refer to it by a better name
  there.
- Comment in an empty block to indicate that it's supposed to be empty.

Result:

Bit cleaner code.
2020-09-30 19:55:21 +01:00
Graeme Jenkinson b5c1696033 Provide a convenience API for dispatching blocking work (#1563) (#1662)
Motivation:

SwiftNIO lacks a convenience API for performing blocking IO / tasks. As
this is a fairly common task it then requires the clients to make ad hoc
implementations that address this requirement.

Modifications:

Extension to DispatchQueue with the following method to schedule a work
item to the `DispatchQueue` and return and `EventLoopFuture` for the
result returned:

- `asyncWithFuture<NewValue>(eventLoop: EventLoop, _ callbackMayBlock: @escaping () throws -> NewValue) -> EventLoopFuture<NewValue>`

Added new unit tests for this function both when the promise succeeds
and fails.

Extention to EventLoopFuture with the following public functions:

- `flatMapBlocking<NewValue)(onto queue DispatchQueue, _ callbackMayBlock: @escpaing (Value) throws -> NewValue) -> EventLoopFuture<NewValue>`
- `whenSuccessBlocking(onto queue DispatchQueue, _ callbackMayBlock: @escaping (Value) -> Void) -> EventLoopFuture<NewValue>`
- `whenFailureBlocking()onto queue DispatchQueue, _ callbackMayBlock: @escaping (Error) -> Void) -> EventLoopFuture<NewValue>`
- `whenCompleteBlocking(onto queue DispatchQueue, _ callbackMayBlock: @escaping (Result<Value, Error>) -> Void) -> EventLoopFuture<NewValue>`

These functions may all be called safely with callbacks that perform blocking IO / Tasks.

Added new unit tests to EventLoopFutureTest.swift for each new function.

Result:

New public API for `EventLoopFuture` that allows scheduling of blocking IO / Tasks.
2020-09-30 17:04:21 +01:00
Graeme Jenkinson 7c42e5a45d A helper for easily unwrapping Optional values in an EventLoopFuture (#1656)
Motivation:

Unwrapping an `Optional` value from an `EventLoopFuture` is a fairly
common requirement that currently involves the client writing
boilerplate code, for example:

```
extension EventLoopFuture {
    func unwrapOptional<T>(orError error: Swift.Error) -> EventLoopFuture<T> where Value == T? {
        self.flatMapThrowing { value in
            guard let value = value else {
                throw error
            }
            return value
        }
    }
}
```

As this is a fairly common requirement adding an extension of
`EventLoopFuture` to unwrap `Optional` values would remove this
burden from clients.

Modifications:

Added Extension to `EventLoopFuture` containing the following functions:

- `unwrap<NewValue>(orError: Error)`: Unwraps a future returning a new
  `EventLoopFuture` with the same value as the resolved future when
  its value is Optional.some(...)`, otherwise the `Error` passed in
  the `orError` parameter is thrown

- func unwrap<NewValue>(orReplace: NewValue)`: Unwraps a future returning a new
  `EventLoopFuture` with either: the value passed in the `orReplace`
  parameter when the future resolved with value `Optional.none`, or
  the same value otherwise.

- func unwrap<NewValue>(orElse: @escaping ()- > NewValue): Unwraps a future
  returning a new `EventLoopFuture` with either: the value returned
  by the closure passed in the `orElse` parameter when the future
  resolved with value `Optional.none`, or the same value otherwise.

Added new unit tests for each new `unwrap(orXXX:)` function.

Result:

Client's no longer have to write their own boilerplate code.
2020-09-30 13:47:14 +01:00
Saleem AbdulrasoolandCory Benfield 934de6a284 NIO: implement address resolution for Windows (#1661)
This implements address resolution on Windows using the WinSock API.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-30 13:25:39 +01:00
Saleem AbdulrasoolandCory Benfield 8454066e8d NIO: shave off parts of System (#1658)
This shaves off parts of System to reduce the noise when building to get
the Windows build more manageable.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-30 11:35:07 +01:00
Saleem AbdulrasoolandCory Benfield 7686fbf4b0 NIO: improvements to Windows BSD API (#1659)
Some improvements to the API surface to actually handle some more error
cases correctly and fix typing.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-30 10:50:10 +01:00
Saleem AbdulrasoolandCory Benfield 0ae9524ca8 NIO: invalid sockets are not -1 but INVALID_SOCKET (#1660)
Adjust the sentinel indicating an invalid socket.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-30 10:32:52 +01:00
Saleem AbdulrasoolandCory Benfield bc328cd3a8 NIO: ignore SIGPIPE on Windows (#1653)
Windows does not support Unix-style signals.  Simply exclude the SIGPIPE
path on Windows.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-30 10:13:10 +01:00
Saleem Abdulrasool 2d913d65af NIO: make BSDSocketAPI build on Windows (#1657)
These interfaces use types from WinSDK to re-export them in the NIO
namespace.  Import the types required.  This allows us to build this
file on Windows again.
2020-09-25 18:30:17 +01:00
f9a7eaf6e0 Disambiguate the capacity of the ByteBuffer (no. of addressable bytes) and capacity of underlying storage (#1485). (#1629)
Motivation:

The exisiting ByteBuffer`s `capacity` property exposes the number of
addressable bytes in the buffer (that is, the difference between its
upper and lower bound). This value can be significantly different than
the number of bytes allocated to the buffer's underlying storage.
For example, when constructing of COW slice from the original buffer the
underlying storage maybe tens of thousands of bytes while the slice's
capacity is 1.

To avoid any ambiguitity, a new property - `storageCapacity` - will be
added.

Modifications:

Added new `storageCapacity` property to expose the capacity of the buffer (or
derived COW slice) underlying storage (that is allocated to the buffer).
This property is part of public interface ans is typed as an Int.

Updated unit tests to verify `storedCapacity` remains constant when
slicing the ByteBuffer and also to account for the addition of the new
property in the CustomStringConvertible desciption.

Result:

The `storageCapacity` of a buffer and a COW slice taken from that buffer
with remain the same data is written to the slice.

Co-authored-by: Graeme Jenkinson <gcjenkinson@Graemes-MacBook-Pro.local>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-25 11:10:20 +01:00
Saleem Abdulrasool 715efd0c0d NIO: add import for the C library for Windows (#1652)
`ByteBuffer` uses `size_t` which requires the C library.
2020-09-25 09:12:26 +01:00
976ccdd0d0 Scheduling tasks Int.max ns into future results in an obtuse fatal error (#1056) (#1642)
Motivation:

When scheduling a task too far into the future on a Darwin-kernel,
a fatal error is produced. Whilst the error indicates that a parameter
to the kevent syscall was invalid (EINVAL) it gives no further
information as to the root cause.

As the user's intent is to schedule an task far into the future, a fatal
error should not result. Instead the time should be clamped to the
maximum value that the Darwin-kernel supports. This ensures that
, provided the system remains running, the task will eventually run
(though this may be several yeasr into the future).

Modifications:

Duplicated the bounds checks from those in Darwin-kernel interval timer,
clamping timespec values to the maximum value. Added an assert to check
that the timespec tv_nsec field is valid (according to definition of
the timespec datatype in ISO C11). And a precondition on the tv_sec
field being > 0 (tasks schedule with times <= 0 should not result in
a kevent being registered as they are scheduled immediately).

Added note clarifying behaviour under Darwin-based OSes to the EventLoop
scheduleTask() method.

Added new unit test scheduling a task at the maximum value (which
under any regression would crash).

Result:

Scheduled tasks where the timeout exceed the maximum value supported by
Darwin-based OSes will be clamped to the maximum.

Co-authored-by: Graeme Jenkinson <graemee_jenkinson@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-24 15:05:54 +01:00
Andrius 801b879b35 fixes docstring with correct return type (#1644) 2020-09-22 17:37:18 +01:00
AndriusandCory Benfield b2f3de8ed5 Cleanup unix socket pathname on server socket close or bind (#1637)
* Cleanup unix socket pathname on server socket close or bind

* cleaner use of swift syntax

* using stat and unlink via syscal wrappers

* separate error type when UDS path is not a socket file

* track if socket needs cleanup to avoid extra syscall

* struct instead of enum for a single new error type

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-22 15:30:49 +01:00
Andrius bc72ee7537 Increases default initial size for AdaptiveRecvByteBufferAllocator (#1641)
Motivation:

Resolves https://github.com/apple/swift-nio/issues/1558
A common MTU on the internet is 1500 bytes, and it should fit in the initial size buffer

Modifications:

Only the default initial size is increased

Result:

Little is changed, but should result in fewer reallocations e.g. during TLS conneciton handshake
2020-09-22 11:43:10 +01:00
Saleem Abdulrasool b72ed545aa NIO: import additional values from WinSDK (#1640)
These values are referenced but not imported which results in undefined
references.
2020-09-22 10:45:06 +01:00
Saleem AbdulrasoolandCory Benfield 15a2e49402 NIO: fix close(socket:) (#1633)
`Posix.*` cannot be used on Windows.  Sockets and (file) descriptors are
in entirely different namespaces, and will result in an invalid
operation.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-21 10:45:00 +01:00
f7dc232e0c NIO: remove poll from the _BSDSocketProtocol protocol (#1635)
This removes the testing-only API of `poll` on Windows which does not
have a semantic compatible poll.

Co-authored-by: David Evans <d.evans@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-09-21 10:31:13 +01:00
Saleem AbdulrasoolandDavid Evans 0c2789c56a NIO: remove unnecessary @discardableResult (#1634)
The function returns `Void`, the attribute does not apply.

Co-authored-by: David Evans <d.evans@apple.com>
2020-09-21 10:01:38 +01:00
Saleem Abdulrasool 36b19f98c3 NIO: repair the build after e3508b0d0 (#1636)
`ssize_t` is not a standard type and does not have a portable Swift
spelling.  Use `size_t` which is compatible in size, but is signed
instead.  This is needed in order to be compatible to more standard
conforming environments like Windows.
2020-09-21 09:36:18 +01:00
Max Desiatov 96db8838be Note that certain NIOFileHandle.init overloads are blocking (#1630)
This was noted in review  of swift-server/async-http-client#275, but I don't think that this was clearly stated in the documentation.
2020-09-07 10:48:15 +01:00
George Barnett 98721c75b0 Remove incorrect assertion in MarkedCircularBuffer.popFirst (#1627)
Motivation:

`MarkedCircularBuffer.popFirst()` asserts that the backing buffer should
contain more than zero elements yet `popFirst()` allows `nil` to be
returned when there is no value to return.

Modifications:

- Move the assertion from `popFirst() -> Element?` to `removeFirst() -> Element`
- Test for `popFirst()`

Result:

- We can safely call `popFirst()` on an empty `MarkedCircularBuffer` in
  debug mode.
2020-09-03 14:06:14 +01:00
Andrew Naylor 08c7821ba3 Correct typo in _ChannelOutboundHandler docs (#1628)
Motivation:

The doc block for `_ChannelOutboundHandler.read(context:)` mentions suppressing
a *flush*, it appears this is a copy-paste error from the docs for `flush(context:)`
above and should in fact refer to suppressing the *read*.

Modifications:

Substituted `read` for `flush` in the doc block for `_ChannelOutboundHandler.read(context:)`
2020-09-03 13:46:28 +01:00
Cory Benfield a4a3a4b1b0 Add @inlinable to all BBV methods. (#1625)
Motivation:

While looking at a different part of the code in swift-nio-http2 I
noticed that we can't inline many straightforward ByteBufferView
operations, including bytewise-access. That's pretty sad, so I thought
we should fix it.

Modifications:

- Slap @inlinable on all the BBV entry points.

Result:

Better code generation, particularly around repeated subscript accesses.
2020-08-28 15:33:56 +01:00
George Barnett 5fc24345f9 Better handle writability changes in triggerWriteOperations (#1624)
Motivation:

If a write is buffered in the `PendingWritesManager` and the high
watermark is breached then a writability change will be fired as a
result. The corresponding event when the channel becomes writable again
comes when enough pending bytes have been written to the socket (i.e. as
a result of a `flush()`) and we fall below the low watermark.

However, if a promise associated with a write has a callback
registered on its future which writes enough data to breach the high
watermark (and also flushes) then we will re-entrantly enter
`flushNow()`. This is okay, `flushNow()` protects against re-entrancy
and any re-entrantly enqueud flushed writes will be picked up in the
write-spin-loop.

The issue here is that the `writeSpinLoop` does not monitor for changes
in writability. Instead if checks the writability before it begins and
after it completes, only signalling if there was a change. This is
problematic: the re-entrant write-and-flush could have caused the
channel to become unwritable yet no event will be fired to make it
writable again!

Modifications:

- Store a local writability state in the pending writes manager and
  modify it when we emit writability changes

Result:

- Better protection against re-entrant writability changes.
2020-08-26 12:26:05 +01:00
Cory Benfield f9552beffa Replace NIONetworkInterface with NIONetworkDevice. (#1622)
Motivation:

NIONetworkInterface was a useful type, but its implementation was fairly
fatally flawed in a number of ways. While we could have lived with the
awkward type construction (it's a class, which isn't the semantic we
want), the ultimate flaw is that you cannot create a NIONetworkInterface
for an interface that does not have an IP address.

That's not helpful, given that it's not uncommon for an interface to not
have an IP address!

Modifications:

- Deprecate NIONetworkInterface
- Add NIONetworkDevice
- Provide new methods on MulticastChannel that use NIONetworkDevice
  instead of NIONetworkInterface.
- Provide default implementations of new MulticastChannel protocol
  requirements.
- Implement new MulticastChannel protocol requirements.
- Update the tests.

Result:

Devices will be able to reflect network devices without IP addresses.
2020-08-24 09:37:27 +01:00
Saleem Abdulrasool cf6f2b1807 Linux: make Epoll available on Android (#1621)
Android is sufficiently Linux-esque that it should be able to use `Epoll`.
2020-08-18 08:05:31 +01:00
Timothée PeignierandCory Benfield 0570d9a1cb Recover from EINVAL even if the error is untyped (#1598)
* Recover from EINVAL even if the error is untyped

* Handle fcntl EINVAL error

* Fix EINVAL test

* Rename and deprecate errors

Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-08-12 15:05:42 +01:00
Cory Benfield 831cf89d54 Reduce refcounting in Heap by removing configurability (#1614)
Motivation:

Right now Heap.heapify incurs quite a lot of ARC traffic when it is used
in SelectableEventLoop. Specifically, each of the invocations of
self.comparator in heapify incurs three refcount operations. These three
are all the result of the fact that the comparator is an arbitrary
function, but all three are guaranteed to be unnecessary.

The first refcount is for the closure context for self.comparator. Of
course, self.comparator has only two possible values, neither of which
needs a closure context, but the compiler doesn't know that and the type
system doesn't encode it.

The other two refcounts are for the ScheduledTask objects themselves.
Again, the compiler doesn't know what the comparator function will do,
so it must defensively ensure that a retain/release is inserted for the
arguments of that function.

If we happen to hit both branches of the code, we'll execute 6 retains
and 6 releases, and even in fairly average cases we'll execute 3 of
each.

All of this is unnecessary: the only runtime function ever used here is
a trivial comparison operation. We know what it is at compile time, we
just have to ask. While it was admirable to have the configurability of
the priority queue in place, after 3 years I think we have a pretty good
feeling that we're not going to need the ability to have a max-heap
instead of a min-heap.

We can always get this back if we need it.

Modifications:

- Removed the configurability of Heap.
- Removed HeapType.
- Removed arguments from PriorityQueue
- Removed all tests testing now-removed max-heap functionality.

Result:

Less ARC traffic in the core task scheduling loop.
2020-08-10 13:12:43 +01:00
David Evans 08706eb13e Deprecate and replace ByteBuffer.clear(minimumCapacity: _Capacity) (#1610)
* Add new method

* Fix precondition message

* George PR comments
2020-08-04 12:04:06 +01:00
pokryfkaandKonrad `ktoso` Malawski 3141b02d2f Define public EventLoopGroupProvider type (#1609)
Closes #1608

Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
2020-08-03 13:25:26 +01:00
Peter Adams e0254bd274 Add doc comment about potential of events to arrive out of order. (#1606)
Motivation:

This has come as a surprise to at least one person and is easy to forget.

Modifications:

Doc commented added at the top of ChannelPipeline.

Result:

Docs are clearer.
2020-08-03 09:17:55 +01:00
Cory Benfield acf5465b5e Avoid including non-modular headers. (#1605)
Motivation:

We included netinet/ip.h in CNIODarwin, which unfortunately is not
modularised. This causes issues when using SwiftPM to create xcodeproj
files. There's no real reason to do it this way, when we can just as
easily abstract the issue.

Modifications:

- Moved netinet/ip.h to the .c file instead of the .h.
- Defined some exported namespaced integers to correspond to the macros.
- Performed platform abstraction in Posix instead of everywhere.

Result:

- Creating xcodeproj files should be fine.
2020-07-31 09:57:25 +01:00
Peter Adams 496d697df7 Don't use deadbeef for dead pointers. (#1604)
Motivation:

It turns out using this overflows Int on "Any iOS Device"

Modifications:

Switch the first d to a 7.

Result:

Code will compile on "Any iOS Device".
2020-07-30 18:27:26 +01:00
Peter Adams 86ce6aae8b Explicit Congestion Notification for UDP (#1596)
Motivation:

Network congestion can be controlled without packet loss if explicit congestion notification messages are understood.

Modifications:

Receive single and vector paths to get notification and surface.
Send paths for both single and vector sends.
Round trip tests.
Storage for control messages added in a reusable way.

I have tested allocations and they seem to be fine but the allocation tests for vector read and write were not stable enough to sensibly add to CI.

Result:

Explicit Congestion Notifications can be both sent and received.
2020-07-17 16:25:09 +01:00
Peter Adams 1e2d2b997b Plumb metadata through PendingDatagramWritesManager. (#1593)
Motivation:

ECN information is held in metadata.
As part of the path to writing ECN to the network the
required state needs to pass through PendingDatagramWritesManager.

Modifications:

Add an extra metadata field to PendingDatagramWrite and ensure
this data is passed to the correct write method.

Result:

Nothing visible - just preparation for actual ECN send.
2020-07-14 17:42:23 +01:00
Peter Adams 723ff6acf1 Allow Metadata to be constructed and set on AddressedEnvelope (#1591)
Motivation:

This needs to be possible so users can specify what
ECN status they wish to send.  The auto-generated
initialiser is internal.

Modifications:

Add public initialiser to AddressedEnvelope.Metadata
Add public initialiser to AddressedEnvelope taking Metadata

Result:

Users will be able to construct AddressedEnvelopes with Metadata set.
2020-07-14 15:51:07 +01:00
Peter Adams f12803dbf1 Add methods to create and parse cmsghdr structured data. (#1590)
Motivation:

cmsghdrs can be used to send an receive extra data on UDP packets.
For example ECN data.

Modifications:

Map in Linux and Darwin versions of cmsghdr macros as functions.
Create strctures for holding a received collection; parsing ecn
data from a received collection and building a collection suitable
for sending.

Result:

Functions to manipulate cmsghdr and data exist.
2020-07-14 12:29:31 +01:00
Peter Adams ee8acd9b3d Use sendmsg rather than sendto to send UDP data. (#1587)
Motivation:

sendmsg is more powerful - this is paving the way for
Explicit Congestion Notifications to be sent.

Modifications:

Replace the sendto system call with sendmsg up to DatagramChannel.

Result:

Sendmsg will be used to send UDP data.
2020-07-10 13:41:13 +01:00
Cory Benfield 97450139d5 Improve pointer hygeine in SocketAddresses.swift (#1588)
Motivation:

The socket address types are some of the worst types for handling in
Swift. They pervasively type-pun in a way that Swift strongly wants to
resist, and they expose a bunch of data through awkward fixed-length
arrays.

We've done a number of passes over this code to improve its pointer
hygeine. This is another one. Here, we remove some uses of the memory
binding APIs that were unnecessary, and that can instead take advantage
of the way Swift handles binding memory of homogeneous tuple types.

In Swift, whenever we have a homogeneous tuple (i.e. a tuple whose
elements are all the same type), that memory is actually bound to _two_
types: to the tuple type, and to the type of the elements. This allows
us to use `assumingMemoryBound(to:)` to convert between the pointer to
the tuple and the pointer to the first element of the tuple.

This knowledge lets us remove calls to `bindMemory` and
`withMemoryRebound`. Neither call is correct to use in this situation,
and while we were unlikely to encounter any damage, this is the best
possible use of the Swift pointer APIs for this work.

Modifications:

- Rewrite accesses to the UNIX domain socket path to use appropriately
  typed pointers without binding or rebinding memory.
- Added some assertions about the static types of the stored elements.

Result:

Better management of pointer type bindings.
2020-07-10 08:14:29 +01:00
Cory Benfield e3508b0d04 Move DatagramChannel over to using recvmsg. (#1473)
Motivation:

When attempting to obtain metadata about a read, we need to use recvmsg
in order to obtain that data. While we're using recvmmsg for vector
reads right now, our scalar reads use recvfrom, which does not provide
us with that metadata.

While we're not extracting metadata right now, we may well do so in
future, so we can apply it now.

Modifications:

- Move recvfrom usage to recvmsg.

Result:

We'll be able to extend recvmsg to extract metadata.
2020-07-08 09:10:32 +01:00
Saleem Abdulrasool 5de1e41310 NIO: Implement BSD sockets APIs for Windows (#1471)
Motivation:

Split out the internal implied BSD socket API code to allow alternative implementations of these interfaces on other platforms.

Modifications:

- Split the code apart.
- Provide POSIX and Windows implementations of the BSD socket API.

Result:

Should be easier to run NIO unmodified on Windows.
2020-07-03 10:14:36 +01:00
Luo Xiu 8aae654645 fix incorrect case when removing an element from a circular buffer (#1584) 2020-07-01 10:13:44 +01:00
Gregor Milos (Grzegorz Miłoś) 3c5ea83a9a Fix RepeatedTask scheduling logic to run on the correct EL (#1567)
Motivation:

Fixes: #1334

Modifications:

ELF hops on the correct EL before executing.

Result:

Fixes precondition failure, caused by being on the wrong ELG.
2020-06-26 09:19:06 +01:00
David Evans 6bba46fb90 Fix non-public init (#1573) 2020-06-25 13:07:18 +01:00
Cory Benfield 30961d2f05 Properly allow ThreadPool to be started multiple times. (#1572)
Motivation:

Our API documentation claims that NIOThreadPool.start() will tolerate
being called multiple times. However, this wasn't actually true: in
debug mode it'd hit an assertion, and in release mode it would quietly
orphan all its threads and replace them with new ones, leaving there
with twice as many threads and some that wouldn't be closed down.

We should support the functionality we claim we do.

Modifications:

- Fixed the incorrect check for running thread pool state.
- Added a test to validate we actually allow multiple starts.

Result:

Thread pools really can be started multiple times.
2020-06-25 11:14:43 +01:00
George Barnett 8a25c0f5a0 Make TimeAmount Hashable (#1571)
Motivation:

TimeAmount wasn't `Hashable` and there's no clear reason it shouldn't
be.

Modifications:

Add synthesized `Hashable` conformance to `TimeAmount`

Result:

`TimeAmount` is hashable.
2020-06-24 12:31:05 +01:00
George Barnett 7d2e632da2 Execute tasks scheduled at the same time in order on EmbeddedEventLoop (#1540)
Motivation:

`EmbeddedEventLoop` executes scheduled tasks in their run-time order.
If multiple tasks are scheduled for the same time then the order in
which they are eventually executed is undefined.

Since `execute` defers to scheduling a task for "now" it is possible for
tasks to be executed out of order if `run()` is not called between each
execute.

In "real" event loops this isn't an issue because the system time must
advance between each call to `execute`.

Modifications:

- Add a 'insertionOrder' to `EmbeddedScheduledTask`; use it to break
  ties when comparing two tasks with the same run time
- Add a task counter to `EmbeddedEventLoop` which is used to provide an
  insertion order when scheduling tasks.

Result:

- EmbeddedEventLoop will `execute` tasks in order
2020-06-17 10:56:32 +01:00
George Barnett 5739d4e6f1 Allow EmbeddedEventLoop to advanceTime(to:) a deadline (#1557)
Motivation:

You can schedule tasks for a deadline on `EmbeddedEventLoop` but have no
way of knowing the current time on the `EventLoop` and how much to
advance the time by in order to meet that deadline. In most cases this
is okay because you know that time starts at zero and you can keep track
of time, however, it's generally useful to not have to keep track of
this yourself.

Modifications:

- Add `advanceTime(to:)` on `EmbeddedEventLoop`
- Document that time may be controlled on `EmbeddedEventLoop` and how to
  advance it
- Tests

Result:

- `EmbeddedEventLoop` is more usable with deadlines
- Better documentation
2020-06-16 18:00:02 +01:00
Peter Adams 9f732b2382 Shorthand way of setting options in universal bootstrap (#1547)
Motivation:

Guide novice users towards the options they are most likely to want to use.

Modifications:

New type to represent shorthand TCP client options containing only the options
which are sensible for novice users.
New type to represent a collection of these options.
A method to allow underlying bootstraps to override universal behaviour - default
implementation is to do nothing.

A test case to demonstrate that shorthand options match old style options.
A test case to demonstrate that overriding option behaviour is possible.

Result:

For universal botostrap there will be an new way of setting options involving
less typing which guides the user towards the common options.
2020-06-15 17:24:20 +01:00