From fe923bbbe6ee34eed575ebe534f4cf8c57d6357f Mon Sep 17 00:00:00 2001 From: Ali Ali Date: Tue, 15 Jul 2025 22:43:22 +1000 Subject: [PATCH] Make file handle sendable (#3300) Solve Issue-3295 ### Motivation: Solve https://github.com/apple/swift-nio/issues/3295 ### Modifications: Make a few objects send able. ### Result: WriteFileHandle will be sendable --------- Co-authored-by: George Barnett --- Sources/NIOFileSystem/FileHandle.swift | 8 ++++---- Sources/NIOFileSystem/Internal/SystemFileHandle.swift | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/NIOFileSystem/FileHandle.swift b/Sources/NIOFileSystem/FileHandle.swift index 287c7408b..3281a5d4f 100644 --- a/Sources/NIOFileSystem/FileHandle.swift +++ b/Sources/NIOFileSystem/FileHandle.swift @@ -95,7 +95,7 @@ extension _HasFileHandle { /// Implements ``FileHandleProtocol`` by making system calls to interact with the local file system. @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -public struct FileHandle: FileHandleProtocol { +public struct FileHandle: FileHandleProtocol, Sendable { internal let systemFileHandle: SystemFileHandle internal init(wrapping handle: SystemFileHandle) { @@ -171,7 +171,7 @@ public struct FileHandle: FileHandleProtocol { /// Implements ``ReadableFileHandleProtocol`` by making system calls to interact with the local /// file system. @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -public struct ReadFileHandle: ReadableFileHandleProtocol, _HasFileHandle { +public struct ReadFileHandle: ReadableFileHandleProtocol, _HasFileHandle, Sendable { public let fileHandle: FileHandle internal init(wrapping systemFileHandle: SystemFileHandle) { @@ -206,7 +206,7 @@ public struct ReadFileHandle: ReadableFileHandleProtocol, _HasFileHandle { /// Implements ``WritableFileHandleProtocol`` by making system calls to interact with the local /// file system. @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -public struct WriteFileHandle: WritableFileHandleProtocol, _HasFileHandle { +public struct WriteFileHandle: WritableFileHandleProtocol, _HasFileHandle, Sendable { public let fileHandle: FileHandle internal init(wrapping systemFileHandle: SystemFileHandle) { @@ -300,7 +300,7 @@ public struct ReadWriteFileHandle: ReadableAndWritableFileHandleProtocol, _HasFi /// Implements ``DirectoryFileHandleProtocol`` by making system calls to interact with the local /// file system. @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -public struct DirectoryFileHandle: DirectoryFileHandleProtocol, _HasFileHandle { +public struct DirectoryFileHandle: DirectoryFileHandleProtocol, _HasFileHandle, Sendable { public let fileHandle: FileHandle internal init(wrapping systemFileHandle: SystemFileHandle) { diff --git a/Sources/NIOFileSystem/Internal/SystemFileHandle.swift b/Sources/NIOFileSystem/Internal/SystemFileHandle.swift index c525d59ce..53d35f88d 100644 --- a/Sources/NIOFileSystem/Internal/SystemFileHandle.swift +++ b/Sources/NIOFileSystem/Internal/SystemFileHandle.swift @@ -33,7 +33,7 @@ import CNIOLinux /// descriptor. @_spi(Testing) @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -public final class SystemFileHandle { +public final class SystemFileHandle: Sendable { /// The executor on which to execute system calls. internal var threadPool: NIOThreadPool { self.sendableView.threadPool }