Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ let package = Package(
"_NIODataStructures",
swiftCollections,
swiftAtomics,
],
swiftSettings: strictConcurrencySettings
]
),
.target(
name: "_NIODataStructures",
Expand Down Expand Up @@ -415,13 +414,11 @@ let package = Package(
.testTarget(
name: "NIOCoreTests",
dependencies: [
"NIOConcurrencyHelpers",
"NIOCore",
"NIOEmbedded",
"NIOFoundationCompat",
swiftAtomics,
],
swiftSettings: strictConcurrencySettings
]
),
.testTarget(
name: "NIOEmbeddedTests",
Expand Down
23 changes: 3 additions & 20 deletions Sources/NIOCore/AsyncAwaitSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ extension Channel {
/// - data: the data to write
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@inlinable
@preconcurrency
public func writeAndFlush<T: Sendable>(_ data: T) async throws {
try await self.writeAndFlush(data).get()
public func writeAndFlush<T>(_ any: T) async throws {
try await self.writeAndFlush(any).get()
}

/// Set `option` to `value` on this `Channel`.
Expand Down Expand Up @@ -148,11 +147,6 @@ extension ChannelOutboundInvoker {
/// - file: The file this function was called in, for debugging purposes.
/// - line: The line this function was called on, for debugging purposes.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(
*,
deprecated,
message: "NIOAny is not Sendable: avoid wrapping the value in NIOAny to silence this warning."
)
public func writeAndFlush(_ data: NIOAny, file: StaticString = #fileID, line: UInt = #line) async throws {
try await self.writeAndFlush(data, file: file, line: line).get()
}
Expand All @@ -173,14 +167,8 @@ extension ChannelOutboundInvoker {
/// - Parameters:
/// - event: the event itself.
/// - file: The file this function was called in, for debugging purposes.
/// - line: The line this function was called on, for debugging purposes.
@preconcurrency
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
public func triggerUserOutboundEvent(
_ event: Any & Sendable,
file: StaticString = #fileID,
line: UInt = #line
) async throws {
public func triggerUserOutboundEvent(_ event: Any, file: StaticString = #fileID, line: UInt = #line) async throws {
try await self.triggerUserOutboundEvent(event, file: file, line: line).get()
}
}
Expand Down Expand Up @@ -208,11 +196,6 @@ extension ChannelPipeline {
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@available(
*,
deprecated,
message: "Use .syncOperations.removeHandler(context:) instead, this method is not Sendable-safe."
)
public func removeHandler(context: ChannelHandlerContext) async throws {
try await self.removeHandler(context: context).get()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOCore/BSDSocketAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ let SO_TIMESTAMP = CNIOLinux_SO_TIMESTAMP
let SO_RCVTIMEO = CNIOLinux_SO_RCVTIMEO
#endif

public enum NIOBSDSocket: Sendable {
public enum NIOBSDSocket {
#if os(Windows)
public typealias Handle = SOCKET
#else
Expand Down
77 changes: 21 additions & 56 deletions Sources/NIOCore/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,30 +145,6 @@ public protocol Channel: AnyObject, ChannelOutboundInvoker, _NIOPreconcurrencySe
/// The default implementation returns `nil`, and `Channel` implementations must opt in to
/// support this behavior.
var syncOptions: NIOSynchronousChannelOptions? { get }

/// Write data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.write`.
@preconcurrency
func write<T: Sendable>(_ any: T) -> EventLoopFuture<Void>

/// Write data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.write`.
@preconcurrency
func write<T: Sendable>(_ any: T, promise: EventLoopPromise<Void>?)

/// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.writeAndFlush`.
@preconcurrency
func writeAndFlush<T: Sendable>(_ any: T) -> EventLoopFuture<Void>

/// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.writeAndFlush`.
@preconcurrency
func writeAndFlush<T: Sendable>(_ any: T, promise: EventLoopPromise<Void>?)
}

extension Channel {
Expand Down Expand Up @@ -201,36 +177,18 @@ extension Channel {
pipeline.connect(to: address, promise: promise)
}

@available(
*,
deprecated,
message: "NIOAny is not Sendable. Avoid wrapping the value in NIOAny to silence this warning."
)
public func write(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
pipeline.write(data, promise: promise)
}

public func write<T: Sendable>(_ data: T, promise: EventLoopPromise<Void>?) {
pipeline.write(data, promise: promise)
}

public func flush() {
pipeline.flush()
}

@available(
*,
deprecated,
message: "NIOAny is not Sendable. Avoid wrapping the value in NIOAny to silence this warning."
)
public func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?) {
pipeline.writeAndFlush(data, promise: promise)
}

public func writeAndFlush<T: Sendable>(_ data: T, promise: EventLoopPromise<Void>?) {
pipeline.writeAndFlush(data, promise: promise)
}

public func read() {
pipeline.read()
}
Expand All @@ -247,33 +205,40 @@ extension Channel {
promise?.fail(ChannelError._operationUnsupported)
}

@preconcurrency
public func triggerUserOutboundEvent(_ event: Any & Sendable, promise: EventLoopPromise<Void>?) {
public func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise<Void>?) {
pipeline.triggerUserOutboundEvent(event, promise: promise)
}
}

/// Provides special extension to make writing data to the `Channel` easier by removing the need to wrap data in `NIOAny` manually.
extension Channel {

/// Write data into the `Channel`.
/// Write data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.write`.
@preconcurrency
public func write<T: Sendable>(_ any: T) -> EventLoopFuture<Void> {
let promise = self.eventLoop.makePromise(of: Void.self)
self.write(any, promise: promise)
return promise.futureResult
public func write<T>(_ any: T) -> EventLoopFuture<Void> {
self.write(NIOAny(any))
}

/// Write and flush data into the `Channel`.
/// Write data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.write`.
public func write<T>(_ any: T, promise: EventLoopPromise<Void>?) {
self.write(NIOAny(any), promise: promise)
}

/// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.writeAndFlush`.
public func writeAndFlush<T>(_ any: T) -> EventLoopFuture<Void> {
self.writeAndFlush(NIOAny(any))
}

/// Write and flush data into the `Channel`, automatically wrapping with `NIOAny`.
///
/// - seealso: `ChannelOutboundInvoker.writeAndFlush`.
@preconcurrency
public func writeAndFlush<T: Sendable>(_ any: T) -> EventLoopFuture<Void> {
let promise = self.eventLoop.makePromise(of: Void.self)
self.writeAndFlush(any, promise: promise)
return promise.futureResult
public func writeAndFlush<T>(_ any: T, promise: EventLoopPromise<Void>?) {
self.writeAndFlush(NIOAny(any), promise: promise)
}
}

Expand Down
34 changes: 3 additions & 31 deletions Sources/NIOCore/ChannelInvoker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ public protocol ChannelOutboundInvoker {
/// - data: the data to write
/// - promise: the `EventLoopPromise` that will be notified once the operation completes,
/// or `nil` if not interested in the outcome of the operation.
@available(
*,
deprecated,
message: "NIOAny is not Sendable. Avoid wrapping the value in NIOAny to silence this warning."
)
func write(_ data: NIOAny, promise: EventLoopPromise<Void>?)

/// Flush data that was previously written via `write` to the remote peer.
Expand All @@ -61,11 +56,6 @@ public protocol ChannelOutboundInvoker {
/// - data: the data to write
/// - promise: the `EventLoopPromise` that will be notified once the `write` operation completes,
/// or `nil` if not interested in the outcome of the operation.
@available(
*,
deprecated,
message: "NIOAny is not Sendable. Avoid wrapping the value in NIOAny to silence this warning."
)
func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?)

/// Signal that we want to read from the `Channel` once there is data ready.
Expand All @@ -89,8 +79,7 @@ public protocol ChannelOutboundInvoker {
/// - event: The event itself.
/// - promise: the `EventLoopPromise` that will be notified once the operation completes,
/// or `nil` if not interested in the outcome of the operation.
@preconcurrency
func triggerUserOutboundEvent(_ event: Any & Sendable, promise: EventLoopPromise<Void>?)
func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise<Void>?)

/// The `EventLoop` which is used by this `ChannelOutboundInvoker` for execution.
var eventLoop: EventLoop { get }
Expand Down Expand Up @@ -155,11 +144,6 @@ extension ChannelOutboundInvoker {
/// - file: The file this function was called in, for debugging purposes.
/// - line: The line this function was called on, for debugging purposes.
/// - Returns: the future which will be notified once the operation completes.
@available(
*,
deprecated,
message: "NIOAny is not Sendable. Avoid wrapping the value in NIOAny to silence this warning."
)
public func write(_ data: NIOAny, file: StaticString = #fileID, line: UInt = #line) -> EventLoopFuture<Void> {
let promise = makePromise(file: file, line: line)
write(data, promise: promise)
Expand All @@ -173,11 +157,6 @@ extension ChannelOutboundInvoker {
/// - file: The file this function was called in, for debugging purposes.
/// - line: The line this function was called on, for debugging purposes.
/// - Returns: the future which will be notified once the `write` operation completes.
@available(
*,
deprecated,
message: "NIOAny is not Sendable. Avoid wrapping the value in NIOAny to silence this warning."
)
public func writeAndFlush(_ data: NIOAny, file: StaticString = #fileID, line: UInt = #line) -> EventLoopFuture<Void>
{
let promise = makePromise(file: file, line: line)
Expand Down Expand Up @@ -206,9 +185,8 @@ extension ChannelOutboundInvoker {
/// - file: The file this function was called in, for debugging purposes.
/// - line: The line this function was called on, for debugging purposes.
/// - Returns: the future which will be notified once the operation completes.
@preconcurrency
public func triggerUserOutboundEvent(
_ event: Any & Sendable,
_ event: Any,
file: StaticString = #fileID,
line: UInt = #line
) -> EventLoopFuture<Void> {
Expand Down Expand Up @@ -247,11 +225,6 @@ public protocol ChannelInboundInvoker {
///
/// - Parameters:
/// - data: the data that was read and is ready to be processed.
@available(
*,
deprecated,
message: "NIOAny is not Sendable. Avoid wrapping the value in NIOAny to silence this warning."
)
func fireChannelRead(_ data: NIOAny)

/// Called once there is no more data to read immediately on a `Channel`. Any new data received will be handled later.
Expand Down Expand Up @@ -280,8 +253,7 @@ public protocol ChannelInboundInvoker {
///
/// - Parameters:
/// - event: the event itself.
@preconcurrency
func fireUserInboundEventTriggered(_ event: Any & Sendable)
func fireUserInboundEventTriggered(_ event: Any)
}

/// A protocol that signals that outbound and inbound events are triggered by this invoker.
Expand Down
Loading
Loading