Commit Graph

12 Commits

Author SHA1 Message Date
Cory Benfield ea5ba9bd25 Don't transition to .registered unless registration succeeds. (#19)
Motivation:

In some cases, such as when an event loop has been shutdown, channel
registration may fail. In these cases, we would incorrectly attempt to
deregister the channel, which would fail (and in debug builds, assert).
Really, we shouldn't transition into .registered until we know that we have,
in fact, registered.

However, we need to be cautious: we don't want to register unless we
believe we're in an acceptable state to register.

Modifications:

Updated the state enum to perform the registration at the correct
part of the state change function.

Result:

Harder to crash in debug mode
2019-01-08 21:40:57 +00:00
Cory Benfield fb5d37a1e1 Correctly hop across event loops during child channel setup. (#17)
Motivation:

We were inadvertently modifying the registration information of
NIOTSEventLoop objects from multiple threads, which is very not good.

Modifications:

Add an event loop execute to hop loops.

Result:

Thread safe!
2018-12-06 15:02:08 +00:00
Cory Benfield 1761d4eafa Make Channel.isActive thread-safe. (#16)
Motivation:

Sadly I overlooked the fact that Channel.isActive is supposed to be
safe to call from multiple threads: the implementation here was not.

Modifications:

Store the active state into an Atomic.

Result:

It will be thread-safe to ask if a channel is active.
2018-12-06 12:22:58 +00:00
Cory Benfield 5840333f0a Support opting-out of Network.framework waiting state. (#15)
Motivation:

In some cases users may prefer not to wait for Network.framework to
reattempt connection in the future. Users should be able to opt-out of the
default waiting behaviour in those cases.

Modifications:

- Added WaitForActivity ChannelOption.

Result:

Users can configure channels better.
2018-12-03 11:28:20 +00:00
Cory Benfield 73f758b5da Remove invalid assertion. (#13)
Motivation:

It is possible to receive the dataReceived callback after we've called
cancel, mostly because there may be such a block in place in the queue
before that cancel call fires. We should tolerate that.

Modifications:

Removed the invalid assertion.

Result:

Fewer failures.
2018-11-15 10:47:01 +00:00
Johannes Weiss 833b152a21 better diagnostics if unsupported ChannelOption set (#12)
Motivation:

If the user sets an unsupported ChannelOption we should give the best
diagnostics possible.

Modifications:

Add the ChannelOption type to the error message that it's unsupported.

Result:

Happier users
2018-11-09 17:15:35 +00:00
Cory Benfield a9cece8a6d
Support preconditionInEventLoop. (#11)
Motivation:

In SwiftNIO 1.11 we shipped improved interfaces for Channels to support
asserting being in the event loop. This is necessary because Dispatch
provides no non-precondition way to 100% guarantee that you are on a
specific queue, which is a requirement for accurate behaviour of
inEventLoop.

Modifications:

- Added an implementation of preconditionInEventLoop.
- Changed all assertions to use new interface.
- Required NIO 1.11.

Result:

Accurate assertions
2018-11-06 17:44:41 +00:00
Jim Dovey 9e8685be61 Fixes #8, and cleans some switch cases. (#9)
Motivation:

One bugfix, some cleanliness.

Modifications:

`NIOTSListenerChannel.doClose0()` now evaluates and updates `self.bindPromise` irrespective of whether `self.nwListener` had been set.

Also, some case statements could be better: I've swapped `case _ as Thing:` with `case is Thing:`, and I've inlined the `let` value from `case _ as Thing: let thing = x as! Thing` to simply be `case let x as Thing:`.

Result:

If the call to create the `NWListener` in `NIOTSListenerChannel.beginActivating0()` throws an error, any promise passed to that method will now correctly be updated, where before it would be silently ignored, potentially causing a waiting caller to wait forever.

Also, no case statements remain that might cause damage to my tooth enamel.
2018-10-16 10:29:47 +01:00
Jim Dovey e14a834008 Some cleanliness changes. (#7)
* Use DispatchWorkItem.cancel() for cancellation. Make StateManagedChannel.beginActivating() use the same methodology as all the others.

* A needless `if let x = opt` that could be replaced with a question mark.
2018-10-01 05:55:53 +01:00
Cory Benfield 897eb363f5 Handle errors during channel setup. (#2)
Motivation:

If an error is encountered early in the bootstrap process we should
probably not hit an assertion.

Modifications:

Added tests that we don't crash when closing idle channels.

Result:

Fewer crashes.
2018-08-08 19:15:33 +01:00
Cory Benfield 955d1b91e7
Add support for SO_REUSEADDR and SO_REUSEPORT. (#1)
Motivation:

These are commonly-set socket options for channels, and we should
support them when using Transport Services as well.

Modifications:

Pass the socket options through to allowLocalEndpointReuse.

Result:

SO_REUSEADDR and SO_REUSEPORT will be available.
2018-08-08 17:22:02 +01:00
Cory Benfield 6475881aea Initial commit 2018-07-18 17:11:24 +01:00