Commit Graph

91 Commits

Author SHA1 Message Date
Gautier Delorme 0695662d7d
fix cores count in containers (#1518)
Motivation:

The current System.coreCount implementation relies on _SC_NPROCESSORS_ONLN so isn't cgroups aware which might have a bad impact for apps runnings in containers (e.g. Docker, Kubernetes, Amazon ECS...).

Modifications:

- Changed System.coreCount on Linux only to make it read from CFS quotas and cpusets when present.
- Removed incorrect precondition in Sources/NIO/LinuxCPUSet.swift

Result:

System.coreCount returns correct values when apps run in containers.

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-05-15 10:09:35 +01:00
Johannes Weiss b2d937b22f
shorten NIOThreadPool's thread names (#1466)
Motivation:

Previously, NIOThreadPool would use super long thread names. Linux
doesn't allow more than 15 bytes (+ \0 char) so in the end they would
never get set at all.

Modifications:

- Shorten NIOThreadPool's thread names
- Only take the first 15 characters of thread names in general on Linux

Result:

We don't lose thread names on Linux.
2020-03-31 20:01:56 +01:00
Johannes Weiss 2ad77f9a9b
WIP: universal bootstrap (#1323)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-03-18 16:20:19 +00:00
Doug Friedman a4fe7d4840
get IOError down to git in an existential container (#1355) (#1376)
resolves #1355 shaving off some bytes from IOError struct

Motivation:

It's important for frequently used errors to fit in existential containers because otherwise throwing them leads to allocations.

Modifications:

- Don't store `StaticString`s anymore which are 2 words + 1 bytes wide

Result:

Fewer allocations when IOErrors are thrown.
2020-02-03 12:30:37 +00:00
Johannes Weiss 52a4cae14d
add SAL (Syscall Abstraction Layer) and new SALChannelTests
## Motivation:

In SwiftNIO's codebase, most things were always testable just as well as user code is. With one big missing piece: We could never make the `Selector` do arbitrary things to the `Channel` implementations which lead to super expensive to (create, read, understand) integration tests like [`testWriteAndFlushFromReentrantFlushNowTriggeredOutOfWritabilityWhereOuterSaysAllWrittenAndInnerDoesNot `](5dc9083c6a/Tests/NIOTests/StreamChannelsTest.swift (L468-L760)).

## Modification

Add SAL, a 'syscall abstraction layer' which makes it possible to assert all syscalls that come through a `Socket` or the `Selector` by mocking them. It lets the NIO programmer play the kernel in these "SAL tests" which makes it possible to assert the exact syscalls (with their parameters) and decide the syscalls' returns.

## Result

Finally, we're able to write proper unit tests for scenarios where the `Channel` drove the `Selector` incorrectly.
2020-01-28 12:36:36 +00:00
Richard Low 1f94a6e620 Out of pipeline byte stream decoding (#1268)
* Add NIOSingleStepByteToMessageDecoder and NIOSingleStepByteToMessageProcessor
for processing byte streams outside of the channel pipeline.

Motivation:

ByteToMessageHandler works well when you can embed it in your pipeline, but if
you have a wrapped protocol (e.g. sending a protocol over HTTP), you can't use
it without losing the context of the outer protocol (e.g. HTTP headers/trailers).

Modifications:

Added NIOSingleStepByteToMessageDecoder and NIOSingleStepByteToMessageProcessor.

Result:

New functionality above.
2019-12-03 11:29:38 +00:00
Johannes Weiss c2c725044a
allow deprecated tests to test deprecated functionality (#1271)
Motivation:

It's important to also test deprecated functionliaty. One way of
achieving this without warnings is to also deprecate the tests that test
this deprecated functionality. Unfortunately, on Linux we need to
generate lists of tests which would then reference deprecated tests
(which gives us a warning).

Modifications:

Deprecate test suites and the main test runner all the way to the top so
never get warnings.

Result:

Possible to test deprecated functionlity without warnings.
2019-11-27 14:26:51 +00:00
Johannes Weiss 8dd62cb068
ByteBuffer: add direct Codable support (#1153)
Motivation:

So far, it has been harder than necessary to use Codable & ByteBuffer.
These new APIs should simplify that and allow future optimisations.

Modifications:

Add new API to use `JSONEncoder` and `JSONDecoder` directly with
`ByteBuffer`.

Result:

Easier Codable + ByteBuffer usage.
2019-10-17 16:03:44 -07:00
Johannes Weiss e102aa9ae9
add PipeChannel (#1138)
Motivation:

There are use-cases for SwiftNIO where there are no actual sockets but
rather two pipe file descriptors - one for input, one for output.
There's no real reason why SwiftNIO shouldn't work for those.

Modifications:

Add a PipeChannel.

Result:

More use-cases for SwiftNIO.
2019-10-16 22:06:55 -07:00
Mario Sangiorgio 23303e7ce7 NIOHTTP1TestServer (#1152)
* NIOHTTP1TestServer implementation

* Test simple request and two concurrent requests

* Accepting multiple connections but keeping only one active at a time

* Linux tests

* Addressed some PR comments
2019-10-02 12:10:09 +01:00
George Barnett a545d59c47 Fix creating HTTPResponseStatus from 418 (#1140)
Motivation:

I ran across a case in a test where `HTTPResponseStatus(statusCode: 418)`
unexpectedly returned a `.custom` response status.

Modifications:

- Add a missing `case` for creating a status from `418`
- Shuffled some of cases around so that they are correctly listed in the
  correct 2xx, 3xx, 4xx etc. sections

Result:

- `HTTPResponseStatus(statusCode: 418)` now returns `.imATeapot`
2019-09-13 15:28:40 +01:00
Will Lisac 26586835fd Fail promise in MessageToByteHandler write error cases (#1096)
* Fail promise in MessageToByteHandler write error cases

* Add test case for MessageToByteHandler failing write promises
2019-08-08 10:33:00 +01:00
Liam Flynn 64c673b6e8 Add a WebSocket client upgrader. (#1038)
Motivation:

There is a client protocol upgrader but, unlike the server protocol upgrader, it does not have a WebSocket protocol as part of the project.

Modifications:

Made the magic WebSocket GUID public to the WebSockets project.
Added a NIOWebSocketClientUpgrader.
Added tests for the upgrader.
Updated the Linux test script files.

Result:

The project now has a WebSocket client upgrader to match the WebSocket server upgrader.
2019-07-08 03:55:02 -04:00
Liam Flynn 57785e6d9c An HTTP upgrader class for a client pipeline. (#1001)
* Reorder ‘channel active’ calls to the same order as `_ChannelInboundHandler` and their likely chronological order.

Motivation:
When first viewing the example classes, coming to the ‘read’ method first, leaves the subject unclear as to what the method is ‘reading’.
It is preferable to view something being sent first, and then to view the reading of the response.
It also matches the call order against the protocol making it a little easier for those unfamiliar with the protocol to see which methods have been implemented.

Modifications:
Moved channel active calls to be top of the class.
Despite the diff there are no actual code modifications.
UDP Client changed to indent using spaces to match rest of project. Incidental change.

Result:
The examples are slighter clearer to read, particularly for newcomers to swift-no as the calls are in a logical chronological order.

* Fix an error in the upgrader and its tests which checked the connection header incorrectly.

Motivation:
To correct the logic in the upgrader. Previously it checked if the upgraders required headers include the connection header. Now it checks that the connection header value was present as a separate header in the incoming request.
To prepare the class naming for the presence of a client upgrader.

Modifications:
Slight change in server upgrader handler logic with accompanying tests.
Renamed upgrader and test files to include the word ‘server’.
Ran the linux test script.

Result:
The server upgrader now checks for the presence of the connection header value as a header of its own.

* Rename WebSocketServer upgrader to make the naming clearer and make way for a client version.

Motivation:

To make the web socket upgrader naming clearer, particularly once we add a client version.

Modifications:

Rename WebSocketUpgrader too WebSocketServerUpgrader.

Result:

Improved clarity of naming on the web socket upgrader.

* Adds  correct naming conventions to NIOWebSocketServerUpgrader. Sets back an incorrect fix (non-fix).

* Move deprecation for NIOWebSocketServerUpgrader typealias out of API shims file.

* Makes HTTPEncoder removable.
Adds a client upgrade handler with tests.
Adds the ability to use a client upgrader to the client setup.
Initial linux file update.

* Allow assertContains to be accessed publicly, so that it can be used in the client side tests.

* Update tests to remove server upgrader from client tests.
Change client tests to use Embedded channel.
Update HTTPUpgradeConfiguration class name to be NIOHTTPServerUpgradeConfiguration
Few other small stylistic changes.

* Removed awaiting upgrader state.
Removed future from handle upgrade call as is synchronous.
Removed protocol iterator from handle upgrade call as is not required by the client.

* Ensure that the client handler calls for the HTTPPipeline are backwards compatible.
Ensure that incoming promises to the handler write call are completed.
Neaten the upgrade header formation to remove looping.
Improve the correctness of the upgrade error throwing.

* Update scripts to match new unit tests.

* Change the documentation for HTTPServerPipeline to remove nil options which have now been removed.

* Restore an incorrectly added server pipeline comment change and make it to the client pipeline instead.

* Raise the allocation limits in the docker images to allow the tests to pass.
2019-06-16 11:10:12 +01:00
Liam Flynn f5084352c6 Rename the EndToEndTests in the WebSocket project to WebSocketServerEndToEndTests. (#1032)
Motivation:

To make the web socket server end to end tests class more descriptive.
This will allow ‘WebSocketClientEndToEndTests’ or other end to end tests to be added at a later date.

Modifications:

Renames the class and filename for ‘EndToEndTests’ to ‘WebSocketServerEndToEndTests’

Result:

The nomenclature now allow for other end to end tests to be added.
2019-06-11 19:22:02 -07:00
Johannes Weiss ccc459a86e TestUtils: EventCounterHandler (#1005)
Motivation:

In many unit tests, it's important to count the events. So far we have
many many ad-hoc handlers to do so but having one that counts all events
would be handy.

Modifications:

Add `EventCounterHandler` to count all events travelling the
`ChannelPipeline`.

Result:

Easier unit testing
2019-05-17 14:09:03 +01:00
Johannes Weiss 5513bb202a
Create NIOTestUtils & add B2MD verifier (#939)
Motivation:

When writing B2MDs, there are a couple of scenarios that always need to
be tested: firehose feeding, drip feeding, many messages, ...

It's tedious writing those tests over and over again for every B2MD.

Modifications:

- Add a simple B2MD verifier that users can use in unit tests.
- Add a new, public `NIOTestUtils` module which contains utilities
  mostly useful for testing. Crucially however, it does not depend on
  `XCTest` so it can be used it all targets.

Result:

Hopefully fewer bugs in B2MDs.
2019-05-10 17:29:13 +01:00
Liam Flynn 993a3b7521 Update naming to allow for the easy addition of a HTTP client upgrader. (#983)
Motivation:

To make the web socket upgrader naming clearer, particularly once we add a client version.

Modifications:

Rename WebSocketUpgrader too WebSocketServerUpgrader.

Result:

Improved clarity of naming on the web socket upgrader.
2019-05-02 11:02:48 +01:00
Romain Pouclet 4991d0930f Add a way to convert HTTP methods from/to String (#976)
Motivation:

https://github.com/apple/swift-nio/issues/701

Modifications:

* Add `init(rawValue:)`
* Add `rawValue`
* Add tests in HTTPTypesTest.swift

Result:

Users no longer have to write their own conversion methods.
2019-04-30 13:17:54 +01:00
Romain Pouclet d093ae0659 Add a Channel Handler that closes the channel (#967)
Motivation:
Because of #600, many users will start leaking Channels because they
don't close on error.

Modifications:

* Add ChannelHandlerError
* Add ChannelHandlerErrorTest

Result:

User will have access to an handler to use to automatically close
the channel in case of unhandled errors
2019-04-30 12:06:24 +01: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
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
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 ce39ec20c0 all caps for SNI (#693)
Motivation:

In Swift, abbreviations use the same case for all letters, therefore it
should be `SNI` and not `Sni`.

Modifications:

changes `Sni` to `SNI`

Result:

more consistent with naming guidelines
2018-12-10 20:28:10 +00:00
Cory Benfield c73eb57694
Support UDP multicast. (#618)
Motivation:

A large number of very useful protocols are implemented using multicast
with UDP. As a result, it would be helpful to add support for joining and
leaving IP multicast groups using SwiftNIO.

Modifications:

- Defines a MulticastChannel protocol for channels that support joining and
  leaving multicast groups.
- Adds an implementation of MulticastChannel to DatagramChannel.
- Adds a interfaceIndex property to NIONetworkInterface.
- Adds if_nametoindex to the Posix enum.
- Adds a isMulticast computed property to SocketAddress
- Adds a demo multicast chat application.
- Add a number of multicast-related socket options to SocketOptionProvider.

Result:

NIO users will be able to write channels that handle multicast UDP.
2018-09-24 10:24:09 +01:00
Cory Benfield be4ea8ac74 Add SocketOptionChannel for wider socket options. (#589)
Motivation:

A small number of socket options have values that do not fit into a C
int type. Our current ChannelOption based approach for setting these
simply does not work, and cannot be extended to support the truly arbitrary
types that the setsockopt/getsockopt functions allow here.

This makes it impossible to use some socket options, which is hardly a
good place to be.

There were a number of ways we could have addressed this: we could have
special-cased all socket options with non-integer types in ChannelOption,
but I believe that would be too manual, and risk limiting users that need
to set other socket options. We could also have added a ChannelOption
that simply allows users to pass a buffer to write into or read from,
but that is a very un-Swift-like API that feels pretty gross to hold.

Ultimately, the nicest seemed to be a new protocol users could check
for, and that would provide APIs that let users hold the correct concrete
type. As with setsockopt/getsockopt, while this API is typed it is
not type-safe: ultimately, the struct we have here is treated just as a
buffer by setsockopt/getsockopt. We do not attempt to prevent users from
shooting themselves in the foot here.

This PR does not include an example use case in any server, as I will
provide such an example in a subsequent multicast PR.

Modifications:

- Added a SocketOptionChannel protocol.
- Conformed BaseSocketChannel to SocketOptionChannel.
- Wrote some tests for this.

Result:

Users can set and get sockopts with data that is larger than a C int.
2018-09-18 13:40:38 +02:00
Johannes Weiss 501af860f5
allow two distinct ChannelOptions of one type (#597)
Motivation:

Quite embarrasingly, we previously would only store one `ChannelOption`
per `ChannelOption` type. Most channel option types are distinct and
that's probably why it took so long to find this issue. Thanks
@pushkarnk for reporting. Unfortunately though, the most important
`ChannelOption` is `.socket` which crucially also holds a level and a
name. That means if you set two `ChannelOptions.socket` options with
distinct name/level, one would still override the other.

Example:

    .serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEPORT), value: 1)
    .serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)

would only actually set the latter.

Modifications:

- made all common `ChannelOption` types equatable (for 2.0 this will
  be a protocol requirement)
- deprecated non-Equatable `ChannelOption` types
- zero out buffer before calling getsockopt as Linux doesn't do that

Result:

you can now set two distinct `ChannelOptions` for one type
2018-08-29 15:24:58 +01:00
fadi-botros 78729bd4ad Solving issue #410 (#414)
match all values in HTTPHeaders.isKeepAlive(...)

HTTPHeaders.isKeepAlive(...) does only match the first value.

### Motivation:

Keep-alive and Close may be something on comma separated arrays

### Modifications:

 - Made an extension function to `ByteBuffer` that could separate the strings at low level, without Swift string API, so that it could split the values
 - Another extension functions that compares the comma separated array with a given array to tell the caller which exists and which no
 - Added unit tests for them
 - Used them in the HTTPHeader

### Result:

- Now, if a request is sent using Keep-alive or Close where it was in an array, it will be handled
- fixes #410
2018-08-07 18:49:30 +01:00
Johannes Weiß 80363d9d8c fix EventLoops that Bootstrap channel initialiser's call out on (#424)
Motivation:

Previously we were not running the (child/server)channelInitializers on the
event loop associated to the `Channel` we're initialising. Almost all
operations in there are pipeline modifications which are thread safe so
it presumably wasn't a massive correctness issue. However it's very
expensive to hop threads that often and it is also very unexpected. This
addresses this issue.

Modifications:

made all (child/server)channelInitializers run on the event loop that is
associated to their `Channel`

Result:

- more correctness
- less unexpected behaviour
2018-05-22 15:58:43 +01:00
Johannes Weiß cea84765de Channel quiescing support (#399)
Motivation:

In certain cases it's useful to quiesce a channel instead of just
closing them immediately for example when receiving a signal.
This lays the groundwork by introducing the
`ChannelShouldQuiesceUserEvent` user event that when received can be
interpreted by a ChannelHandler in a protocol & application specific
way. Some protocols support tear down and that would be a good place to
initiate the tear down.

Modifications:

- introduce `ChannelShouldQuiesceUserEvent`
- handle `ChannelShouldQuiesceUserEvent` in the `AcceptHandler` with
  closing the server socket
- handle `ChannelShouldQuiesceUserEvent` in the
  `HTTPServerPipelineHandler` by only handling a already in-flight
  request and then no longer accepting input
- added `CircularBuffer.removeAll` (& tests)
- added tests for `nextPowerOf2()`

Result:

- handlers can now support quiescing
2018-05-18 10:48:18 +02:00
Cory Benfield 9326f749aa
Allow ChannelCore implementors to unwrap NIOAny. (#321)
Motivation:

When implementing a custom ChannelCore, you will probably need access
to the data inside a NIOAny. It should be possible to unwrap that.

Modifications:

Added an extension to ChannelCore to allow unwrapping a NIOAny.
Added @_versioned to almost all of NIOAny.

Result:

ChannelCore is implementable outside NIO
2018-04-18 10:04:12 +01:00
Cory Benfield bc6e3db537
Fix up HTTP message framing edge cases. (#298)
Motivation:

HTTP message framing has a number of edge cases that NIO currently does
not tolerate. We should decide what our position is on each of these edge
cases and handle it appropriately.

Modifications:

Provide an extensive test suite that codifies our expected handling of
these edge cases. Fix divergences from this behaviour.

Result:

Better tolerance for the weird corners of HTTP.
2018-04-12 15:12:39 +01:00
Cory Benfield 5b2ad2d921 Add support for automatic HTTP error reporting. (#268)
Motivation:

Currently the HTTP decoders can throw errors, but they will be ignored
and lead to a simple EOF. That's not ideal: in most cases we should make
a best-effort attempt to send a 4XX error code before we shut the client
down.

Modifications:

Provided a new ChannelHandler that generates 400 errors when the HTTP
decoder fails.
Added a flag to automatically add that handler to the channel pipeline.
Added the handler to the HTTP sample server.
Enabled integration test 12.

Result:

Easier error handling for HTTP servers.
2018-04-07 10:13:31 +02:00
Cory Benfield d6ade1424e
Forbid HTTP protocols other than 1. (#283)
Motivation:

Our HTTP code handles only HTTP/1.X. There is no reason to support
HTTP/0.9, and we cannot safely handle a major protocol higher than 1 in
this code, so we should simply treat requests/responses claiming to be
of those protocols as errors.

Modifications:

HTTPDecoder now checks the major version is equal to 1 before it
continues with parsing. If it hits an error, that error will be propagated
out to the user.

Result:

Better resilience against bad HTTP messages.
2018-04-06 11:26:32 +01:00
Norman Maurer b1f948a115
Set hints for getaddrinfo to restrict results (#221)
Motivation:

We only use our GetaddrinfoResolver for SocketChannels (TCP stream channels), so we should set some hints for getaddrinfo.

Modifications:

Set proto and socktype hints.

Result:

More correct usage of getaddrinfo. Fixes https://github.com/apple/swift-nio/issues/201.
2018-03-28 10:49:05 +02:00
Johannes Weiß c9c3974276 bring PriorityQueue/Heap implementations inline (#245)
Motivation:

We triggered extra allocations for the generics on PriorityQueue/Heap.
They unfortunately can't be solved using `@_specialize` as the element
type is `ScheduledTask`.
Fortunately we never exposed those types externally so we can just
inline without breaking the public API.

Modifications:

Moved everything from the `NIOPriorityQueue` module into the `NIO`
module.

Result:

Less allocations, more happiness.
2018-03-27 19:04:33 +02:00
Norman Maurer b8055f7467
Guard against the case when a Selectable is deregistered during Selector.whenReady(...) processing. (#210)
Motivation:

It's possible someone deregistered a Selectable while Selector.whenReady(...) is processed and an even for the now deregistered Selectable is ready. In this case we crashed (due a force-unwrap) on linux.

Modifications:

- Skip the processing of the Selectable if deregistered (by replacing force-unwrap with an if let).
- Add unit test.

Result:

No more crashes caused by this on Linux
2018-03-21 15:32:15 +01:00
Norman Maurer edfbe50fc8 Ensure we always update the promise before calling fire* methods and also udate channel state before. (#181)
Motivation:

We not always ensure correct ordering which made it quite hard to reason about things. We should always first notify the promise before we call the fire* method that belongs to the event. Beside this we sometimes fired events or notified promised before correctly update the active state / addresses of a Channel which could result in unexpected results when query the Channel during execution of callbacks and handlers.

Modifications:

- Ensure we always notify promise first
- Always correctly update channel state before notify promise
- Add test to verify notification order.

Result:

Correct ordering of events which makes things easier to reason about and which follows what netty is doing.
2018-03-19 20:52:31 +09:00
Norman Maurer 22d3439c4b
Add handler that provides some backoff for accepts if these failed because of an IOError. (#126)
Motivation:

Often accept errors are recoverable over time as for example you may just run out of file descriptors. Because of this it may be useful to just "delay" accepts a bit to recover.

Modifications:

Add ChannelHandler which will backoff accepts.

Result:

Be able to recover from accept errors gracefully.
2018-03-15 21:23:19 +01:00
Cory Benfield b542775605 Add initial websocket codec. (#109)
Motivation:

Websockets is a major protocol in use on the web today, and is
particularly valuable in applications that use asynchronous I/O
as it allows servers to keep connections open for long periods of
time for fully-duplex communication.

Users of NIO should be able to build websocket clients and servers
without too much difficulty.

Modifications:

Provided a WebsocketFrameEncoder and Decoder that can serialize and
deserialize Websocket frames.

Result:

Easier use of websockets.
2018-03-13 17:24:54 +01:00
Cory Benfield 860a7d40a3 Add channel handler for server side pipelining. (#62)
Motivation:

HTTP pipelining can be tricky to handle properly on the server side.
In particular, it's very easy to write out of order or inconsistently
mutate state. Users often need help to handle this appropriately.

Modifications:

Added a HTTPServerPipelineHandler that only lets one request through
at a time.

Result:

Better servers that are more able to handle HTTP pipelining
2018-03-13 15:21:12 +00:00
adamnemecek 0bbed6d72f * removed trailing whitespace (#52) 2018-03-02 15:40:52 +09: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
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
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
Johannes Weiß ebf351abda implement thread specific values 2018-02-08 17:37:01 +00: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
Cory Benfield ce7b0c52ce Add a CompositeError type 2018-02-08 13:12:30 +00:00
Johannes Weiss 755ea5aedc non-blocking file IO 2018-02-07 17:25:45 +00:00