Commit Graph

1131 Commits

Author SHA1 Message Date
Tim 010a6e6e96 Update my name in Contributors list (#798)
Update my name in Contributors list

Motivation:

Name/email was wrong, should fix it. Also added an entry for Tom since he was appearing twice

Modifications:

Updated mail map, ran script to generate contributors list

Result:

New contributors list with correct name/email for me and new contributors added
2019-02-01 16:18:08 +00:00
George Barnett 6050c9c864 Fix documenation markup (#799)
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.
2019-02-01 15:34:59 +00:00
Johannes Weiss 89a4eaa807
fix #657 (#795)
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
2019-01-31 16:41:55 +00:00
Moritz Lang 5c2de043b3 Make use of dropFirst(_:) in example code (#794)
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.
2019-01-31 14:54:20 +00:00
Tanner 0154604408 rename HTTPProtocolUpgrader to HTTPServerProtocolUpgrader (#750)
* rename HTTPProtocolUpgrader to HTTPServerProtocolUpgrader
2019-01-31 11:36:55 +00:00
JovanMilenkovic cf56bfd119 Remove EmbeddedChannel restriction to IOData (#763)
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
2019-01-30 19:24:59 +00:00
Johannes Weiss 70c714a54d
address Norman's B2MD feedback (#792)
Motivation:

Norman gave feedback on the new B2MD but after it was already merged.

Modifications:

address feedback

Result:

better code
2019-01-29 16:27:00 +00:00
Johannes Weiss d3e611f3de
allow 2017-2019 copyright headers (#790)
Motivation:

Previously we required all copyright headers to be 2017-2018 but now
that's not the only allowed string anymore.

Modifications:

allow 2017-2019 besides 2017-2018

Result:

Happy New Year
2019-01-29 15:17:01 +00:00
Johannes Weiss 15e69f5fb6 README: update requirements (#791)
Motivation:

We still recommend to patch Xcode 10.1 instead of using Xcode 10.2 beta.

Modifications:

Recommend Xcode 10.2 beta + custom toolchain

Result:

Happier NIO devs
2019-01-29 13:50:47 +00:00
Gwynne Raskind 8222af4aad Add cancel notification to RepeatedTask (#783)
* 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.
2019-01-29 13:19:12 +00:00
Johannes Weiss 2ad1e21512 CircularBuffer.init: rename initialRingCapacity to initialCapacity
Motivation:

initialRingCapacity is not a great name, initialCapacity is much better

Modifications:

rename CircularBuffer(initialRingCapacity:) to initialCapacity

Result:

more consistent code
2019-01-29 12:29:04 +00:00
Jovan Milenkovic a5838ae22b Replace ByteBufferTest use of deprecated "withUnsafeBytes" with new API
Motivation:

Remove the only warning in the project.

Modifications:

Use new withUnsafeBytes API.

Result:

The project will have no warnings.

(cherry picked from commit b41e50403b)
2019-01-29 11:52:20 +00:00
Johannes Weiss c45c7e181c use DEVELOPMENT-SNAPSHOT-2019-01-28-a
Motivation:

New Swift versions are great.

Modifications:

Upgrade to 5.0-DEVELOPMENT-SNAPSHOT-2019-01-28-a.

Result:

Should unblock #769.
2019-01-29 11:52:20 +00:00
Johannes Weiss 9480c27148 malloc-aggregation.d: don't forget posix_memalign (#785)
Motivation:

When counting the number of allocations it's important not to forget an
allocation function that Swift uses.

Modifications:

add posix_memalign to dev/malloc-aggregation.d

Result:

malloc aggregations accurate with recent Swift versions
2019-01-29 11:23:42 +00:00
Johannes Weiss 58a58b9680
CI: use DEVELOPMENT-SNAPSHOT-2019-01-23-a (#780)
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
2019-01-25 23:50:01 +00:00
David Skrundz 0eb85a4478 Add deadlines as an alternative to timeouts (#770)
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.
2019-01-25 19:32:55 +00:00
Johannes Weiss de8d3e260e alloc tests: hook posix_memalign & reallocf (#782)
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
2019-01-25 16:11:23 +00:00
Nathan Harris 30f1a544d0 Add `whenAllComplete` EventLoopFuture method (#773)
* Add `whenAllComplete` method to group a homogenous array of future results into a single ELF
2019-01-25 10:03:11 +00:00
Johannes Weiss 3563b9d795
provide ELF.flatMapResult (#778)
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`.
2019-01-24 20:11:00 +00:00
Johannes Weiss f3294dd803 rename ELF.mapIfError to ELF.recover (#777)
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
2019-01-24 17:09:13 +00:00
Johannes Weiss c4ff795dda
remove ELP.succeed/fail's labels (#776)
Motivation:

EventLoopPromise.succeed/fail has extraneous labels that don't add
anything but noise.

Modifications:

remove extraneous labels

Result:

less noise in the code
2019-01-24 16:42:53 +00:00
0xflotus a87859085e fixed small typo (#775) 2019-01-24 09:22:04 +00:00
Johannes Weiss c741ec1f9b NIO1 API Shims: Forgotten deprecation warning (#771)
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
2019-01-22 15:53:46 +00:00
Jari (LotU) 313ddabb48 Allow setting of RemoveAfterUpgradeStrategy (#766)
Allow to set RemoveAfterUpgradeStrategy on HTTPResoonseSecoder
2019-01-21 22:12:24 +00:00
Johannes Weiss f4b185675f
speed up getBytes (#761)
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!
2019-01-21 21:26:56 +00:00
Johannes Weiss 5619395fa0
provide NIO1 API shim for ELF.then* (#768)
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.
2019-01-21 20:19:12 +00:00
Johannes Weiss 3e7d6a7bfd rename ELF.then to ELF.flatMap (#760)
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
2019-01-21 16:41:04 +00:00
Johannes Weiss 9033aa6eff provide _NIO1APIShims (#758)
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
2019-01-21 15:51:12 +00:00
Johannes Weiss 72370b6b42 defined NIO_CI_BUILD in the CI builds (#765)
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
2019-01-21 15:24:51 +00:00
Johannes Weiss a5b6ca06ab actually enable warnings as errors (#759)
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
2019-01-19 20:32:13 +00:00
Cory Benfield ea888e6405
Fix broken test for byte delivery. (#745)
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.
2019-01-19 20:17:38 +00:00
Johannes Weiss f32f283dd4
declare public API (#673)
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.
2019-01-19 14:17:38 +00:00
Cory Benfield 7a98195524 Actually remove promise logging info. (#752)
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.
2019-01-19 14:15:41 +00:00
David Skrundz f7357e66ab make ELF.cascade accept an optional promise (#757)
* 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
2019-01-19 13:59:12 +00:00
JovanMilenkovic f50230aeba Fix NIOHTTP1Server handleJustWrite always using response status "ok" (#755)
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"
2019-01-18 08:57:27 +00:00
Kevin Sweeney 8f3ac9ac1a Docs: move defer shutdown next to EventLoop creation (#754)
See #753 for rationale.
2019-01-17 17:24:06 +00:00
Kevin Sweeney 794b7b7f02 Docs: move defer closer to the group instantiation (#753)
This makes the boot/shutdown pair visually closer, reinforcing that you shouldn't forget to shutdown the EventLoopGroup.
2019-01-17 11:28:30 +00:00
Johannes Weiss 9c93d6e7ec use SwiftPM's linker settings to link zlib (#705)
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
2019-01-07 20:25:37 +00:00
Johannes Weiss f38984d80e
remove bogus 'is active' assertion in channelRead0 (#739)
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
2019-01-07 14:18:48 +00:00
Johannes Weiss fa2ebe4a56 remove backports of newer Swift functionality (#738)
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
2019-01-07 12:32:58 +00:00
Johannes Weiss 95b290a51f use automatic Equatable conformances (#737)
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
2019-01-07 11:52:22 +00:00
Johannes Weiss 684cad331c EventLoopFuture: use Result type (#734)
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
2019-01-05 08:08:47 +00:00
Johannes Weiss 08eb3259ce better DispatchData support (#732)
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
2019-01-03 17:45:45 +00:00
Johannes Weiss 695b1ebe13
prefer non-deprecated API for Data/Range (#733)
Motivation:

Deprecated API sucks.

Modifications:

Use non-deprecated API for Data/Range stuff

Result:

better code
2019-01-03 16:00:16 +00:00
Johannes Weiss 90b72abd21
re-enable allocation test for Swift 5 (fixes #685) (#710)
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
2019-01-03 11:32:13 +00:00
Cory Benfield 0db974bdbe
Fix: BlockingIOThreadPool not releasing the latest WorkItem (#716) (#730)
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)
2019-01-03 10:58:15 +00:00
Ilya Puchka 0db96bf744 [NIOHTTP1Server] Use fixed default string to write in response and do not hardcode content length (#718)
* 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
2019-01-03 10:09:13 +00:00
Ilya Puchka b878f06b20 override content encoding header value in compressor (#728)
override content encoding header value in compressor
2019-01-03 09:57:57 +00:00
Johannes Weiss 3ce1c25dfb raise Swift 5 ByteBuffer read/write allocation limit (#729)
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.
2019-01-03 08:25:04 +00:00
Johannes Weiss 0221ab8efc raise Swift 5 HTTP/1 req/res pair alloc limits (#725)
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.
2019-01-02 19:35:17 +00:00