Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sendability annotations on SocketOptionProvider #3034

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions Sources/NIOCore/SocketOptionProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public protocol SocketOptionProvider: _NIOPreconcurrencySendable {
/// - value: The value to set the socket option to.
/// - Returns: An `EventLoopFuture` that fires when the option has been set,
/// or if an error has occurred.
func unsafeSetSocketOption<Value>(
@preconcurrency
func unsafeSetSocketOption<Value: Sendable>(
level: SocketOptionLevel,
name: SocketOptionName,
value: Value
Expand All @@ -95,7 +96,8 @@ public protocol SocketOptionProvider: _NIOPreconcurrencySendable {
/// - value: The value to set the socket option to.
/// - Returns: An `EventLoopFuture` that fires when the option has been set,
/// or if an error has occurred.
func unsafeSetSocketOption<Value>(
@preconcurrency
func unsafeSetSocketOption<Value: Sendable>(
level: NIOBSDSocket.OptionLevel,
name: NIOBSDSocket.Option,
value: Value
Expand All @@ -114,7 +116,11 @@ public protocol SocketOptionProvider: _NIOPreconcurrencySendable {
/// - name: The name of the socket option, e.g. `SO_REUSEADDR`.
/// - Returns: An `EventLoopFuture` containing the value of the socket option, or
/// any error that occurred while retrieving the socket option.
func unsafeGetSocketOption<Value>(level: SocketOptionLevel, name: SocketOptionName) -> EventLoopFuture<Value>
@preconcurrency
func unsafeGetSocketOption<Value: Sendable>(
level: SocketOptionLevel,
name: SocketOptionName
) -> EventLoopFuture<Value>
#endif

/// Obtain the value of the socket option for the given level and name.
Expand All @@ -129,15 +135,16 @@ public protocol SocketOptionProvider: _NIOPreconcurrencySendable {
/// - name: The name of the socket option, e.g. `SO_REUSEADDR`.
/// - Returns: An `EventLoopFuture` containing the value of the socket option, or
/// any error that occurred while retrieving the socket option.
func unsafeGetSocketOption<Value>(
@preconcurrency
func unsafeGetSocketOption<Value: Sendable>(
level: NIOBSDSocket.OptionLevel,
name: NIOBSDSocket.Option
) -> EventLoopFuture<Value>
}

#if !os(Windows)
extension SocketOptionProvider {
func unsafeSetSocketOption<Value>(
func unsafeSetSocketOption<Value: Sendable>(
level: NIOBSDSocket.OptionLevel,
name: NIOBSDSocket.Option,
value: Value
Expand All @@ -149,7 +156,7 @@ extension SocketOptionProvider {
)
}

func unsafeGetSocketOption<Value>(
func unsafeGetSocketOption<Value: Sendable>(
level: NIOBSDSocket.OptionLevel,
name: NIOBSDSocket.Option
) -> EventLoopFuture<Value> {
Expand Down
11 changes: 7 additions & 4 deletions Sources/NIOPosix/BaseSocketChannel+SocketOptionProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import NIOCore

extension BaseSocketChannel: SocketOptionProvider {
#if !os(Windows)
func unsafeSetSocketOption<Value>(
func unsafeSetSocketOption<Value: Sendable>(
level: SocketOptionLevel,
name: SocketOptionName,
value: Value
Expand All @@ -28,7 +28,7 @@ extension BaseSocketChannel: SocketOptionProvider {
}
#endif

func unsafeSetSocketOption<Value>(
func unsafeSetSocketOption<Value: Sendable>(
level: NIOBSDSocket.OptionLevel,
name: NIOBSDSocket.Option,
value: Value
Expand All @@ -47,15 +47,18 @@ extension BaseSocketChannel: SocketOptionProvider {
}

#if !os(Windows)
func unsafeGetSocketOption<Value>(level: SocketOptionLevel, name: SocketOptionName) -> EventLoopFuture<Value> {
func unsafeGetSocketOption<Value: Sendable>(
level: SocketOptionLevel,
name: SocketOptionName
) -> EventLoopFuture<Value> {
unsafeGetSocketOption(
level: NIOBSDSocket.OptionLevel(rawValue: CInt(level)),
name: NIOBSDSocket.Option(rawValue: CInt(name))
)
}
#endif

func unsafeGetSocketOption<Value>(
func unsafeGetSocketOption<Value: Sendable>(
level: NIOBSDSocket.OptionLevel,
name: NIOBSDSocket.Option
) -> EventLoopFuture<Value> {
Expand Down
Loading