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 :)
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.
* 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
Motivation:
To ensure we not leave any unread data on the socket we should try to read one last time (if autoread is enabled).
Modifications:
- Depending on if autoread is enabled or not we will try to read one more time
- Guard against re-entry of flushNow0()
- Correctly handle SIGPIPE in all cases
- Add testcase
Result:
Drain data from socket on write error if needed.
Motivation:
Explain here the context, and why you're making that change.
What is the problem you're trying to solve.
Modifications:
Describe the modifications you've done.
Result:
After your change, what will change.
Motivation:
Creating an IOError is not "cheap" as we use String formatting to do so. In cases of EWOULDBLOCK we will never use the IOError at the end so we should not even create one.
Modifications:
Handle EWOUDLBOCK without creating and IOError
Result:
Less overhead when a syscall will fail because it would block
Motivation:
Checking for blacklisted errno values should be an assert and not a precondition as this would signal a bug in our code itself and not something bad the user was doing. Also this will make the code smaller when compiling in release mode.
Modifications:
Change the blacklist check to be an assert.
Result:
Only check for blacklisted errno when asserts are enabled.
Motivation:
We had a few external dependencies that were mainly used to include header files.
Modifications:
Add extra modules that will be used to export these headers.
Result:
Less external dependencies.
* Move all syscalls that also need to handle errno in an extra file and ensure we not get any problems with invalid errno handling
Motivation:
Because it is possible ARC cause an syscall and so set the errno value we need to ensure no ARC can ever happen before we were able to read the errno value that was caused by an syscall we made.
Modifications:
Move all syscalls to an extra file (System.swift) and ensure all exposed methods are marked with `@inline(never)` and not capture any classes. This ensures no ARC can ever happen.
Result:
Be able to safely read errno if needed.
* Comments