Compare commits
12 Commits
72e94c6ce9
...
d597722cca
| Author | SHA1 | Date |
|---|---|---|
|
|
d597722cca | |
|
|
c90c6432fd | |
|
|
08a31ceb2f | |
|
|
9e6e4ed7ab | |
|
|
7a8dcde582 | |
|
|
b37cc8bd40 | |
|
|
d61bf6d098 | |
|
|
f129546483 | |
|
|
fca19c5367 | |
|
|
1f354a871f | |
|
|
3d21b85af4 | |
|
|
9eb2ebde13 |
|
|
@ -14,6 +14,7 @@ jobs:
|
|||
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
|
||||
linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
|
||||
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
|
||||
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ jobs:
|
|||
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
|
||||
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
|
||||
linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
|
||||
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
|
||||
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ let strictConcurrencySettings: [SwiftSetting] = {
|
|||
if strictConcurrencyDevelopment {
|
||||
// -warnings-as-errors here is a workaround so that IDE-based development can
|
||||
// get tripped up on -require-explicit-sendable.
|
||||
initialSettings.append(.unsafeFlags(["-require-explicit-sendable", "-warnings-as-errors"]))
|
||||
initialSettings.append(.unsafeFlags(["-Xfrontend", "-require-explicit-sendable", "-warnings-as-errors"]))
|
||||
}
|
||||
|
||||
return initialSettings
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ internal final class NIOTSDatagramChannel: StateManagedNWConnectionChannel {
|
|||
internal var allowLocalEndpointReuse = false
|
||||
internal var multipathServiceType: NWParameters.MultipathServiceType = .disabled
|
||||
|
||||
private let nwParametersConfigurator: (@Sendable (NWParameters) -> Void)?
|
||||
internal let nwParametersConfigurator: (@Sendable (NWParameters) -> Void)?
|
||||
|
||||
var parameters: NWParameters {
|
||||
let parameters = NWParameters(dtls: self.tlsOptions, udp: self.udpOptions)
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ internal final class NIOTSConnectionChannel: StateManagedNWConnectionChannel {
|
|||
/// An `EventLoopPromise` that will be succeeded or failed when a connection attempt succeeds or fails.
|
||||
internal var connectPromise: EventLoopPromise<Void>?
|
||||
|
||||
private let nwParametersConfigurator: (@Sendable (NWParameters) -> Void)?
|
||||
internal let nwParametersConfigurator: (@Sendable (NWParameters) -> Void)?
|
||||
|
||||
internal var parameters: NWParameters {
|
||||
let parameters = NWParameters(tls: self.tlsOptions, tcp: self.tcpOptions)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import NIOCore
|
|||
public protocol NIOTSError: Error, Equatable {}
|
||||
|
||||
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
|
||||
public enum NIOTSErrors {
|
||||
public enum NIOTSErrors: Sendable {
|
||||
/// ``InvalidChannelStateTransition`` is thrown when a channel has been asked to do something
|
||||
/// that is incompatible with its current channel state: e.g. attempting to register an
|
||||
/// already registered channel.
|
||||
|
|
|
|||
|
|
@ -83,6 +83,8 @@ internal protocol StateManagedNWConnectionChannel: StateManagedChannel where Act
|
|||
|
||||
var multipathServiceType: NWParameters.MultipathServiceType { get }
|
||||
|
||||
var nwParametersConfigurator: (@Sendable (NWParameters) -> Void)? { get }
|
||||
|
||||
func setChannelSpecificOption0<Option: ChannelOption>(option: Option, value: Option.Value) throws
|
||||
|
||||
func getChannelSpecificOption0<Option: ChannelOption>(option: Option) throws -> Option.Value
|
||||
|
|
@ -242,6 +244,7 @@ extension StateManagedNWConnectionChannel {
|
|||
connection.betterPathUpdateHandler = self.betterPathHandler
|
||||
connection.viabilityUpdateHandler = self.viabilityUpdateHandler
|
||||
connection.pathUpdateHandler = self.pathChangedHandler(newPath:)
|
||||
self.nwParametersConfigurator?(connection.parameters)
|
||||
connection.start(queue: self.connectionQueue)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import XCTest
|
|||
import Network
|
||||
import NIOCore
|
||||
import NIOEmbedded
|
||||
import NIOTransportServices
|
||||
@testable import NIOTransportServices
|
||||
import NIOConcurrencyHelpers
|
||||
import Foundation
|
||||
|
||||
|
|
@ -372,34 +372,58 @@ final class NIOTSBootstrapTests: XCTestCase {
|
|||
XCTAssertEqual(try connectionChannel.getOption(NIOTSChannelOptions.multipathServiceType).wait(), .handover)
|
||||
}
|
||||
|
||||
func testNWParametersConfigurator() throws {
|
||||
let group = NIOTSEventLoopGroup()
|
||||
defer {
|
||||
try! group.syncShutdownGracefully()
|
||||
func testNWParametersConfigurator() async throws {
|
||||
final class WaitForConnectionHandler: ChannelInboundHandler, Sendable {
|
||||
typealias InboundIn = Never
|
||||
|
||||
let connectionPromise: EventLoopPromise<Void>
|
||||
|
||||
init(connectionPromise: EventLoopPromise<Void>) {
|
||||
self.connectionPromise = connectionPromise
|
||||
}
|
||||
|
||||
func channelActive(context: ChannelHandlerContext) {
|
||||
self.connectionPromise.succeed()
|
||||
}
|
||||
}
|
||||
|
||||
let group = NIOTSEventLoopGroup(loopCount: 1)
|
||||
|
||||
let configuratorListenerCounter = NIOLockedValueBox(0)
|
||||
let configuratorConnectionCounter = NIOLockedValueBox(0)
|
||||
let waitForConnectionHandler = WaitForConnectionHandler(
|
||||
connectionPromise: group.next().makePromise()
|
||||
)
|
||||
|
||||
let listenerChannel = try NIOTSListenerBootstrap(group: group)
|
||||
let listenerChannel = try await NIOTSListenerBootstrap(group: group)
|
||||
.childChannelInitializer { connectionChannel in
|
||||
connectionChannel.eventLoop.makeCompletedFuture {
|
||||
try connectionChannel.pipeline.syncOperations.addHandler(waitForConnectionHandler)
|
||||
}
|
||||
}
|
||||
.configureNWParameters { _ in
|
||||
configuratorListenerCounter.withLockedValue { $0 += 1 }
|
||||
}
|
||||
.bind(host: "localhost", port: 0)
|
||||
.wait()
|
||||
.get()
|
||||
|
||||
let connectionChannel: Channel = try NIOTSConnectionBootstrap(group: group)
|
||||
let connectionChannel: Channel = try await NIOTSConnectionBootstrap(group: group)
|
||||
.configureNWParameters { _ in
|
||||
configuratorConnectionCounter.withLockedValue { $0 += 1 }
|
||||
}
|
||||
.connect(to: listenerChannel.localAddress!)
|
||||
.wait()
|
||||
.get()
|
||||
|
||||
try listenerChannel.close().wait()
|
||||
try connectionChannel.close().wait()
|
||||
// Wait for the server to activate the connection channel to the client.
|
||||
try await waitForConnectionHandler.connectionPromise.futureResult.get()
|
||||
|
||||
XCTAssertEqual(1, configuratorListenerCounter.withLockedValue { $0 })
|
||||
try await listenerChannel.close().get()
|
||||
try await connectionChannel.close().get()
|
||||
|
||||
XCTAssertEqual(2, configuratorListenerCounter.withLockedValue { $0 })
|
||||
XCTAssertEqual(1, configuratorConnectionCounter.withLockedValue { $0 })
|
||||
|
||||
try await group.shutdownGracefully()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -233,34 +233,63 @@ final class NIOTSDatagramConnectionChannelTests: XCTestCase {
|
|||
XCTAssertNoThrow(try connection.close().wait())
|
||||
}
|
||||
|
||||
func testNWParametersConfigurator() throws {
|
||||
let group = NIOTSEventLoopGroup()
|
||||
defer {
|
||||
try! group.syncShutdownGracefully()
|
||||
func testNWParametersConfigurator() async throws {
|
||||
final class WaitForConnectionHandler: ChannelInboundHandler, Sendable {
|
||||
typealias InboundIn = Never
|
||||
|
||||
let connectionPromise: EventLoopPromise<Void>
|
||||
|
||||
init(connectionPromise: EventLoopPromise<Void>) {
|
||||
self.connectionPromise = connectionPromise
|
||||
}
|
||||
|
||||
func channelActive(context: ChannelHandlerContext) {
|
||||
self.connectionPromise.succeed()
|
||||
}
|
||||
}
|
||||
|
||||
let group = NIOTSEventLoopGroup(loopCount: 1)
|
||||
|
||||
let configuratorListenerCounter = NIOLockedValueBox(0)
|
||||
let configuratorConnectionCounter = NIOLockedValueBox(0)
|
||||
let waitForConnectionHandler = WaitForConnectionHandler(
|
||||
connectionPromise: group.next().makePromise()
|
||||
)
|
||||
|
||||
let listenerChannel = try NIOTSDatagramListenerBootstrap(group: group)
|
||||
let listenerChannel = try await NIOTSDatagramListenerBootstrap(group: group)
|
||||
.childChannelInitializer { connectionChannel in
|
||||
connectionChannel.eventLoop.makeCompletedFuture {
|
||||
try connectionChannel.pipeline.syncOperations.addHandler(waitForConnectionHandler)
|
||||
}
|
||||
}
|
||||
.configureNWParameters { _ in
|
||||
configuratorListenerCounter.withLockedValue { $0 += 1 }
|
||||
}
|
||||
.bind(host: "localhost", port: 0)
|
||||
.wait()
|
||||
.get()
|
||||
|
||||
let connectionChannel: Channel = try NIOTSDatagramBootstrap(group: group)
|
||||
let connectionChannel: Channel = try await NIOTSDatagramBootstrap(group: group)
|
||||
.configureNWParameters { _ in
|
||||
configuratorConnectionCounter.withLockedValue { $0 += 1 }
|
||||
}
|
||||
.connect(to: listenerChannel.localAddress!)
|
||||
.wait()
|
||||
.get()
|
||||
|
||||
try listenerChannel.close().wait()
|
||||
try connectionChannel.close().wait()
|
||||
// Need to write something so the server can activate the connection channel: this is UDP,
|
||||
// so there is no handshaking that happens and thus the server cannot know that the
|
||||
// connection has been established and the channel can be activated.
|
||||
try await connectionChannel.writeAndFlush(ByteBuffer(bytes: [42]))
|
||||
|
||||
XCTAssertEqual(1, configuratorListenerCounter.withLockedValue { $0 })
|
||||
// Wait for the server to activate the connection channel to the client.
|
||||
try await waitForConnectionHandler.connectionPromise.futureResult.get()
|
||||
|
||||
try await listenerChannel.close().get()
|
||||
try await connectionChannel.close().get()
|
||||
|
||||
XCTAssertEqual(2, configuratorListenerCounter.withLockedValue { $0 })
|
||||
XCTAssertEqual(1, configuratorConnectionCounter.withLockedValue { $0 })
|
||||
|
||||
try await group.shutdownGracefully()
|
||||
}
|
||||
|
||||
func testCanExtractTheConnection() throws {
|
||||
|
|
|
|||
Loading…
Reference in New Issue