diff --git a/Sources/Subprocess/AsyncBufferSequence.swift b/Sources/Subprocess/AsyncBufferSequence.swift index fbdffbae..a63c1f40 100644 --- a/Sources/Subprocess/AsyncBufferSequence.swift +++ b/Sources/Subprocess/AsyncBufferSequence.swift @@ -16,7 +16,6 @@ import SystemPackage #endif #if !os(Windows) -internal import Dispatch #if SubprocessFoundation diff --git a/Sources/Subprocess/IO/AsyncIO+Windows.swift b/Sources/Subprocess/IO/AsyncIO+Windows.swift index adc6babd..da7877ec 100644 --- a/Sources/Subprocess/IO/AsyncIO+Windows.swift +++ b/Sources/Subprocess/IO/AsyncIO+Windows.swift @@ -21,7 +21,6 @@ import SystemPackage import _SubprocessCShims import Synchronization -internal import Dispatch @preconcurrency import WinSDK private typealias SignalStream = AsyncThrowingStream diff --git a/Sources/Subprocess/Platforms/Subprocess+Darwin.swift b/Sources/Subprocess/Platforms/Subprocess+Darwin.swift index b827876e..51e05b76 100644 --- a/Sources/Subprocess/Platforms/Subprocess+Darwin.swift +++ b/Sources/Subprocess/Platforms/Subprocess+Darwin.swift @@ -12,7 +12,6 @@ #if canImport(Darwin) public import Darwin -internal import Dispatch #if canImport(System) import System #else diff --git a/Sources/Subprocess/Platforms/Subprocess+Linux.swift b/Sources/Subprocess/Platforms/Subprocess+Linux.swift index 6024b7ba..86952a13 100644 --- a/Sources/Subprocess/Platforms/Subprocess+Linux.swift +++ b/Sources/Subprocess/Platforms/Subprocess+Linux.swift @@ -25,8 +25,6 @@ import Android import Musl #endif -internal import Dispatch - import Synchronization import _SubprocessCShims diff --git a/Sources/Subprocess/Platforms/Subprocess+Unix.swift b/Sources/Subprocess/Platforms/Subprocess+Unix.swift index 8881bbe6..86d143a6 100644 --- a/Sources/Subprocess/Platforms/Subprocess+Unix.swift +++ b/Sources/Subprocess/Platforms/Subprocess+Unix.swift @@ -29,8 +29,6 @@ public import Glibc public import Musl #endif -@preconcurrency internal import Dispatch - // MARK: - Signals /// Signals are standardized messages sent to a running program to diff --git a/Sources/Subprocess/Platforms/Subprocess+Windows.swift b/Sources/Subprocess/Platforms/Subprocess+Windows.swift index 85575c71..f77654de 100644 --- a/Sources/Subprocess/Platforms/Subprocess+Windows.swift +++ b/Sources/Subprocess/Platforms/Subprocess+Windows.swift @@ -12,7 +12,6 @@ #if canImport(WinSDK) @preconcurrency public import WinSDK -internal import Dispatch #if canImport(System) import System #else diff --git a/Sources/Subprocess/SubprocessFoundation/Input+Foundation.swift b/Sources/Subprocess/SubprocessFoundation/Input+Foundation.swift index 86f76e09..ccf64bd5 100644 --- a/Sources/Subprocess/SubprocessFoundation/Input+Foundation.swift +++ b/Sources/Subprocess/SubprocessFoundation/Input+Foundation.swift @@ -25,8 +25,6 @@ import System import SystemPackage #endif -internal import Dispatch - /// An input type that reads from a `Data` value. public struct DataInput: InputProtocol { private let data: Data diff --git a/Sources/Subprocess/SubprocessFoundation/Span+SubprocessFoundation.swift b/Sources/Subprocess/SubprocessFoundation/Span+SubprocessFoundation.swift index 94b131e0..e96e7ce4 100644 --- a/Sources/Subprocess/SubprocessFoundation/Span+SubprocessFoundation.swift +++ b/Sources/Subprocess/SubprocessFoundation/Span+SubprocessFoundation.swift @@ -19,8 +19,6 @@ import Foundation import FoundationEssentials #endif // canImport(Darwin) -internal import Dispatch - extension Data { init(_ s: borrowing RawSpan) { self = s.withUnsafeBytes { Data($0) } diff --git a/Sources/Subprocess/Thread.swift b/Sources/Subprocess/Thread.swift index 18f3b5bb..304fc378 100644 --- a/Sources/Subprocess/Thread.swift +++ b/Sources/Subprocess/Thread.swift @@ -22,7 +22,6 @@ import Musl import WinSDK #endif -internal import Dispatch import _SubprocessCShims #if canImport(Synchronization) diff --git a/Tests/SubprocessTests/AsyncIOTests.swift b/Tests/SubprocessTests/AsyncIOTests.swift index edbda831..db392c87 100644 --- a/Tests/SubprocessTests/AsyncIOTests.swift +++ b/Tests/SubprocessTests/AsyncIOTests.swift @@ -28,7 +28,6 @@ import WinSDK #endif import Testing -import Dispatch import Foundation import TestResources import _SubprocessCShims @@ -283,7 +282,7 @@ extension SubprocessAsyncIOTests { try await group.waitForAll() // Keep both pipe endpoints alive until both tasks complete, - // preventing the DispatchIO cleanup handler from closing + // preventing the cleanup handler from closing // a pipe fd while the other task is still using it. withExtendedLifetime((readTestBed, writeTestBed)) {} // Teardown diff --git a/Tests/SubprocessTests/DarwinTests.swift b/Tests/SubprocessTests/DarwinTests.swift index b59a8f3d..7bdbdeb4 100644 --- a/Tests/SubprocessTests/DarwinTests.swift +++ b/Tests/SubprocessTests/DarwinTests.swift @@ -101,38 +101,4 @@ struct SubprocessDarwinTests { } } -extension FileDescriptor { - internal func readUntilEOF(upToLength maxLength: Int) async throws -> Data { - return try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in - let dispatchIO = DispatchIO( - type: .stream, - fileDescriptor: self.rawValue, - queue: .global() - ) { error in - if error != 0 { - continuation.resume(throwing: POSIXError(.init(rawValue: error) ?? .ENODEV)) - } - } - var buffer: Data = Data() - dispatchIO.read( - offset: 0, - length: maxLength, - queue: .global() - ) { done, data, error in - guard error == 0 else { - continuation.resume(throwing: POSIXError(.init(rawValue: error) ?? .ENODEV)) - return - } - if let data = data { - buffer += Data(data) - } - if done { - dispatchIO.close() - continuation.resume(returning: buffer) - } - } - } - } -} - #endif // canImport(Darwin) diff --git a/Tests/SubprocessTests/IntegrationTests.swift b/Tests/SubprocessTests/IntegrationTests.swift index d87ff227..5bb5b77a 100644 --- a/Tests/SubprocessTests/IntegrationTests.swift +++ b/Tests/SubprocessTests/IntegrationTests.swift @@ -28,7 +28,6 @@ import WinSDK #endif import Testing -import Dispatch import Foundation import TestResources import _SubprocessCShims @@ -951,7 +950,7 @@ extension SubprocessIntegrationTests { contentsOf: URL(filePath: theMysteriousIsland.string) ) let stream: AsyncStream = AsyncStream { continuation in - DispatchQueue.global().async { + Task.detached { var currentStart = 0 while currentStart + chunkSize < expected.count { continuation.yield(expected[currentStart.. Data { - // TODO: Figure out a better way to asynchronously read - return try await withCheckedThrowingContinuation { continuation in - DispatchQueue.global(qos: .userInitiated).async { - var totalBytesRead: Int = 0 - var lastError: DWORD? = nil - let values = [UInt8]( - unsafeUninitializedCapacity: maxLength - ) { buffer, initializedCount in - while true { - guard let baseAddress = buffer.baseAddress else { - initializedCount = 0 - break - } - let bufferPtr = baseAddress.advanced(by: totalBytesRead) - var bytesRead: DWORD = 0 - let readSucceed = ReadFile( - self.platformDescriptor, - UnsafeMutableRawPointer(mutating: bufferPtr), - DWORD(maxLength - totalBytesRead), - &bytesRead, - nil - ) - if !readSucceed { - // Windows throws ERROR_BROKEN_PIPE when the pipe is closed - let error = GetLastError() - if error == ERROR_BROKEN_PIPE { - // We are done reading - initializedCount = totalBytesRead - } else { - // We got some error - lastError = error - initializedCount = 0 - } - break - } else { - // We successfully read the current round - totalBytesRead += Int(bytesRead) - } - - if totalBytesRead >= maxLength { - initializedCount = min(maxLength, totalBytesRead) - break - } - } - } - if let lastError = lastError { - let windowsError: SubprocessError = .failedToReadFromProcess( - withUnderlyingError: SubprocessError.WindowsError(rawValue: lastError) - ) - continuation.resume(throwing: windowsError) - } else { - continuation.resume(returning: Data(values)) - } - } - } - } -} - #endif // canImport(WinSDK)