Commit Graph
2945 Commits
Author SHA1 Message Date
Norman Maurer ebae948897 Add docs for ChannelCore methods. (#17)
Motivation:

`ChannelCore` methods lack docs.

Modifications:

Add docs.

Result:

More docs == happier users
2018-02-22 16:38:10 +00:00
Norman Maurer b3e2362f40 Add docs for NIOAny methods. (#16)
Motivation:

NIOAny methods did not have any documentation.

Modifications:

- Add docs to methods.
- Fix typos.

Result:

More docs.
2018-02-22 15:31:16 +00:00
Cory Benfield 2a3396998d HTTPUpgradeHandler should accept Futures for upgraders. (#10)
Motivation:

Currently the HTTPUpgradeHandler does not allow for the protocol
upgraders to return EventLoopFuture objects. This leads to an
awkward scenario: it's essentially required that an upgrader be able
to synchronously change the pipeline to its satisfaction and prepare for
more bytes.

This is not really possible: ChannelPipeline.add(handler:) returns a
Future, which means that it is possible for this operation, at least
in principle, to not execute synchronously. This reality puts the
HTTPUpgradeHandler at odds with the reality of channel pipelines, and
cannot stand.

Modifications:

Give the HTTPProtocolUpgrader protocol to have upgrade() return an
EventLoopFuture<Void>, and update the HTTPServerUpgradeHandler to
appropriately handle the returned future by buffering until the future
completes.

Result:

It is no longer necessary to synchronously change the channel
pipeline during protocol upgrade.
2018-02-22 14:03:26 +01:00
tomer doron 31a693fd93 fix doc generation (#8)
Motivation:

doc generation broken due to module rename and lack of tags

Modifications:

* update module names
* set default version if tag not found

Result:

doc generation works again
2018-02-22 07:57:46 +01:00
tomer doron dffb404cf0 fix broken swift-nio-http2 link (#6)
Motivation:

swift-nio-http2 is not released yet, link is broken

Modifications:

replace link with coming soon notice

Result:

no broken link
2018-02-21 14:53:59 -08:00
tomer doron 379feabc54 update getting started guide to use git ssh address (#5)
Motivation:

consistency with other examples

Modifications:

use git ssh address in Package.swift example

Result:

more consistent with other getting started guides
2018-02-21 20:17:20 +01:00
Cory Benfield 088c09ece5 Improve Linux test gen script to match current format. (#3)
Motivation:

Right now the test gen script will rewrite every file. Not ideal!

Modifications:

Added the license header, and made the follow-on comment match that
style.

Result:

Test files will look the same when running this script as they do
now.
2018-02-21 20:16:28 +01:00
Cory Benfield c8c8dbf2a2 Don't require casing to match in the HTTP upgrade header. (#1)
Motivation:

The HTTP upgrade handler should not require that we case-match with
the mandatory headers.

Modifications:

Treat all headers as lowercase.

Result:

Upgrade is easier.
2018-02-21 20:15:12 +01:00
Johannes Weiß de0bc1ed83 fix integration tests on Darwin (#4)
Motivation:

The integration tests didn't work on Darwin anymore as the `CNIODarwin`
module wasn't included in their build.

Modifications:

Included the `CNIODarwin` module, just like `CNIOLinux`.

Result:

integration tests run on Darwin
2018-02-21 20:14:24 +01:00
Daniel Dunbar e41acdaa4d [README] Add a note on supported platforms. (#2)
Motivation:

Make sure it is obvious that SwiftNIO is cross-platform, and also communicate
what platforms are expected to work/will be supported currently.

Modifications:

Amended README.md

Result:

The README documents our current expectations on supported platforms.
2018-02-21 17:35:49 +00:00
Cory Benfield d2c5c7aad1 Add documentation for EventLoopFuture and EventLoopPromise
Motivation:

It's useful to be able to understand how these objects work.

Modifications:

Documented the public interface for both types.

Result:

There will be documentation
2018-02-21 13:15:49 +00:00
Johannes Weiss 5deffc630d replace var closed with var isOpen for more positive conditions
Motivation:

guard !self.open else { ... } is a double negation and can be confusing,
guard self.isOpen else { ... } is much better

Modifications:

replaced all `var closed: Bool` with `var isOpen: Bool`

Result:

we're more positive
2018-02-21 15:09:22 +00:00
Norman Maurer 8c2169663d Add docs for ByteToMessageDecoder and MessageToByteEncoder
Motivation:

We should provide docs for our provided codec extensions.

Modifications:

Add docs.

Result:

More clear for the user how to implement a custom codec.
2018-02-21 15:56:54 +01:00
Cory Benfield 93a1f8e6fd Explain non-blocking I/O
Motivation:

It would be nice to have a bit of an explainer on the name.

Modifications:

Add a paragraph explaining non-blocking I/O.

Result:

There is now a paragraph in the readme explaining non-blocking I/O.
2018-02-21 08:39:52 +00:00
Norman Maurer 2180d03690 Channel.getOption(...) should return EventLoopFuture and not block
Motivation:

Channel.getOption(...) should return an EventLoopFuture to ensure we not end up with a deadlock.

Modifications:

Change getOption(...) to return EventLoopFuture.

Result:

No deadlocks and more consistent API.
2018-02-21 11:55:15 +01:00
Norman Maurer adbcd7c4a8 Make half-closure tests more robust.
Motivation:

Out half-closure tests did not wait for the actual event to be received before trying to tear-down the Channel which could lead to test-failures if the event was received not fast enough. We need to ensure we wait until we receive the event before closing the Channel and assert the received events.

Modifications:

Ensure we wait for the events before we try to close the Channel and assert the received events.

Result:

Less flaky tests.
2018-02-21 10:53:52 +01:00
Johannes Weiß 2e5f62d653 make ByteBuffer.set/write work on Sequence rather than Collection
Motivation:

Previously we required the `ByteBuffer.set/write` methods to be a
`Collection` of `UInt8` but a `Sequence` is really enough.

Modifications:

Implemented `ByteBuffer.write/set` for `Sequence`s of `UInt8`

Result:

More stuff can be used with `ByteBuffer`
2018-02-20 16:37:39 +00:00
Johannes Weiss c7e47e75f3 remove flush promises
Motivation:

We have multiple reasons why flush promises weren't great, for example:

- writeAndFlush sounds like it's a write + flush optimisation but in
  reality it was more expensive (2 extra promises)
- the semantics were never quite clear
- lots of implementation complexity, especially for the datagram channel

Modifications:

- removed the flush promises in the API
- this deliberately doesn't do the PendingWritesManager simplifications
  that this unlocks

Result:

flush doesn't have a promise anymore.
2018-02-20 16:13:41 +00:00
Johannes Weiß c6fa249797 implement Max's suggestions
Motivation:

Max Moiseev had some good suggestions on how to clean up some APIs, this
implements those.

Modifications:

- remove `IOData.isFileRegion` (not necessary or used)
- offer an optional `as: T.Type` parameter for the integer reading methods
- remove one unnecessary method in `StaticString`'s `Collection` conformance

Result:

nicer
2018-02-20 15:51:35 +00:00
Johannes Weiß 64eac6177c make inbound channel operations non-throwing
Motivation:

Except for blocking methods (which shouldn't be used on the event loop),
there aren't that many error cases that we should just send through the
pipeline automatically. Best proof for that is that nothing in the code
base did that. Therefore these methods shouldn't be throwing.

If the user does indeed want to catch and fire an error through the
pipeline that's still super simple `ctx.fireErrorCaught(error)`.

Modifications:

removed `throws` from the `ChannelInboundHandler` methods.

Result:

better
2018-02-19 18:10:21 +00:00
Cory Benfield 58e147f682 ByteToMessageDecoder should reclaim memory.
Motivation:

ByteToMessageDecoder implementations can potentially have usage
patterns that never reclaim memory. This is problematic when used
for a long time, as they can be holding on to large chunks of memory
they don't need.

Modifications:

Gave ByteToMessageDecoder a new protocol method,
shouldReclaimBytes(buffer:), and a default implementation.

Result:

ByteToMessageDecoders will not be able to hold on to more than 2kB
of unreachable memory under any circumstances, and will often hold
less memory than that.
2018-02-20 14:12:20 +00:00
Norman Maurer 6e9b626d57 We should not use deprecated methods.
Motivation:

We had some usage of deprecated methods.

Modifications:

Replace deprecated method usage.

Result:

No more warnings during build.
2018-02-20 16:21:04 +01:00
Johannes Weiss 68724be6e6 fix Channel thread-safety (local/remoteAddress)
Motivation:

There were a couple of places in the Channel implementations that just
weren't thread-safe at all, namely:

- localAddress
- remoetAddress
- parent

those are now fixed. I also re-ordered the code so it should be easier
to maintain in the future (the `// MARK` markers were totally
incorrect).

Modifications:

- made Channel.{local,remote}Address return a future
- made Channel.parent a `let`
- unified more of `SocketChannel` and `DatagramSocketChannel`
- fixed the `// MARK`s by reordering code
- annotated methods/properties that are in the Channel API and need to
be thread-safe

Result:

slightly more thread-safety :)
2018-02-20 15:18:51 +00:00
Norman Maurer 273932ae36 Change ByteToMessageDecoder.decode and decodeLast to return an enum.
Motivation:

We used a bool to signal if we should continue decoding or not. Using an enum is more self-documenting.

Modifications:

Add DecodingState and use.

Result:

Code is more self-documenting.
2018-02-20 13:07:31 +01:00
Tom Doron 5f114eb3f7 fix documentation generation
motivation: bring documentation generation closer to what it will look like on oss

changes:
* make cacheable steps conditional
* use absolute path for source-kitten generated index files
2018-02-19 17:38:34 -08:00
Cory Benfield 6b999ad368 Remove quadratic buffering from ByteToMessageDecoder
Motivation:

Don't make the system fall over under slowloris-style attacks.

Modifications:

Remove the quadratic copy loop from ByteToMessageDecoder.

Result:

NIO goes from 🚂 to 🚄
2018-02-20 08:02:43 +00:00
Norman Maurer 1912948fd4 Remove promise parameter on read method.
Motivation:

The promise on read is not very useful, we should just remove it.

Modifications:

Remove promise.

Result:

Cleaner code.
2018-02-19 21:39:46 +01:00
Johannes Weiß 85513e7268 rename linker tests 2018-02-19 20:08:13 +00:00
Tom Doron 7d5dc67af8 scripts cleanup
motivation: nicer source tree

chanages:
* move scripts to scripts directory
* move integration tests to IntegrationTests directory and remove driver script
* add .sh extension to bash scripts
* adjust rio.yaml
2018-02-12 10:06:46 -08:00
Johannes Weiss 26582a3e97 redundant let elimination
Motivation:

`let _ = ...` is redundant and should be `_ =`

Modifications:

removed redundant `let`s

Result:

saved disk space ;)
2018-02-19 17:41:52 +00:00
Johannes Weiss 225951e7c3 remove Foundation dependency
Motivation:

Foundation is problematic for a few reasons:
- its implementation is different on Linux and on macOS which means our
  macOS tests might be inaccurate
- on macOS it uses ObjC Foundation which means the autorelease pool
  might get populated
- it links the world on Linux which means we can't do static
  binaries at all

Modifications:

removed the last bits of Foundation dependency

Result:

no Foundation dependency
2018-02-19 17:22:38 +00:00
Johannes Weiss 8e173fb348 small channel flush refactoring
Motivation:

Previously in `flushNow()` we had an odd case: A loop that could never
loop. Also `flushNow()` returns a boolean with a complicated meaning:

 - `true`: We wrote everything, so we don't need to be registered for
 writing
 - `false`: We couldn't write everything, write notification necessary

Modifications:

Removed the non-loop & made the odd bool an enum.

Result:

code easier to read.
2018-02-19 16:35:56 +00:00
Johannes Weiss 94213c74fd remove one Foundation import & one copy/roundtrip through Data
Motivation:

The SNI handler used Foundation for something that can be done fairly
easily without. Also avoids going through Data.

Modifications:

Removed Foundation method and implemented directly on Swift stdlib's
String encoding methods.

Result:

one less Foundation import
2018-02-19 12:59:03 +00:00
Johannes Weiss ca6b0ff28d replace Foundation whitespace trimming
Motivation:

For HTTP parsing, we used Foundation to trim whitespace which is not
needed.

Modifications:

Implemented whitespace trimming in Swift.

Result:

less Foundation
2018-02-19 12:55:29 +00:00
Johannes Weiss 4a09182a39 rewrite closures that just ignore their parameter & change whenComplete
to not return a value

Motivation:

We recently had a bug where we had `EventLoopFuture<EventLoopFuture<()>>` which didn't make any sense. The compiler couldn't catch that problem because we just ignored a closure's argument like this:

    future.then { _ in
        ...
    }

which is dangerous. For closures that take an empty tuple, the `_ in`
isn't actually required and the others should state the type they want
to ignore.

And most whenComplete calls can be better (and often shorter) expressed
by other combinators.

Modifications:

remove pretty much all closures which just blanket ignore their
parameter.

Result:

- no closures which just ignore their parameter without at least stating
  its type.
- rewrote all whenCompletes that actually used the value
2018-02-16 17:28:43 +00:00
Norman Maurer eb98b651bb Cleanup test code
Motivation:

We had a few return statements that could be removed and some places where trailing closure syntax could be used.

Modifications:

- Remove returns
- Use trailing closures

Result:

Cleaner code.
2018-02-16 15:22:18 +01:00
Norman Maurer 55e99b603d Expose BlockingIOThreadPool
* Expose BlockingIOThreadPool

Motivation:

Sometimes we need to execute some blocking IO. For this we should expose the BlockingIOThreadPool that can be used.

Modifications:

- Factor out BlockingIOThreadPool
- Added tests
- Correctly start threadpool before execute NonBlockingIO tests.

Result:

Possible to do blocking IO.

* Corrys comment

* Correctly start pool before using it
2018-02-16 14:53:19 +01:00
Cory Benfield ab9427bdd4 Initial UDP support 2018-01-16 17:00:09 +00:00
Norman Maurer 3f4a755de1 Remove no needed return statements and cleanup examples.
Motivation:

We do not need to use return in the closures used in the examples.

Modifications:

- Remove return
- Remove bug where we set the same channel option two times in one example

Result:

Cleaner code.
2018-02-16 10:50:57 +01:00
Johannes Weiss 0e7b90ef16 unify channel write handling for stream and datagram channels
Motivation:

After the previous change to the channel writes, the datagram and the
stream PWMs behaved differently and there was code duplication.

Modifications:

Removed different behaviour & reduced code duplication

Result:

Less code and hopefully less bugs.
2018-02-16 09:19:52 +00:00
Johannes Weiss be1de1c433 simplify channel writes
Motivation:

Channel writes are a complex matter and it was even more
complex when `FileRegion` and `ByteBuffer` were completely
different kinds of objects. Now that they're more in line we can
simplify a lot of things.

Modifications:

Rewrote the inner layers of channel writes to make them more readable
and hopefully more correct.

Result:

hopefully fewer bugs.
2018-02-15 14:07:57 +00:00
Norman Maurer 68f20f84fd Make the Resolver pluggable.
Motivation:

We should allow to use a custom Resolver for the ClientBootstrap as users may want to use different strategies then using a DNS based approach.

Beside this GetaddrinfoResolver should not keep any state and should be more rebust as at the moment it only will ever complee the future for the A query if also an AAAA query was sent.

Modifications:

- Make Resolver protocol public
- Remove state in GetaddrinfoResolver and so allow to use it multiple times. Now it is also more conform to the protocol itself.

Result:

Allow to use custom Resolver
2018-02-15 14:50:51 +01:00
Johannes Weiss 0370f98f2b examples for {Server,Client}Bootstrap
Motivation:

The bootstraps are important objects that everybody will use and I think
the best way to explain them is a simple example.

Modifications:

Added examples in the doc comments.

Result:

hopefully easier to use.
2018-02-14 17:42:57 +00:00
Johannes Weiß 5cb13b21e6 make FileRegion a value type and behave much more like ByteBuffer
Motivation:

Previously `FileRegion` was a special snow flake, a bit like
`ByteBuffer` but also totally different. That caused surprise and made
`PendingWritesManager` even harder. It was also used to manage the
lifetime of a file descriptor but only sort of.

Modifications:

We now have a `FileHandle` which is a one-to-one mapping with a file
descriptor and its lifetime must be managed appropriately.

Result:

hopefully less bugs and fd leaks.
2018-02-06 16:48:35 +00:00
Cory Benfield 67bb71e44b Add a pending datagram writes manager
This change adds support for doing datagram-style writes. It's not currently
hooked up to anything, but it will be sometime soon.
2018-02-14 15:32:31 +00:00
Norman Maurer 52aa0a1c43 Add a chat server / client example
* Add a chat server / client example

Motivation:

We should add some more complex examples.

Modifications:

Add a chat server and client example.

Result:

More examples.

* Comments

* More comments
2018-02-13 14:26:47 +01:00
Johannes Weiss eaa8ffaee4 remove redundant labels
Motivation:

Lots of our most important operations had redundant labels like

    func write(data: NIOAny)

the `data: ` label doesn't add anything meaningful and therefore it
should be removed.

Modifications:

removed lots of redundant labels

Result:

less redundant labels
2018-02-13 11:13:30 +00:00
Johannes Weiß dba0a5379c fix longstanding typo in newSucceededFuture
Motivation:

We used to have a method `newSucceedFuture` which should be
`newSucceededFuture`

Modifications:

grammar

Result:

better grammar
2018-02-13 09:55:33 +00:00
Johannes Weiß 2c95f53e0f fix master build
Motivation:

master didn't build

Modifications:

fixed it

Result:

works again
2018-02-12 18:51:26 +00:00
Johannes Weiß 85b45e6912 make function names for connect/bind/SocketAddress more Swift-like 2018-02-12 15:09:22 +00:00