Change naming of datagram-related types to make them more consistent + fix docs (#233)

### Motivation:

The datagram-related types logically mirror the TCP-based ones
(`NIOTSDatagramListenerBootstrap` vs `NIOTSListenerBootstrap`;
`NIOTSListenerChannel` vs `NIOTSDatagramListenerChannel`;
`NIOTSDatagramChannel` vs `NIOTSDatagramConnectionChannel`;
`NIOTSDatagramBootstrap` vs `NIOTSConnectionBootstrap`).
However, some of the type names could more closely resemble their TCP
counterparts to make it easier to navigate the code/understand what
their purpose is.
Additionally, the docs for some of these types are wrong, as they've
been copy-pasted into the datagram versions without changes.

### Modifications:

There are separate commits for each of the following changes:
- Fix docs for `NIOTSDatagramListenerBootstrap` and rename the file to
match the type name.
- Rename `NIOTSDatagramConnectionChannelTests` to
`NIOTSDatagramBootstrapTests` (to match `NIOTSBootstrapTests`).
- Rename `NIOTSDatagramChannel` to `NIOTSDatagramConnectionChannel` (to
match `NIOTSConnectionChannel`)
- Fix docs for `NIOTSConnectionBootstrap`.
- Rename `NIOTSDatagramBootstrap` to `NIOTSDatagramConnectionBootstrap`
(to match `NIOTSConnectionBootstrap`). This one required a deprecate and
replace since it's a public type.

### Result:

Better docs and more consistency in our type names.
This commit is contained in:
Gus Cairo 2025-04-29 13:56:21 +01:00 committed by GitHub
parent cd1e89816d
commit d8443227d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 104 additions and 105 deletions

View File

@ -17,9 +17,13 @@ import NIOCore
import Dispatch
import Network
/// A `NIOTSDatagramBootstrap` is an easy way to bootstrap a `NIOTSDatagramChannel` when creating network clients.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
public typealias NIOTSDatagramBootstrap = NIOTSDatagramConnectionBootstrap
/// A ``NIOTSDatagramConnectionBootstrap`` is an easy way to bootstrap a UDP channel when creating network clients.
///
/// Usually you re-use a `NIOTSDatagramBootstrap` once you set it up, calling `connect` multiple times on the same bootstrap.
/// Usually you re-use a ``NIOTSDatagramConnectionBootstrap`` once you set it up, calling `connect` multiple times on the
/// same bootstrap.
/// This way you ensure that the same `EventLoop`s will be shared across all your connections.
///
/// Example:
@ -29,7 +33,7 @@ import Network
/// defer {
/// try! group.syncShutdownGracefully()
/// }
/// let bootstrap = NIOTSDatagramBootstrap(group: group)
/// let bootstrap = NIOTSDatagramConnectionBootstrap(group: group)
/// .channelInitializer { channel in
/// channel.pipeline.addHandler(MyChannelHandler())
/// }
@ -37,9 +41,9 @@ import Network
/// /* the Channel is now connected */
/// ```
///
/// The connected `NIOTSDatagramChannel` will operate on `ByteBuffer` as inbound and outbound messages.
/// The connected channel will operate on `ByteBuffer` as inbound and outbound messages.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
public final class NIOTSDatagramBootstrap {
public final class NIOTSDatagramConnectionBootstrap {
private let group: EventLoopGroup
private var channelInitializer: (@Sendable (Channel) -> EventLoopFuture<Void>)?
private var connectTimeout: TimeAmount = TimeAmount.seconds(10)
@ -73,7 +77,7 @@ public final class NIOTSDatagramBootstrap {
self.init(group: group as EventLoopGroup)
}
/// Initialize the connected `NIOTSDatagramConnectionChannel` with `initializer`. The most common task in initializer is to add
/// Initialize the connected channel with `initializer`. The most common task in initializer is to add
/// `ChannelHandler`s to the `ChannelPipeline`.
///
/// The connected `Channel` will operate on `ByteBuffer` as inbound and outbound messages.
@ -86,7 +90,7 @@ public final class NIOTSDatagramBootstrap {
return self
}
/// Specifies a `ChannelOption` to be applied to the `NIOTSDatagramConnectionChannel`.
/// Specifies a `ChannelOption` to be applied to the channel.
///
/// - parameters:
/// - option: The option to be applied.
@ -193,7 +197,7 @@ public final class NIOTSDatagramBootstrap {
private func connect0(
_ binder: @Sendable @escaping (Channel, EventLoopPromise<Void>) -> Void
) -> EventLoopFuture<Channel> {
let conn: Channel = NIOTSDatagramChannel(
let conn: Channel = NIOTSDatagramConnectionChannel(
eventLoop: self.group.next() as! NIOTSEventLoop,
qos: self.qos,
udpOptions: self.udpOptions,
@ -229,5 +233,5 @@ public final class NIOTSDatagramBootstrap {
}
@available(*, unavailable)
extension NIOTSDatagramBootstrap: Sendable {}
extension NIOTSDatagramConnectionBootstrap: Sendable {}
#endif

View File

@ -24,7 +24,7 @@ import Network
import Security
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
internal final class NIOTSDatagramChannel: StateManagedNWConnectionChannel {
internal final class NIOTSDatagramConnectionChannel: StateManagedNWConnectionChannel {
typealias ActiveSubstate = UDPSubstate
enum UDPSubstate: NWConnectionSubstate {
@ -34,11 +34,11 @@ internal final class NIOTSDatagramChannel: StateManagedNWConnectionChannel {
self = .open
}
static func closeInput(state: inout ChannelState<NIOTSDatagramChannel.UDPSubstate>) throws {
static func closeInput(state: inout ChannelState<NIOTSDatagramConnectionChannel.UDPSubstate>) throws {
throw NIOTSErrors.InvalidChannelStateTransition()
}
static func closeOutput(state: inout ChannelState<NIOTSDatagramChannel.UDPSubstate>) throws {
static func closeOutput(state: inout ChannelState<NIOTSDatagramConnectionChannel.UDPSubstate>) throws {
throw NIOTSErrors.InvalidChannelStateTransition()
}
}
@ -230,11 +230,11 @@ internal final class NIOTSDatagramChannel: StateManagedNWConnectionChannel {
}
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSDatagramChannel {
extension NIOTSDatagramConnectionChannel {
internal struct SynchronousOptions: NIOSynchronousChannelOptions {
private let channel: NIOTSDatagramChannel
private let channel: NIOTSDatagramConnectionChannel
fileprivate init(channel: NIOTSDatagramChannel) {
fileprivate init(channel: NIOTSDatagramConnectionChannel) {
self.channel = channel
}
@ -253,5 +253,5 @@ extension NIOTSDatagramChannel {
}
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
extension NIOTSDatagramChannel: @unchecked Sendable {}
extension NIOTSDatagramConnectionChannel: @unchecked Sendable {}
#endif

View File

@ -17,7 +17,7 @@ import NIOCore
import Dispatch
import Network
/// A ``NIOTSListenerBootstrap`` is an easy way to bootstrap a `NIOTSListenerChannel` when creating network servers.
/// A ``NIOTSDatagramListenerBootstrap`` is an easy way to bootstrap a listener channel when creating network servers.
///
/// Example:
///
@ -26,7 +26,7 @@ import Network
/// defer {
/// try! group.syncShutdownGracefully()
/// }
/// let bootstrap = NIOTSListenerBootstrap(group: group)
/// let bootstrap = NIOTSDatagramListenerBootstrap(group: group)
/// // Specify backlog and enable SO_REUSEADDR for the server itself
/// .serverChannelOption(ChannelOptions.backlog, value: 256)
/// .serverChannelOption(ChannelOptions.socketOption(.reuseaddr), value: 1)
@ -46,13 +46,12 @@ import Network
/// try! channel.closeFuture.wait() // wait forever as we never close the Channel
/// ```
///
/// The `EventLoopFuture` returned by `bind` will fire with a `NIOTSListenerChannel`. This is the channel that owns the
/// listening socket. Each time it accepts a new connection it will fire a `NIOTSConnectionChannel` through the
/// `ChannelPipeline` via `fireChannelRead`: as a result, the `NIOTSListenerChannel` operates on `Channel`s as inbound
/// messages. Outbound messages are not supported on a `NIOTSListenerChannel` which means that each write attempt will
/// fail.
/// The `EventLoopFuture` returned by `bind` will fire with a channel. This is the channel that owns the listening socket. Each
/// time it accepts a new connection it will fire a new child channel for the new connection through the `ChannelPipeline` via
/// `fireChannelRead`: as a result, the listening channel operates on `Channel`s as inbound messages. Outbound messages are
/// not supported on these listening channels, which means that each write attempt will fail.
///
/// Accepted `NIOTSConnectionChannel`s operate on `ByteBuffer` as inbound data, and `IOData` as outbound data.
/// Accepted channels operate on `ByteBuffer` as inbound data, and `IOData` as outbound data.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
public final class NIOTSDatagramListenerBootstrap {
private let group: EventLoopGroup
@ -71,7 +70,7 @@ public final class NIOTSDatagramListenerBootstrap {
private var nwParametersConfigurator: (@Sendable (NWParameters) -> Void)?
private var childNWParametersConfigurator: (@Sendable (NWParameters) -> Void)?
/// Create a ``NIOTSListenerBootstrap`` for the `EventLoopGroup` `group`.
/// Create a ``NIOTSDatagramListenerBootstrap`` for the `EventLoopGroup` `group`.
///
/// This initializer only exists to be more in-line with the NIO core bootstraps, in that they
/// may be constructed with an `EventLoopGroup` and by extension an `EventLoop`. As such an
@ -82,20 +81,20 @@ public final class NIOTSDatagramListenerBootstrap {
/// > Note: The "real" solution is described in https://github.com/apple/swift-nio/issues/674.
///
/// - parameters:
/// - group: The `EventLoopGroup` to use for the `NIOTSListenerChannel`.
/// - group: The `EventLoopGroup` to use for the listening channel.
public convenience init(group: EventLoopGroup) {
self.init(group: group, childGroup: group)
}
/// Create a ``NIOTSListenerBootstrap`` for the ``NIOTSEventLoopGroup`` `group`.
/// Create a ``NIOTSDatagramListenerBootstrap`` for the ``NIOTSEventLoopGroup`` `group`.
///
/// - parameters:
/// - group: The ``NIOTSEventLoopGroup`` to use for the `NIOTSListenerChannel`.
/// - group: The ``NIOTSEventLoopGroup`` to use for the listening channel.
public convenience init(group: NIOTSEventLoopGroup) {
self.init(group: group as EventLoopGroup)
}
/// Create a ``NIOTSListenerBootstrap``.
/// Create a ``NIOTSDatagramListenerBootstrap``.
///
/// This initializer only exists to be more in-line with the NIO core bootstraps, in that they
/// may be constructed with an `EventLoopGroup` and by extension an `EventLoop`. As such an
@ -106,9 +105,8 @@ public final class NIOTSDatagramListenerBootstrap {
/// > Note: The "real" solution is described in https://github.com/apple/swift-nio/issues/674.
///
/// - parameters:
/// - group: The `EventLoopGroup` to use for the `bind` of the `NIOTSListenerChannel`
/// and to accept new `NIOTSConnectionChannel`s with.
/// - childGroup: The `EventLoopGroup` to run the accepted `NIOTSConnectionChannel`s on.
/// - group: The `EventLoopGroup` to use for the `bind` of the listening channel and to accept new child channels with.
/// - childGroup: The `EventLoopGroup` to run the accepted child channels on.
public convenience init(group: EventLoopGroup, childGroup: EventLoopGroup) {
guard NIOTSBootstraps.isCompatible(group: group) && NIOTSBootstraps.isCompatible(group: childGroup) else {
preconditionFailure(
@ -121,13 +119,12 @@ public final class NIOTSDatagramListenerBootstrap {
self.init(validatingGroup: group, childGroup: childGroup)!
}
/// Create a ``NIOTSListenerBootstrap`` on the `EventLoopGroup` `group` which accepts `Channel`s on `childGroup`,
/// validating that the `EventLoopGroup`s are compatible with ``NIOTSListenerBootstrap``.
/// Create a ``NIOTSDatagramListenerBootstrap`` on the `EventLoopGroup` `group` which accepts `Channel`s
/// on `childGroup`, validating that the `EventLoopGroup`s are compatible with ``NIOTSDatagramListenerBootstrap``.
///
/// - parameters:
/// - group: The `EventLoopGroup` to use for the `bind` of the `NIOTSListenerChannel`
/// and to accept new `NIOTSConnectionChannel`s with.
/// - childGroup: The `EventLoopGroup` to run the accepted `NIOTSConnectionChannel`s on.
/// - group: The `EventLoopGroup` to use for the `bind` of the listening channel and to accept new child channels with.
/// - childGroup: The `EventLoopGroup` to run the accepted child channels on.
public init?(validatingGroup group: EventLoopGroup, childGroup: EventLoopGroup? = nil) {
let childGroup = childGroup ?? group
guard NIOTSBootstraps.isCompatible(group: group) && NIOTSBootstraps.isCompatible(group: childGroup) else {
@ -138,23 +135,22 @@ public final class NIOTSDatagramListenerBootstrap {
self.childGroup = childGroup
}
/// Create a ``NIOTSListenerBootstrap``.
/// Create a ``NIOTSDatagramListenerBootstrap``.
///
/// - parameters:
/// - group: The ``NIOTSEventLoopGroup`` to use for the `bind` of the `NIOTSListenerChannel`
/// and to accept new `NIOTSConnectionChannel`s with.
/// - childGroup: The ``NIOTSEventLoopGroup`` to run the accepted `NIOTSConnectionChannel`s on.
/// - group: The ``NIOTSEventLoopGroup`` to use for the `bind` of the listening channel and to accept new child
/// channels with.
/// - childGroup: The ``NIOTSEventLoopGroup`` to run the accepted child channels on.
public convenience init(group: NIOTSEventLoopGroup, childGroup: NIOTSEventLoopGroup) {
self.init(group: group as EventLoopGroup, childGroup: childGroup as EventLoopGroup)
}
/// Initialize the `NIOTSListenerChannel` with `initializer`. The most common task in initializer is to add
/// Initialize the listening channel with `initializer`. The most common task in initializer is to add
/// `ChannelHandler`s to the `ChannelPipeline`.
///
/// The `NIOTSListenerChannel` uses the accepted `NIOTSConnectionChannel`s as inbound messages.
/// The listening channel uses the accepted child channels as inbound messages.
///
/// > Note: To set the initializer for the accepted `NIOTSConnectionChannel`s, look at
/// ``childChannelInitializer(_:)``.
/// > Note: To set the initializer for the accepted child channels, look at ``childChannelInitializer(_:)``.
///
/// - parameters:
/// - initializer: A closure that initializes the provided `Channel`.
@ -165,7 +161,7 @@ public final class NIOTSDatagramListenerBootstrap {
return self
}
/// Initialize the accepted `NIOTSConnectionChannel`s with `initializer`. The most common task in initializer is to add
/// Initialize the accepted child channels with `initializer`. The most common task in initializer is to add
/// `ChannelHandler`s to the `ChannelPipeline`. Note that if the `initializer` fails then the error will be
/// fired in the *parent* channel.
///
@ -179,9 +175,9 @@ public final class NIOTSDatagramListenerBootstrap {
return self
}
/// Specifies a `ChannelOption` to be applied to the `NIOTSListenerChannel`.
/// Specifies a `ChannelOption` to be applied to the listening channel.
///
/// > Note: To specify options for the accepted `NIOTSConnectionChannel`s, look at ``childChannelOption(_:value:)``.
/// > Note: To specify options for the accepted child channels, look at ``childChannelOption(_:value:)``.
///
/// - parameters:
/// - option: The option to be applied.
@ -191,7 +187,7 @@ public final class NIOTSDatagramListenerBootstrap {
return self
}
/// Specifies a `ChannelOption` to be applied to the accepted `NIOTSConnectionChannel`s.
/// Specifies a `ChannelOption` to be applied to the accepted child channels.
///
/// - parameters:
/// - option: The option to be applied.
@ -268,7 +264,7 @@ public final class NIOTSDatagramListenerBootstrap {
return self
}
/// Bind the `NIOTSListenerChannel` to `host` and `port`.
/// Bind the listening channel to `host` and `port`.
///
/// - parameters:
/// - host: The host to bind on.
@ -292,7 +288,7 @@ public final class NIOTSDatagramListenerBootstrap {
}
}
/// Bind the `NIOTSListenerChannel` to `address`.
/// Bind the listening channel to `address`.
///
/// - parameters:
/// - address: The `SocketAddress` to bind on.
@ -302,7 +298,7 @@ public final class NIOTSDatagramListenerBootstrap {
}
}
/// Bind the `NIOTSListenerChannel` to a UNIX Domain Socket.
/// Bind the listening channel to a UNIX Domain Socket.
///
/// - parameters:
/// - unixDomainSocketPath: The _Unix domain socket_ path to bind to. `unixDomainSocketPath` must not exist, it will be created by the system.
@ -317,7 +313,7 @@ public final class NIOTSDatagramListenerBootstrap {
}
}
/// Bind the `NIOTSListenerChannel` to a given `NWEndpoint`.
/// Bind the listening channel to a given `NWEndpoint`.
///
/// - parameters:
/// - endpoint: The `NWEndpoint` to bind this channel to.
@ -327,7 +323,7 @@ public final class NIOTSDatagramListenerBootstrap {
}
}
/// Bind the `NIOTSListenerChannel` to an existing `NWListener`.
/// Bind the listening channel to an existing `NWListener`.
///
/// - parameters:
/// - listener: The NWListener to wrap.
@ -388,7 +384,7 @@ public final class NIOTSDatagramListenerBootstrap {
eventLoop.assertInEventLoop()
return eventLoop.makeCompletedFuture {
try serverChannel.pipeline.syncOperations.addHandler(
AcceptHandler<NIOTSDatagramChannel>(
AcceptHandler<NIOTSDatagramConnectionChannel>(
childChannelInitializer: childChannelInit,
childChannelOptions: childChannelOptions
)

View File

@ -22,7 +22,7 @@ import Network
import Atomics
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
internal final class NIOTSDatagramListenerChannel: StateManagedListenerChannel<NIOTSDatagramChannel> {
internal final class NIOTSDatagramListenerChannel: StateManagedListenerChannel<NIOTSDatagramConnectionChannel> {
/// The TCP options for this listener.
private var udpOptions: NWProtocolUDP.Options {
get {
@ -135,7 +135,7 @@ internal final class NIOTSDatagramListenerChannel: StateManagedListenerChannel<N
return
}
let newChannel = NIOTSDatagramChannel(
let newChannel = NIOTSDatagramConnectionChannel(
wrapping: connection,
on: self.childLoopGroup.next() as! NIOTSEventLoop,
parent: self,

View File

@ -17,9 +17,9 @@ import NIOCore
import Dispatch
import Network
/// A `NIOTSConnectionBootstrap` is an easy way to bootstrap a `NIOTSConnectionChannel` when creating network clients.
/// A ``NIOTSConnectionBootstrap`` is an easy way to bootstrap a channel when creating network clients.
///
/// Usually you re-use a `NIOTSConnectionBootstrap` once you set it up, calling `connect` multiple times on the same bootstrap.
/// Usually you re-use a ``NIOTSConnectionBootstrap`` once you set it up, calling `connect` multiple times on the same bootstrap.
/// This way you ensure that the same `EventLoop`s will be shared across all your connections.
///
/// Example:
@ -37,7 +37,7 @@ import Network
/// /* the Channel is now connected */
/// ```
///
/// The connected `NIOTSConnectionChannel` will operate on `ByteBuffer` as inbound and on `IOData` as outbound messages.
/// The connected channel will operate on `ByteBuffer` as inbound and on `IOData` as outbound messages.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
public final class NIOTSConnectionBootstrap {
private let group: EventLoopGroup
@ -64,9 +64,9 @@ public final class NIOTSConnectionBootstrap {
private var protocolHandlers: (@Sendable () -> [ChannelHandler])? = nil
private var nwParametersConfigurator: (@Sendable (NWParameters) -> Void)?
/// Create a `NIOTSConnectionBootstrap` on the `EventLoopGroup` `group`.
/// Create a ``NIOTSConnectionBootstrap`` on the `EventLoopGroup` `group`.
///
/// The `EventLoopGroup` `group` must be compatible, otherwise the program will crash. `NIOTSConnectionBootstrap` is
/// The `EventLoopGroup` `group` must be compatible, otherwise the program will crash. ``NIOTSConnectionBootstrap`` is
/// compatible only with ``NIOTSEventLoopGroup`` as well as the `EventLoop`s returned by
/// ``NIOTSEventLoopGroup/next()``. See ``init(validatingGroup:)`` for a fallible initializer for
/// situations where it's impossible to tell ahead of time if the `EventLoopGroup` is compatible or not.
@ -84,7 +84,7 @@ public final class NIOTSConnectionBootstrap {
self.init(validatingGroup: group)!
}
/// Create a `NIOTSConnectionBootstrap` on the ``NIOTSEventLoopGroup`` `group`.
/// Create a ``NIOTSConnectionBootstrap`` on the ``NIOTSEventLoopGroup`` `group`.
///
/// - parameters:
/// - group: The ``NIOTSEventLoopGroup`` to use.
@ -92,7 +92,7 @@ public final class NIOTSConnectionBootstrap {
self.init(group: group as EventLoopGroup)
}
/// Create a `NIOTSConnectionBootstrap` on the ``NIOTSEventLoopGroup`` `group`, validating
/// Create a ``NIOTSConnectionBootstrap`` on the ``NIOTSEventLoopGroup`` `group`, validating
/// that the `EventLoopGroup` is compatible with ``NIOTSConnectionBootstrap``.
///
/// - parameters:
@ -107,7 +107,7 @@ public final class NIOTSConnectionBootstrap {
self._channelInitializer = { channel in channel.eventLoop.makeSucceededVoidFuture() }
}
/// Initialize the connected `NIOTSConnectionChannel` with `initializer`. The most common task in initializer is to add
/// Initialize the connected channel with `initializer`. The most common task in initializer is to add
/// `ChannelHandler`s to the `ChannelPipeline`.
///
/// The connected `Channel` will operate on `ByteBuffer` as inbound and `IOData` as outbound messages.
@ -120,7 +120,7 @@ public final class NIOTSConnectionBootstrap {
return self
}
/// Specifies a `ChannelOption` to be applied to the `NIOTSConnectionChannel`.
/// Specifies a `ChannelOption` to be applied to the channel.
///
/// - parameters:
/// - option: The option to be applied.

View File

@ -17,7 +17,7 @@ import NIOCore
import Dispatch
import Network
/// A ``NIOTSListenerBootstrap`` is an easy way to bootstrap a `NIOTSListenerChannel` when creating network servers.
/// A ``NIOTSListenerBootstrap`` is an easy way to bootstrap a listener channel when creating network servers.
///
/// Example:
///
@ -46,13 +46,12 @@ import Network
/// try! channel.closeFuture.wait() // wait forever as we never close the Channel
/// ```
///
/// The `EventLoopFuture` returned by `bind` will fire with a `NIOTSListenerChannel`. This is the channel that owns the
/// listening socket. Each time it accepts a new connection it will fire a `NIOTSConnectionChannel` through the
/// `ChannelPipeline` via `fireChannelRead`: as a result, the `NIOTSListenerChannel` operates on `Channel`s as inbound
/// messages. Outbound messages are not supported on a `NIOTSListenerChannel` which means that each write attempt will
/// fail.
/// The `EventLoopFuture` returned by `bind` will fire with a channel. This is the channel that owns the listening socket. Each
/// time it accepts a new connection it will fire a new child channel for the new connection through the `ChannelPipeline` via
/// `fireChannelRead`: as a result, the listening channel operates on `Channel`s as inbound messages. Outbound messages are
/// not supported on these listening channels, which means that each write attempt will fail.
///
/// Accepted `NIOTSConnectionChannel`s operate on `ByteBuffer` as inbound data, and `IOData` as outbound data.
/// Accepted channels operate on `ByteBuffer` as inbound data, and `IOData` as outbound data.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
public final class NIOTSListenerBootstrap {
private let group: EventLoopGroup
@ -82,7 +81,7 @@ public final class NIOTSListenerBootstrap {
/// > Note: The "real" solution is described in https://github.com/apple/swift-nio/issues/674.
///
/// - parameters:
/// - group: The `EventLoopGroup` to use for the `NIOTSListenerChannel`.
/// - group: The `EventLoopGroup` to use for the listening channel.
public convenience init(group: EventLoopGroup) {
self.init(group: group, childGroup: group)
}
@ -90,7 +89,7 @@ public final class NIOTSListenerBootstrap {
/// Create a ``NIOTSListenerBootstrap`` for the ``NIOTSEventLoopGroup`` `group`.
///
/// - parameters:
/// - group: The ``NIOTSEventLoopGroup`` to use for the `NIOTSListenerChannel`.
/// - group: The ``NIOTSEventLoopGroup`` to use for the listening channel.
public convenience init(group: NIOTSEventLoopGroup) {
self.init(group: group as EventLoopGroup)
}
@ -106,9 +105,9 @@ public final class NIOTSListenerBootstrap {
/// > Note: The "real" solution is described in https://github.com/apple/swift-nio/issues/674.
///
/// - parameters:
/// - group: The `EventLoopGroup` to use for the `bind` of the `NIOTSListenerChannel`
/// and to accept new `NIOTSConnectionChannel`s with.
/// - childGroup: The `EventLoopGroup` to run the accepted `NIOTSConnectionChannel`s on.
/// - group: The `EventLoopGroup` to use for the `bind` of the listening channel
/// and to accept new child channels with.
/// - childGroup: The `EventLoopGroup` to run the accepted child channels on.
public convenience init(group: EventLoopGroup, childGroup: EventLoopGroup) {
guard NIOTSBootstraps.isCompatible(group: group) && NIOTSBootstraps.isCompatible(group: childGroup) else {
preconditionFailure(
@ -125,9 +124,9 @@ public final class NIOTSListenerBootstrap {
/// validating that the `EventLoopGroup`s are compatible with ``NIOTSListenerBootstrap``.
///
/// - parameters:
/// - group: The `EventLoopGroup` to use for the `bind` of the `NIOTSListenerChannel`
/// and to accept new `NIOTSConnectionChannel`s with.
/// - childGroup: The `EventLoopGroup` to run the accepted `NIOTSConnectionChannel`s on.
/// - group: The `EventLoopGroup` to use for the `bind` of the listening channel
/// and to accept new child channels with.
/// - childGroup: The `EventLoopGroup` to run the accepted child channels on.
public init?(validatingGroup group: EventLoopGroup, childGroup: EventLoopGroup? = nil) {
let childGroup = childGroup ?? group
guard NIOTSBootstraps.isCompatible(group: group) && NIOTSBootstraps.isCompatible(group: childGroup) else {
@ -144,19 +143,19 @@ public final class NIOTSListenerBootstrap {
/// Create a ``NIOTSListenerBootstrap``.
///
/// - parameters:
/// - group: The ``NIOTSEventLoopGroup`` to use for the `bind` of the `NIOTSListenerChannel`
/// and to accept new `NIOTSConnectionChannel`s with.
/// - childGroup: The ``NIOTSEventLoopGroup`` to run the accepted `NIOTSConnectionChannel`s on.
/// - group: The ``NIOTSEventLoopGroup`` to use for the `bind` of the listening channel
/// and to accept new child channels with.
/// - childGroup: The ``NIOTSEventLoopGroup`` to run the accepted child channels on.
public convenience init(group: NIOTSEventLoopGroup, childGroup: NIOTSEventLoopGroup) {
self.init(group: group as EventLoopGroup, childGroup: childGroup as EventLoopGroup)
}
/// Initialize the `NIOTSListenerChannel` with `initializer`. The most common task in initializer is to add
/// Initialize the listening channel with `initializer`. The most common task in initializer is to add
/// `ChannelHandler`s to the `ChannelPipeline`.
///
/// The `NIOTSListenerChannel` uses the accepted `NIOTSConnectionChannel`s as inbound messages.
/// The listening channel uses the accepted child channels as inbound messages.
///
/// > Note: To set the initializer for the accepted `NIOTSConnectionChannel`s, look at
/// > Note: To set the initializer for the accepted child channels, look at
/// ``childChannelInitializer(_:)``.
///
/// - parameters:
@ -168,7 +167,7 @@ public final class NIOTSListenerBootstrap {
return self
}
/// Initialize the accepted `NIOTSConnectionChannel`s with `initializer`. The most common task in initializer is to add
/// Initialize the accepted child channels with `initializer`. The most common task in initializer is to add
/// `ChannelHandler`s to the `ChannelPipeline`. Note that if the `initializer` fails then the error will be
/// fired in the *parent* channel.
///
@ -182,9 +181,9 @@ public final class NIOTSListenerBootstrap {
return self
}
/// Specifies a `ChannelOption` to be applied to the `NIOTSListenerChannel`.
/// Specifies a `ChannelOption` to be applied to the listening channel.
///
/// > Note: To specify options for the accepted `NIOTSConnectionChannel`s, look at ``childChannelOption(_:value:)``.
/// > Note: To specify options for the accepted child channels, look at ``childChannelOption(_:value:)``.
///
/// - parameters:
/// - option: The option to be applied.
@ -194,7 +193,7 @@ public final class NIOTSListenerBootstrap {
return self
}
/// Specifies a `ChannelOption` to be applied to the accepted `NIOTSConnectionChannel`s.
/// Specifies a `ChannelOption` to be applied to the accepted child channels.
///
/// - parameters:
/// - option: The option to be applied.
@ -281,7 +280,7 @@ public final class NIOTSListenerBootstrap {
self.serverChannelOption(NIOTSChannelOptions.multipathServiceType, value: type)
}
/// Bind the `NIOTSListenerChannel` to `host` and `port`.
/// Bind the listening channel to `host` and `port`.
///
/// - parameters:
/// - host: The host to bind on.
@ -305,7 +304,7 @@ public final class NIOTSListenerBootstrap {
}
}
/// Bind the `NIOTSListenerChannel` to `address`.
/// Bind the listening channel to `address`.
///
/// - parameters:
/// - address: The `SocketAddress` to bind on.
@ -315,7 +314,7 @@ public final class NIOTSListenerBootstrap {
}
}
/// Bind the `NIOTSListenerChannel` to a UNIX Domain Socket.
/// Bind the listening channel to a UNIX Domain Socket.
///
/// - parameters:
/// - unixDomainSocketPath: The _Unix domain socket_ path to bind to. `unixDomainSocketPath` must not exist, it will be created by the system.
@ -330,7 +329,7 @@ public final class NIOTSListenerBootstrap {
}
}
/// Bind the `NIOTSListenerChannel` to a given `NWEndpoint`.
/// Bind the listening channel to a given `NWEndpoint`.
///
/// - parameters:
/// - endpoint: The `NWEndpoint` to bind this channel to.
@ -340,7 +339,7 @@ public final class NIOTSListenerBootstrap {
}
}
/// Bind the `NIOTSListenerChannel` to an existing `NWListener`.
/// Bind the listening channel to an existing `NWListener`.
///
/// - parameters:
/// - listener: The NWListener to wrap.
@ -441,7 +440,7 @@ public final class NIOTSListenerBootstrap {
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension NIOTSListenerBootstrap {
/// Bind the `NIOTSListenerChannel` to `host` and `port`.
/// Bind the listening channel to `host` and `port`.
///
/// - Parameters:
/// - host: The host to bind on.
@ -486,7 +485,7 @@ extension NIOTSListenerBootstrap {
).get()
}
/// Bind the `NIOTSListenerChannel` to `address`.
/// Bind the listening channel to `address`.
///
/// - Parameters:
/// - address: The `SocketAddress` to bind on.
@ -516,7 +515,7 @@ extension NIOTSListenerBootstrap {
).get()
}
/// Bind the `NIOTSListenerChannel` to a given `NWEndpoint`.
/// Bind the listening channel to a given `NWEndpoint`.
///
/// - Parameters:
/// - endpoint: The `NWEndpoint` to bind this channel to.
@ -549,7 +548,7 @@ extension NIOTSListenerBootstrap {
).get()
}
/// Bind the `NIOTSListenerChannel` to an existing `NWListener`.
/// Bind the listening channel to an existing `NWListener`.
///
/// - Parameters:
/// - listener: The NWListener to wrap.

View File

@ -114,7 +114,7 @@ final class ReadRecorder<DataType: Sendable>: ChannelInboundHandler {
// Mimicks the DatagramChannelTest from apple/swift-nio
@available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 6, *)
final class NIOTSDatagramConnectionChannelTests: XCTestCase {
final class NIOTSDatagramBootstrapTests: XCTestCase {
private var group: NIOTSEventLoopGroup!
private func buildServerChannel(
@ -142,7 +142,7 @@ final class NIOTSDatagramConnectionChannelTests: XCTestCase {
host: String = "127.0.0.1",
port: Int
) throws -> Channel {
try NIOTSDatagramBootstrap(group: group)
try NIOTSDatagramConnectionBootstrap(group: group)
.channelInitializer { channel in
channel.eventLoop.makeCompletedFuture {
try channel.pipeline.syncOperations.addHandler(
@ -219,7 +219,7 @@ final class NIOTSDatagramConnectionChannelTests: XCTestCase {
XCTAssertNoThrow(try listener.close().wait())
}
let connection = try! NIOTSDatagramBootstrap(group: self.group)
let connection = try! NIOTSDatagramConnectionBootstrap(group: self.group)
.channelInitializer { channel in
testSyncOptions(channel)
return channel.eventLoop.makeSucceededVoidFuture()
@ -257,7 +257,7 @@ final class NIOTSDatagramConnectionChannelTests: XCTestCase {
.bind(host: "localhost", port: 0)
.get()
let connectionChannel: Channel = try await NIOTSDatagramBootstrap(group: group)
let connectionChannel: Channel = try await NIOTSDatagramConnectionBootstrap(group: group)
.configureNWParameters { _ in
configuratorClientConnectionCounter.withLockedValue { $0 += 1 }
}
@ -292,7 +292,7 @@ final class NIOTSDatagramConnectionChannelTests: XCTestCase {
XCTAssertNoThrow(try listener.close().wait())
}
_ = try NIOTSDatagramBootstrap(group: self.group)
_ = try NIOTSDatagramConnectionBootstrap(group: self.group)
.channelInitializer { channel in
let conn = try! channel.syncOptions!.getOption(NIOTSChannelOptions.connection)
XCTAssertNil(conn)