Commit Graph

808 Commits

Author SHA1 Message Date
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
Norman Maurer 5aff263ad9 Correctly handle ChannelError.eof when reading data from Socket
Motivation:

The code to filter out ChannelError.eof when reading from the socket and not call fireErrorCaught(...) was broken and so the error was propagated through the pipeline.

Modifications:

- Correctly filter out .eof
- Added testcase

Result:

Correct handling of .eof
2018-02-12 16:50:34 +01:00
Norman Maurer 5705ce104a Add Channel extension which allows to automatically wrap data into NIOAny 2017-12-28 15:37:06 +01:00
Norman Maurer e70587308a Add echo client example
Motiviation:

We already include an echo server as example but not a client portion. This example sends a message to the server and once it received back the message it will close the connection and exit.

Modification:

Add NIOEchoClient example.

Result:

More examples.
2018-02-12 15:15:35 +01:00
Norman Maurer aa9728b852 Use Int for port to make API more consistent
Motivation:

In ClientBootstrap we use Int to represent the port but in ServerBootstrap we use Int32. As swift usually always use Int we should just use Int everywhere to represent the port.

Modifications:

Change Int32 to Int for port

Result:

More consistent API
2018-02-12 13:39:01 +01:00
Norman Maurer 18a8467dfe Make parameter naming between connect / bind consistent.
Motivation:

We should have consistent parameter naming.

Modifications:

Use to path: everywhere.

Result:

Consistent naming.
2018-02-12 14:21:07 +01:00
Johannes Weiß e3ea0d7f5d small cleanups 2018-02-05 17:47:04 +00:00
Johannes Weiß 1d7302a189 make future map not allocate if the values are () 2018-02-12 12:46:49 +00:00
Johannes Weiss 01c6e175b7 improve FileRegion tests 2018-02-12 11:52:55 +00:00
Norman Maurer 4f75af6582 Allow access to pthread_t via withUnsafe function.
Motivation:

We should better allow access to pthread_t via an withUnsafe function which is more swift-like.

Modifications:

- Add withUnsafePthread and use it
- mark pthread_t as private in Thread.

Result:

More swifty code.
2018-02-12 12:29:07 +01:00
Norman Maurer 0b5d59fd25 Consolidate #if #else blocks and use precondition
Motivation:

We sometimes used fatalError(...) where we really could just use precondation(...). Beside this we can also consolidate the #if #else code for handling Darwin and Linux differently and so make the code easier to maintain.

Modifications:

- Use precondation
- Consoldate #if #else blocks for Thread

Result:

Cleaner and easier to maintain code.
2018-02-12 09:21:14 +01:00
Norman Maurer b09c1598af Fix testcase which was not correctly updated as part of 845d9ee8e95e8ba61e550a26b0a70d59ee98c97d 2018-02-12 08:39:38 +01:00
Norman Maurer a8f0dcf0f5 Use computed property for System.coreCount
Motivation:

We should use a computed property to be more swifty.

Modifications:

Replace function with computed property

Result:

More swifty code.
2018-02-11 13:11:54 +01:00
Johannes Weiß 11a609396d don't blow up when holding onto a ChannelPipeline of a deinitialised Channel 2018-02-09 14:53:09 +00:00
Johannes Weiß ebf351abda implement thread specific values 2018-02-08 17:37:01 +00:00
Cory Benfield 9b0b0f9b51 Add support for SOCK_DGRAM 2018-02-08 14:58:10 +00:00
Cory Benfield 3f357a3c79 Minor cleanups for Swift 4.1 2018-02-08 11:40:45 +00:00
Cory Benfield dfe3fe212a Better readme for release 2018-02-09 12:25:50 +00:00
Johannes Weiss 734904d0f4 clean up the (proto)types for EventLoopFuture
* clean up the (proto)types for EventLoopFuture

* Remove more unnecessary parens
2018-02-09 16:03:28 +00:00
Norman Maurer 17b5fd58e4 Use aliases to reduce duplication and make it easier to maintain.
* Use aliases to reduce duplication and make it easier to maintain.

Motivation:

We used many #if #else blocks which made the code very clumby.

Modifications:

Use aliases and define these in one place.

Result:

Easier to maintain code.

* Comments

* Comments
2018-02-09 16:56:52 +01:00
Norman Maurer e1f015aa07 Remove out of date to do.
Motivation:

TODO is not valid anymore.

Modifications:

Remove it.

Result:

No missleading comment anymore.
2018-02-09 15:03:46 +01:00
Norman Maurer 3bfdd3f55b Adapt git template that is also used by Netty 2018-02-09 12:19:12 +01:00
Norman Maurer 49b0af924d Add docs for Selector
* Add docs for Selector

* comments
2018-02-08 19:36:26 +01:00
Daniel Dunbar 41bf7278f8 [NIO] Fix setOption() to be async.
- This fixes Bootstrap's ChannelOptionStore.applyAll to return a future rather
   than synchronously iterating through all the options.

 - This is particular important because when a server accepts a child, if the
   child channel is on a different event loop then it is possible the
   synchronous calls may deadlock (if the child's eventloop happens to be
   scheduled with a similar accept sequence).

 - I did not tackle also making getOption() async, which means the Channel API
   is asymmetric at the moment. That should probably be addressed, potentialy
   with synchronous wrappers for API compatibility.

 - Fixes: <rdar://problem/37191923> [Omega] Worker tasks fail to close subtasks (many connections in CLOSE_WAIT state)
2018-02-08 09:21:40 -08:00
Norman Maurer 995177fbc6 Support setting Thread affinity and use it with EventLoopGroups 2018-02-06 16:08:57 +01:00
Cory Benfield ce7b0c52ce Add a CompositeError type 2018-02-08 13:12:30 +00:00
Cory Benfield 08817ded87 Remove copy in withMutableSockAddr 2018-02-08 12:52:03 +00:00
Cory Benfield 41f3abe366 BaseSocketChannel should use NIOAny 2018-02-08 11:42:01 +00:00
Cory Benfield d216f6a7e9 Add public constructor for AddressedEnvelope 2018-02-08 11:21:55 +00:00
Johannes Weiß b26bfce61e detach threads so we don't leak them 2018-02-08 10:57:51 +00:00
Cory Benfield 453b87ff5e Fixup thread unsafety 2018-02-08 10:57:46 +00:00
Cory Benfield 3768e2a2b9 Don't allow registration on shutting down loops 2018-02-08 10:25:47 +00:00
Norman Maurer 71f179e63b Change Thread to be internal as we not expose it to the user 2018-02-08 09:26:53 +01:00
Johannes Weiss 8ed8f73d9a remote now unnecessary swiftw script 2018-02-07 17:31:39 +00:00
Johannes Weiss 755ea5aedc non-blocking file IO 2018-02-07 17:25:45 +00:00
Johannes Weiß 676453c8b9 trivial: fix RecvByteBufferAllocator typos 2018-02-06 18:24:48 +00:00
Johannes Weiss e21432e955 don't leak open FileRegions (fds) in HTTP client 2018-02-06 16:35:35 +00:00
Johannes Weiß 9c73c9deb9 fix flaky ChannelTests.testHalfClosure 2018-02-06 15:24:01 +00:00