Commit Graph
7 Commits
Author SHA1 Message Date
Joakim Hassila 9a224ae35f Add custom cleanup hook to allow PipeChannel to properly deregister during halfclose (#1793)
Allow PipeChannel to perform custom cleanup to drop references to fds.

Motivation:

Currently PipeChannel doesn't properly deregister from the selector during half-closes.
This means that some backend implementations will keep a reference on the kernel side
which means that the POLLHUP will not be delivered for the read end of a pipe in
e.g. NIOTests.StreamChannelTest/testHalfCloseOwnOutput - this has the test failing
in #1761 / #1788.

Modification:

Add a generic cleanup hook to allow PipeChannel
to properly deregister.

Result:

The final reference to the fd is dropped resulting in a POLLHUP being delivered
as needed - making NIOTests.StreamChannelTest/testHalfCloseOwnOutput to pass
for io_uring.
2021-04-07 16:08:12 +01:00
George Barnett b4483e5c49 Avoid curried thunks (workaround SR-12115) (#1374)
Motivation:

Calling `function(otherFunction)` allocates, but
`function({ otherFunction($0) }` does not.

See: SR-12115 and SR-12116.

Modifications:

Avoid passing functions directly; pass them in new closures instead.

Result:

Fewer allocations.
2020-01-31 17:57:30 +00:00
Johannes Weiss 45bca5672c improve flushNow re-entrancy protection (#1348)
improve flushNow re-entrancy protection

Motivation:

The fix in #1344 wasn't complete, there is another, quite complicated scenario where we would still forget to send flushed bytes until we see another `flush` call. The scenario is

         1: writable()
         2: --> flushNow (result: .writtenCompletely)
         3:     --> writabilityChanged callout
         4:         --> flushNow because user calls writeAndFlush (result: .couldNotWriteEverything)
         5:         --> registerForWritable (because line 4 could not write everything and flushNow returned .register)
         6: --> unregisterForWritable (because line 2 wrote everything and flushNow returned .unregister)

Line 6 undoes the registeration in line 5.

Modification:

This fix makes sure that flushNow never re-enters and therefore the problem described above cannot happen anymore.

Result:

Hopefully actually fixes rdar://58571521
2020-01-22 12:08:15 +00:00
Johannes Weiss ca0ed86766 flushes from channelWritabilityChanged callbacks get lost (#1344) 2020-01-18 09:05:37 +00:00
Johannes Weiss 74944a937d use Optional<T> instead of T? to workaround SR-11777 (#1252)
Motivation:

In Swift, writing

    var something: T?

    init() {
        self.something = someValue
    }

means that the compiler will first set `self.something` to `nil` and
then in the init override it with `self.someValue`
(https://bugs.swift.org/browse/SR-11777). Unfortunately, because of
https://bugs.swift.org/browse/SR-11768 , stored property initialisation
cannot be made `@inlinable` (short of using `@frozen` which isn't
available in Swift 5.0).

The combination of SR-11768 and SR-11777 leads to `var something: T?`
having much worse code than `var something: Optional<T>` iff the `init`
is `public` and `@inlinable`.

Modifications:

Change all `var something: T?` to `var something: Optional<T>`

Result:

Faster code, sad NIO developers.
2019-11-27 18:37:38 +00:00
Jake 58001dac80 namespace ChannelOptions types (#1148) (#1176)
Motivation:

ChannelOptions types like WriteBufferWaterMarkOption are global, public types. These types should be namespaced.

Modifications:

Moved global, public ChannelOptions types into ChannelOptions.Types enum. Created global, public typealiases with deprecation attributes which point to the namespaced types. Switched usage of these types in the codebase to use the namespaced versions.

Result:

Usage of the global, public versions of these types will cause deprecation warnings.
2019-10-22 12:32:45 -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