Skip to content

Commit 0ef16cf

Browse files
committed
Use CreatedPipe to create the pipes so that the handles are compatible with CreateIoCompletionPort
1 parent 6d247b6 commit 0ef16cf

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Sources/Subprocess/PipeConfiguration.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ extension PipeConfiguration {
425425
/// Run the pipeline using withTaskGroup
426426
private func runPipeline() async throws -> CollectedResult<Output, Error> {
427427
// Create a pipe for standard error
428-
let sharedErrorPipe = try FileDescriptor.pipe()
428+
var sharedErrorCreatedPipe = try CreatedPipe(closeWhenDone: false, purpose: .output)
429+
let sharedErrorPipe = (readEnd: FileDescriptor(rawValue: sharedErrorCreatedPipe.readFileDescriptor()!.platformDescriptor()), writeEnd: FileDescriptor(rawValue: sharedErrorCreatedPipe.writeFileDescriptor()!.platformDescriptor()))
429430

430431
return try await withThrowingTaskGroup(of: CollectedPipeResult.self, returning: CollectedResult<Output, Error>.self) { group in
431432
// Collect error output from all stages
@@ -443,8 +444,8 @@ extension PipeConfiguration {
443444
// Create pipes between stages
444445
var pipes: [(readEnd: FileDescriptor, writeEnd: FileDescriptor)] = []
445446
for _ in 0..<(stages.count - 1) {
446-
let pipe = try FileDescriptor.pipe()
447-
pipes.append((readEnd: pipe.readEnd, writeEnd: pipe.writeEnd))
447+
var pipe = try CreatedPipe(closeWhenDone: false, purpose: .input)
448+
pipes.append((readEnd: FileDescriptor(rawValue: pipe.readFileDescriptor()!.platformDescriptor()), writeEnd: FileDescriptor(rawValue: pipe.writeFileDescriptor()!.platformDescriptor())))
448449
}
449450

450451
let pipeResult = try await withThrowingTaskGroup(of: PipelineTaskResult.self, returning: CollectedResult<Output, DiscardedOutput>.self) { group in

Tests/SubprocessTests/PipeConfigurationTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,14 @@ struct PipeConfigurationTests {
413413
@Test func testPipeOperatorWithProcessHelper() async throws {
414414
let pipeline =
415415
pipe(
416-
configuration: Echo("""
416+
configuration: Echo(
417+
"""
417418
apple
418419
banana
419420
cherry
420421
date
421-
""").configuration
422+
"""
423+
).configuration
422424
)
423425
| Head("-3").configuration
424426
| Wc("-l").configuration

0 commit comments

Comments
 (0)