Permalink
Commits on Nov 15, 2018
  1. ByteBuffer test: remove bogus test assertion (#655)

    weissi committed Nov 15, 2018
    Motivation:
    
    One ByteBuffer test was (for whatever reason) asserting that realloc
    never succeeds in realloc'ing from 16 to 32 bytes. That just failed on
    macOS, presumably an allocator change.
    
    Modifications:
    
    remove bogus assertion about reallocs ability to grow allocations.
    
    Result:
    
    tests more stable
  2. Make the member variables of HTTPHeader and HTTPHeaderIndex visible t…

    AlanQuatermain authored and weissi committed Nov 15, 2018
    …o swift-nio-http2. (#654)
Commits on Nov 13, 2018
  1. connect timeout tests: work around ECONNREFUSED (#653)

    weissi committed Nov 13, 2018
    Motivation:
    
    Some network configurations might disallow connecting to unknown IP
    addresses. The effect of that is that we might see `ECONNREFUSED` when
    trying to connect to 198.51.100.254 which nominally is reserved for
    documentation only (ie. we shouldn't get any RSTs).
    
    Modifications:
    
    ignore `ECONNREFUSED` in the timeout tests too
    
    Result:
    
    tests stable in less permissive network environments
  2. remove ugly and unnecessary ignore result (_ = ...) (#652)

    weissi committed Nov 13, 2018
    Motivation:
    
    _ = expression() is ugly and in many cases unimportant. In fact we train
    ourselves to overread it which makes special cases where you'd actually
    expect a result to be used just look normal.
    
    Modifications:
    
    remove _ = from a lot of places. In many cases we already had a better
    (and sometimes cheaper way) to not return a value but in some cases
    (mostly `remove` functions) I added `@discardableResult`
    
    Result:
    
    NIO source code looks nicer
Commits on Nov 7, 2018
  1. Provide ChannelPipeline.remove methods with promises. (#651)

    Lukasa committed Nov 7, 2018
    Motivation:
    
    ChannelPipeline.remove0 contains a comment that indicates that users
    were expected to be able to use the ChannelHandlerContext when both
    handlerRemoved and the promise for channel removal call out.
    
    This works when invoking remove() from outside the event loop, but if
    a handler invokes remove on itself then it will only be able to attach
    a callback to the future *after* the callout occurs. This means that a
    ChannelHandler removing itself from the pipeline cannot rely on there
    being a moment when it can still invoke the ChannelHandlerContext, but
    when it is no longer a formal part of the pipeline.
    
    This kind of behaviour is useful in some unusual cases, and it would
    be nice to support it.
    
    Modifications:
    
    - Added remove() methods that accept promises as input.
    - Rewrote the current remove() methods in terms of the new ones.
    - Added tests.
    
    Result:
    
    ChannelHandlers can perform cleanup with a valid ChannelHandlerContext
    but outside the Channel.
Commits on Nov 5, 2018
  1. EventLoop.assertInEventLoop and preconditionInEventLoop (#644)

    weissi authored and Lukasa committed Nov 5, 2018
    Motivation:
    
    Dispatch can only precondition that code is run from a certain queue, it
    can't return if code is running on a certain queue.
    To support that this introduces new EventLoop.assertInEventLoop and
    EventLoop.preconditionInEventLoop methods instead of
    assert(eventLoop.inEventLoop).
    
    Modifications:
    
    add EventLoop.assertInEventLoop and EventLoop.preconditionInEventLoop
    
    Result:
    
    better support for Network.framework in NIOTS
Commits on Nov 1, 2018
  1. fix Swift 5 warnings (mostly redundant modifiers (#642)

    weissi authored and Lukasa committed Nov 1, 2018
    Motivation:
    
    Swift 5 complains on redundant modifiers. For example declaring a
    `public func` inside of a `public extension` is now a warning. I don't
    agree with this but I dislike warnings even more, so...
    
    Modifications:
    
    remove all redundant modifiers that the compiler now warns about such as
    
        swift-nio/Sources/NIOPriorityQueue/PriorityQueue.swift:90:5: warning: 'public' modifier is redundant for property declared in a public extension
    
    Result:
    
    no warnings in Swift 5
Commits on Oct 31, 2018
  1. add String blitting benchmarks (#641)

    weissi committed Oct 31, 2018
    Motivation:
    
    Writing Strings to ByteBuffers is important, let's have some more
    benchmarks.
    
    Modifications:
    
    add String to ByteBuffer benchmarks
    
    Result:
    
    more benchmarks
Commits on Oct 30, 2018
  1. ByteBuffer: small & medium sized string copies over 10% faster (#640)

    weissi authored and Lukasa committed Oct 30, 2018
    Motivation:
    
    urbp[start ..< end] is quite a bit faster than when done in two
    operations urbp.dropFirst(start).prefix(length). This improves small (4
    bytes) & medium sized (24 bytes) String copies by over 10%. Good for
    HTTP headers etc.
    
    Modifications:
    
    replace urbp.dropFirst(start).prefix(length) by urbp[start ..< start +
    length]
    
    Result:
    
    small & medium sized String copies faster
  2. String decoding: go through URBP directly instead of Slice (#639)

    weissi authored and Lukasa committed Oct 30, 2018
    Motivation:
    
    String decoding can work faster when going through URBP directly instead
    of a Slice of a URBP. The reason is that if the String has the utf8
    represenation stored directly it'll just be a memcpy (+ validation).
    
    Modifications:
    
    go through URBP when decoding a String using String(decoding:as:)
    
    Result:
    
    faster if the String utf8 representation happens to be available
  3. CONNECT method should not have request body (#637)

    norio-nomura authored and weissi committed Oct 30, 2018
    * CONNECT method has no request body
    
    ### Motivation:
    
    [rfc7231](https://tools.ietf.org/html/rfc7231#section-4.3.6) said:
    > A payload within a `CONNECT` request message has no defined semantics;
       sending a payload body on a `CONNECT` request might cause some existing
       implementations to reject the request.
    
    ### Modifications:
    
    Change `HTTPMethod.CONNECT.hasRequestBody` to returns `.no`.
    
    ### Result:
    
    `HTTPRequestEncoder` does not generate chunked body for `CONNECT` method.
    
    * Change `HTTPMethod.CONNECT.hasRequestBody` to returns `.unlikely`
Commits on Oct 29, 2018
  1. verify that IOThreadPools get shut down (#635)

    weissi authored and Lukasa committed Oct 29, 2018
    Motivation:
    
    Not shutting down IOThreadPools leads to thread leaks so we should
    verify they're actually shut down.
    
    Modifications:
    
    add a check that we're shutting down
    
    Result:
    
    fewer thread leaks
Commits on Oct 19, 2018
  1. fix potential deadlock in BlockingIOThreadPool (#634)

    weissi committed Oct 19, 2018
    Motivation:
    
    BlockingIOThreadPool used to call out with a lock held and on top of
    that on the wrong thread...
    
    Modifications:
    
    Make BlockingIOThreadPool call out on the supplied `queue`
    
    Result:
    
    fewer deadlock and surprises
  2. use umbrella headers for C modules (#636)

    weissi authored and Lukasa committed Oct 19, 2018
    Motivation:
    
    SwiftPM only generates fully usable clang modules for C modules if they
    have umbrella headers. Therefore, adding a generated NIO.xcodeproj to
    another Xcode project as a sub-project never worked.
    To make a header an umbrella header you need to name them _exactly_ like
    the module.
    
    Modifications:
    
    give each C module an umbrella header
    
    Result:
    
    generated NIO Xcode projects can be used as sub-projects.
Commits on Oct 16, 2018
  1. update http_parser.c (#627)

    weissi authored and Lukasa committed Oct 16, 2018
    Motivation:
    
    There was an outstanding change in http_parser.c that we did not yet
    have in our copy.
    
    Modifications:
    
    run the update http parser script and add changes as well as a test case
    designed to hit the change.
    
    Result:
    
    ship the latest and greatest
Commits on Sep 30, 2018
  1. Fix minor typo (#626)

    gps authored and Lukasa committed Sep 30, 2018
Commits on Sep 28, 2018
  1. Rest between runs of tests that join multicast groups. (#625)

    Lukasa authored and normanmaurer committed Sep 28, 2018
    Motivation:
    
    On some machines we've seen tests that rapidly join and leave multicast groups
    hitting spurious test failures. These test failures manifest as hitting ENOMEM on
    setsockopt(IP_ADD_MEMBERSHIP). The reason appears to be that the IGMP join/leave
    messages that the kernel needs to emit for these joins can be queued up waiting for
    a timer to fire, and if we move sufficiently quickly we can push too many
    messages into that queue.
    
    This can be avoided by avoiding the need to emit the IGMP join/leave messages
    at all. We can do that by forcing the multicast joins onto the loopback interface,
    as there's no value in the kernel emitting join/leaves on the loopback. Given that
    for these tests the join is necessary only to get the kernel to have IGMP state,
    there's no reason not to do this.
    
    Modifications:
    
    Forced all multicast joins onto the loopback address.
    
    Result:
    
    No weird ENOMEM crashes in test runs.
Commits on Sep 27, 2018
  1. add Android support (#609)

    albertaleksieiev authored and weissi committed Sep 27, 2018
    ### Motivation:
    
    make swift-nio compatible with Android, and pass all test in Android.
    
    ### Modifications:
    
    * add missed `ifaddrs` implementation
    * add missed thread related functions - `CNIOLinux_pthread_getname_np`, `CNIOLinux_pthread_setaffinity_np` and `CNIOLinux_pthread_getaffinity_np`
    * fix types incositency between Linux and Android, e.g. `Epoll.swift` class
    * make bytes counter explicitely 64bits to avoid overflow on 32bit, in `PendingWritesManager.swift` and `PendingDatagramWritesState.swift`
    * fix issue with Unix domain socket, first byte need to be zero in Android
    * several incosistency fixes between Linux and Android api.
    
    ### Result:
    
    now swift-nio works on Android. All tests passed!
Commits on Sep 25, 2018
  1. Work around SE-0213 (#623)

    Lukasa committed Sep 25, 2018
    Motivation:
    
    In Swift 5, types that conform to ExpressibleByIntegerLiteral will now
    have their init(integerLiteral:) initializer invoked whenever the
    compiler sees code of the form `Type(integerLiteral)`, rather than
    before where the integer literal would be created as `Int` and then
    an alternative initializer would be called. This broke our tests, so
    we should fix it now that we're aware of it.
    
    Modifications:
    
    Force the type of the argument for the one broken test line, add new
    test lines that execute this code path.
    
    Result:
    
    Better testing, fewer compile errors.
Commits on Sep 24, 2018
  1. Support UDP multicast. (#618)

    Lukasa committed Sep 24, 2018
    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.
Commits on Sep 20, 2018
  1. make the allocation limits for Swift 4.2 the main ones (#621)

    weissi authored and Lukasa committed Sep 20, 2018
    Motivation:
    
    We always care most about the latest released Swift version. Therefore I
    added allocation limits for Swift 4.2 and indicated that the old ones
    can be removed as soon as they change.
    
    Modifications:
    
    - added allocation limits for Swift 4.2
    - added a comment to the old ones that they don't need to be changed
      anymore now
    
    Result:
    
    - best support for best version
    - document that Swift 4.2 is awesome, lots fewer allocations!
Commits on Sep 19, 2018
  1. explain some force tries/unwraps (#619)

    weissi authored and Lukasa committed Sep 19, 2018
    Motivation:
    
    It's generally good style to explain why something needs to be force
    unwrapped/tried if not obvious.
    
    Modifications:
    
    Add explanations to a bunch of places.
    
    Result:
    
    Code easier to understand.
Commits on Sep 18, 2018
  1. CI: use Swift 4.2-RELEASE instead of CONVERGENCE (#616)

    weissi authored and Lukasa committed Sep 18, 2018
    Motivation:
    
    Now that 4.2 has been released, there's no reason to use the CONVERGENCE
    version anymore.
    
    Modifications:
    
    use the RELEASE instead of the CONVERGENCE version of Swift 4.2
    
    Result:
    
    use the latest and greatest
  2. Add SocketOptionChannel for wider socket options. (#589)

    Lukasa authored and weissi committed Sep 18, 2018
    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.
Commits on Sep 14, 2018
  1. Added some unit tests to MarkedCircularBuffer (#607)

    MarkusJais authored and normanmaurer committed Sep 14, 2018
    Motivation:
    
    MarkedCircularBuffer was missing unit tests for some methods and
    public attributes
    
    Modifications:
    
    Added several unit tests
    
    Result:
    
    Now MarkedCircularBuffer has better test coverage
Commits on Sep 13, 2018
  1. Correct propagate channelActive events to the next handler when using… (

    normanmaurer authored and Lukasa committed Sep 13, 2018
    #615)
    
    * Correct propagate channelActive events to the next handler when using IdleStateHandler.
    
    Motivation:
    
    We missed to propagate the channelActive event to the next handler in IdleStateHandler, which means handlers placed after it in the pipeline will never receive such an event.
    
    Modifications:
    
    - Correctly call ctx.fireChannelActive()
    - Add unit test to assert we forward all inbound events.
    
    Result:
    
    Fixes #614.
Commits on Sep 12, 2018
  1. document the prerequisites (#613)

    weissi authored and Lukasa committed Sep 12, 2018
    Motivation:
    
    We should document the system requirements.
    
    Modifications:
    
    Add list of prerequisites to readme.
    
    Result:
    
    Easier to get started for users.
Commits on Sep 11, 2018
  1. EventLoopPromise didn't point out it has reference semantics (#612)

    weissi committed Sep 11, 2018
    Motivation:
    
    Sometimes people assume that all `struct`s have value semantics but
    that's not true. We should still point that out.
    
    Modifications:
    
    point out that EventLoopPromise has reference semantics
    
    Result:
    
    clearer docs
  2. allow more time to close fds in integration tests (#611)

    weissi authored and Lukasa committed Sep 11, 2018
    Motivation:
    
    As #563 shows, sometimes in CI we don't reach the number of open
    expected file descriptors. The current assumption is that this is just a
    race when CI is slow. This allows up to 10s to reach the correct number
    of open file descriptors.
    
    Modifications:
    
    - allow up to 10s to reach the correct number of fds
    
    Result:
    
    hopefully fixing #563 finally
Commits on Sep 10, 2018
  1. Actually report errors when hitting blacklisted errnos. (#610)

    Lukasa authored and weissi committed Sep 10, 2018
    Motivation:
    
    It's not all that useful to print the value of the pointer from sterror.
    Instead we should aim to print the string. While we're here, let's avoid
    repeating too much code.
    
    Modifications:
    
    - Centralised the handling of blacklisted errnos.
    - Correctly printed the error string when a blacklisted errno is hit.
    - Updated the output of the assertion to include the function failing.
    
    Result:
    
    Better diagnostics when blacklisted errnos are hit.
Commits on Sep 7, 2018
  1. add Ubuntu 18.04 and Swift 4.2 support (#604)

    weissi authored and tomerd committed Sep 7, 2018
    Motivation:
    
    We should support the latest and greatest.
    
    Modifications:
    
    - add Ubuntu 18.04 support (packages exist for Swift 4.2 only)
    - add Swift 4.2 support (for Ubuntu 14.04, 16.04 and 18.04)
    
    Result:
    
    - supporting the latest stuff
Commits on Sep 3, 2018
  1. fix warning in a test (#605)

    weissi authored and normanmaurer committed Sep 3, 2018
    Motivation:
    
    nobody likes warnings, even in tests
    
    Modifications:
    
    fixed a test warning
    
    Result:
    
    no more warnings (apart from the deprecation ones)
Commits on Aug 30, 2018
  1. Cleanup of bf8c642

    normanmaurer committed Aug 30, 2018
  2. Include ipaddress in SocketAddress.description. (#601)

    normanmaurer committed Aug 30, 2018
    Motivation:
    
    WE should include the ipaddress in the description of SocketAddress if any way used as there may be no host at all.
    
    Modifications:
    
    - Always include ipaddress if possible.
    - Add unit tests.
    
    Result:
    
    More useful description of the SocketAddress
Commits on Aug 29, 2018
  1. allow two distinct ChannelOptions of one type (#597)

    weissi committed Aug 29, 2018
    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