Motivation:
Some users are including NIO in Xcode workspaces
rather than using SPM. When this is done, if all
imports of CNIOLinux are conditional they can
remove this project from their workspace.
Modifications:
Make all imports of CNIOLinux conditional on Linux,
Android or FreeBSD
Result:
No user visible change.
Motivation:
The macOS build was broken by #1424, also the Thread.swift file became
a bit of a mess with `#if os(...)/#else` everywhere.
Modifications:
- fix macOS build
- cleanup Thread by splitting it into ThreadPosix & ThreadWindows
Result:
- build working again
- cleaner code
This restructures `Thread` to have a more generic representation of a
thread handle. Using that it is possible to have an implementation of
the threading APIs for Windows.
Similarly, introduce an abstraction over the Thread Specific Key. This
allows us to abstract away the key type and the usage.
Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
Motivation:
Certain issues are easier debugged if we can print the thread names.
Modifications:
- add the thread name to SelectableEventLoop's description
- make EventLoop and NIOThread CustomStringConvertible
Result:
easier debugging.
Motivation:
NIOThreadPool was grossly abusing Dispatch to block a large number of
threads for (usually) blocking IO work.
Modifications:
Back the NIOThreadPool by NIOThreads (pthreads) instead of
DispatchQueues.
Result:
Less abuse.
Motivation:
I noticed some closures were referred to by the wrong name in the
documentation.
Modifications:
Updated the documentation to use the correct names.
Result:
More correct documentation.
Motivation:
Previously we leaked `pthread_key`s as we only ever called
`pthread_key_create` but never `pthread_key_delete`. This patch fixes
that.
Modifications:
- made `ThreadSpecificVariable` a class (so we get lifecycle management
through ARC)
- instead of just storing the value, store `Box<(ThreadSpecificVariable<T>, T)>`
so we can control the lifecycle of the `ThreadSpecificVariable` as
needed
Result:
We don't leak `pthread_key`s anymore.
Motivation:
Collisions with Foundation and other standard libraries is painful.
Modifications:
- rename `FileHandle` to `NIOFileHandle`
- rename `Thread` to `NIOThread` (only exposed in docs)
Result:
fewer collisions
Motivation:
We have seen pthread_setname_np fail with EPERM in containers, it's
non-critical so best to ignore.
Modifications:
ignore pthread_setname_np's return code.
Result:
works in containers.
Motivation:
I came across a few typos and then went through the entire code base
fixing similar errors when I noticed a pattern.
Modifications:
No changes to the code, just to comments.
Result:
No changes.
Motivation:
As discussed with Andrew Trick on the Swift Forums, the additional call
to assumingMemoryBound(to:) is redundant here. Unmanaged.fromOpaque
takes a raw pointer, and p is just that.
See https://forums.swift.org/t/withunsafetypepunnedpointer/14540/9
for the discussion.
Modifications:
Deleted an unnecessary call to assumingMemoryBound(to:). With this
change, we follow the intended usage of Unmanaged more closely.
Result:
No material change. We save one redundant UnsafeRawPointer ->
UnsafePointer<ThreadBox> -> UnsafeRawPointer conversion.
fix some typos, force unwraps and inconsistencies
Motivation:
Reviewing the code I found a few typos that hindered readability, some unnecessary force unwraps and inconsistencies in the codebase.
Modifications:
- The main file in NIOWebSocketServer now accepts command line arguments
and binds to a passed in host and port like the other server examples do.
- Minor typo fixes
- removed one force unwrap
Result:
- The result of my change will bring the NIOWebSocketServer more inline
with how the NIOHTTP1 and NIOChat servers examples are setup.
- less force unwrapping
- fewer typos
[message edited by @weissi]
Motivation:
It's often useful for users to be able to store a thread-specific value (and so also EventLoop specific). We have ThreadSpecificVariable for this which was internal.
Modifications:
Change ThreadSpecificVariable to be public.
Result:
Fixes [#61].
Motivation:
Thread is declared final, so I believe spawnAndRun should be static.
Modifications:
Change class func to static
Result:
More consistent code, and spawnAndRun is statically dispatched.
Motivation:
Sometimes we deviated from the style the Swift stdlib sets out for no
reason.
Modifications:
Fixed some stylistic deviations.
Result:
Looks more Swift-like.
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.
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.
* Replace usage of Foundation.Thread with our own Thread that just used pthread
* Address comments
* some more docs / comments
* Address comments of cory