Skip to content

Commit

Permalink
Fix feedback as provided by Cory
Browse files Browse the repository at this point in the history
  • Loading branch information
Joannis committed Jul 10, 2023
1 parent f750f8c commit adfcaeb
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//

#if canImport(Network)
import NIO
import NIOCore
import Dispatch
import Network

Expand All @@ -37,7 +37,7 @@ import Network
/// /* the Channel is now connected */
/// ```
///
/// The connected `NIOTSDatagramChannel` will operate on `ByteBuffer` as inbound and on `IOData` as outbound messages.
/// The connected `NIOTSDatagramChannel` 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 {
private let group: EventLoopGroup
Expand All @@ -51,7 +51,7 @@ public final class NIOTSDatagramBootstrap {
/// Create a `NIOTSDatagramConnectionBootstrap` on 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 extenstion an `EventLoop`. As such an
/// may be constructed with an `EventLoopGroup` and by extension an `EventLoop`. As such an
/// existing `NIOTSEventLoop` may be used to initialize this bootstrap. Where possible the
/// initializers accepting `NIOTSEventLoopGroup` should be used instead to avoid the wrong
/// type being used.
Expand All @@ -75,7 +75,7 @@ public final class NIOTSDatagramBootstrap {
/// Initialize the connected `NIOTSDatagramConnectionChannel` 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.
/// The connected `Channel` will operate on `ByteBuffer` as inbound and outbound messages.
///
/// - parameters:
/// - handler: A closure that initializes the provided `Channel`.
Expand Down
10 changes: 5 additions & 5 deletions Sources/NIOTransportServices/Datagram/NIOTSDatagramChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#if canImport(Network)
import Atomics
import Foundation
import NIO
import NIOCore
import NIOConcurrencyHelpers
import NIOFoundationCompat
import NIOTLS
Expand Down Expand Up @@ -75,7 +75,7 @@ internal final class NIOTSDatagramChannel: StateManagedNWConnectionChannel {
internal var connectPromise: EventLoopPromise<Void>?

/// The UDP options for this connection.
private var udpOptions: NWProtocolUDP.Options
private let udpOptions: NWProtocolUDP.Options

internal var nwOptions: NWProtocolUDP.Options { udpOptions }

Expand All @@ -96,7 +96,7 @@ internal final class NIOTSDatagramChannel: StateManagedNWConnectionChannel {
internal var options = TransportServicesChannelOptions()

/// Any pending writes that have yet to be delivered to the network stack.
internal var _pendingWrites = CircularBuffer<PendingWrite>(initialCapacity: 8)
internal var pendingWrites = CircularBuffer<PendingWrite>(initialCapacity: 8)

/// An object to keep track of pending writes and manage our backpressure signaling.
internal var _backpressureManager = BackpressureManager()
Expand All @@ -111,7 +111,7 @@ internal final class NIOTSDatagramChannel: StateManagedNWConnectionChannel {
internal var enablePeerToPeer = false

/// The cache of the local and remote socket addresses. Must be accessed using _addressCacheLock.
private var _addressCache = AddressCache(local: nil, remote: nil)
internal var _addressCache = AddressCache(local: nil, remote: nil)

internal var addressCache: AddressCache {
get {
Expand All @@ -127,7 +127,7 @@ internal final class NIOTSDatagramChannel: StateManagedNWConnectionChannel {
}

/// A lock that guards the _addressCache.
private let _addressCacheLock = NIOLock()
internal let _addressCacheLock = NIOLock()

internal var allowLocalEndpointReuse = false
internal var multipathServiceType: NWParameters.MultipathServiceType = .disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public final class NIOTSDatagramListenerBootstrap {
/// Create a ``NIOTSListenerBootstrap`` 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 extenstion an `EventLoop`. As such an
/// may be constructed with an `EventLoopGroup` and by extension an `EventLoop`. As such an
/// existing `NIOTSEventLoop` may be used to initialize this bootstrap. Where possible the
/// initializers accepting ``NIOTSEventLoopGroup`` should be used instead to avoid the wrong
/// type being used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ internal final class NIOTSDatagramListenerChannel: StateManagedListenerChannel<N
return options
}
set {
assert({
if case .udp = protocolOptions {
return true
} else {
return false
}
}(), "The protocol options of this channel were not configured as UDP")

protocolOptions = .udp(newValue)
}
}
Expand All @@ -47,6 +55,14 @@ internal final class NIOTSDatagramListenerChannel: StateManagedListenerChannel<N
return options
}
set {
assert({
if case .udp = childProtocolOptions {
return true
} else {
return false
}
}(), "The protocol options of child channelss were not configured as UDP")

childProtocolOptions = .udp(newValue)
}
}
Expand Down
19 changes: 3 additions & 16 deletions Sources/NIOTransportServices/NIOTSConnectionChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ internal final class NIOTSConnectionChannel: StateManagedNWConnectionChannel {
internal var state: ChannelState<ActiveSubstate> = .idle

/// The active state, used for safely reporting the channel state across threads.
internal var isActive0 = ManagedAtomic(false)
internal let isActive0 = ManagedAtomic(false)

/// The kinds of channel activation this channel supports
internal let supportedActivationType: ActivationType = .connect
Expand Down Expand Up @@ -221,19 +221,6 @@ internal final class NIOTSConnectionChannel: StateManagedNWConnectionChannel {
}
}

internal var addressCache: AddressCache {
get {
return self._addressCacheLock.withLock {
return self._addressCache
}
}
set {
return self._addressCacheLock.withLock {
self._addressCache = newValue
}
}
}

/// A lock that guards the _addressCache.
internal let _addressCacheLock = NIOLock()

Expand Down Expand Up @@ -438,8 +425,8 @@ extension NIOTSConnectionChannel {
/// Drop all outstanding writes. Must only be called in the inactive
/// state.
private func dropOutNIOTransportServicesTestsstandingWrites(error: Error) {
while self._pendingWrites.count > 0 {
self._pendingWrites.removeFirst().promise?.fail(error)
while self.pendingWrites.count > 0 {
self.pendingWrites.removeFirst().promise?.fail(error)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOTransportServices/NIOTSListenerBootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public final class NIOTSListenerBootstrap {
/// Create a ``NIOTSListenerBootstrap`` 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 extenstion an `EventLoop`. As such an
/// may be constructed with an `EventLoopGroup` and by extension an `EventLoop`. As such an
/// existing `NIOTSEventLoop` may be used to initialize this bootstrap. Where possible the
/// initializers accepting ``NIOTSEventLoopGroup`` should be used instead to avoid the wrong
/// type being used.
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOTransportServices/NIOTSListenerChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal final class NIOTSListenerChannel: StateManagedListenerChannel<NIOTSConn
}
set {
assert({
if case .tcp = protocolOptions {
if case .tcp = childProtocolOptions {
return true
} else {
return false
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOTransportServices/StateManagedChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal protocol StateManagedChannel: Channel, ChannelCore {

var state: ChannelState<ActiveSubstate> { get set }

var isActive0: ManagedAtomic<Bool> { get set }
var isActive0: ManagedAtomic<Bool> { get }

var tsEventLoop: NIOTSEventLoop { get }

Expand Down

0 comments on commit adfcaeb

Please sign in to comment.