@@ -90,9 +90,6 @@ public struct Configuration: Sendable {
9090 // After spawn, cleanup child side fds
9191 try await self . cleanup (
9292 execution: execution,
93- inputPipe: inputPipe,
94- outputPipe: outputPipe,
95- errorPipe: errorPipe,
9693 childSide: true ,
9794 parentSide: false ,
9895 attemptToTerminateSubProcess: false
@@ -104,7 +101,7 @@ public struct Configuration: Sendable {
104101 // Body runs in the same isolation
105102 let result = try await body (
106103 execution,
107- . init( fileDescriptor : inputPipe. writeFileDescriptor !)
104+ . init( diskIO : execution . inputPipe. writeEnd !)
108105 )
109106 return ExecutionResult (
110107 terminationStatus: try await waitingStatus,
@@ -116,9 +113,6 @@ public struct Configuration: Sendable {
116113 // this is the best we can do
117114 try ? await self . cleanup (
118115 execution: execution,
119- inputPipe: inputPipe,
120- outputPipe: outputPipe,
121- errorPipe: errorPipe,
122116 childSide: false ,
123117 parentSide: true ,
124118 attemptToTerminateSubProcess: true
@@ -154,9 +148,6 @@ public struct Configuration: Sendable {
154148 // After spawn, clean up child side
155149 try await self . cleanup (
156150 execution: execution,
157- inputPipe: inputPipe,
158- outputPipe: outputPipe,
159- errorPipe: errorPipe,
160151 childSide: true ,
161152 parentSide: false ,
162153 attemptToTerminateSubProcess: false
@@ -174,7 +165,7 @@ public struct Configuration: Sendable {
174165 standardError
175166 ) = try await execution. captureIOs ( )
176167 // Write input in the same scope
177- guard let writeFd = inputPipe. writeFileDescriptor else {
168+ guard let writeFd = execution . inputPipe. writeEnd else {
178169 fatalError ( " Trying to write to an input that has been closed " )
179170 }
180171 try await withCheckedThrowingContinuation { ( continuation: CheckedContinuation < Void , any Swift . Error > ) in
@@ -193,7 +184,7 @@ public struct Configuration: Sendable {
193184 )
194185 #endif
195186
196- writeFd. wrapped . write ( bytes) { _, error in
187+ writeFd. write ( bytes) { _, error in
197188 if let error = error {
198189 continuation. resume ( throwing: error)
199190 } else {
@@ -216,9 +207,6 @@ public struct Configuration: Sendable {
216207 // this is the best we can do
217208 try ? await self . cleanup (
218209 execution: execution,
219- inputPipe: inputPipe,
220- outputPipe: outputPipe,
221- errorPipe: errorPipe,
222210 childSide: false ,
223211 parentSide: true ,
224212 attemptToTerminateSubProcess: true
@@ -257,9 +245,6 @@ public struct Configuration: Sendable {
257245 // After spawn, clean up child side
258246 try await self . cleanup (
259247 execution: execution,
260- inputPipe: inputPipe,
261- outputPipe: outputPipe,
262- errorPipe: errorPipe,
263248 childSide: true ,
264249 parentSide: false ,
265250 attemptToTerminateSubProcess: false
@@ -271,8 +256,8 @@ public struct Configuration: Sendable {
271256 returning: ExecutionResult . self
272257 ) { group in
273258 group. addTask {
274- if let writeFd = inputPipe. writeFileDescriptor {
275- let writer = StandardInputWriter ( fileDescriptor : writeFd)
259+ if let writeFd = execution . inputPipe. writeEnd {
260+ let writer = StandardInputWriter ( diskIO : writeFd)
276261 try await input. write ( with: writer)
277262 try await writer. finish ( )
278263 }
@@ -300,9 +285,6 @@ public struct Configuration: Sendable {
300285 // this is the best we can do
301286 try ? await self . cleanup (
302287 execution: execution,
303- inputPipe: inputPipe,
304- outputPipe: outputPipe,
305- errorPipe: errorPipe,
306288 childSide: false ,
307289 parentSide: true ,
308290 attemptToTerminateSubProcess: true
@@ -350,9 +332,6 @@ extension Configuration {
350332 Error: OutputProtocol
351333 > (
352334 execution: Execution < Output , Error > ,
353- inputPipe: CreatedPipe ,
354- outputPipe: CreatedPipe ,
355- errorPipe: CreatedPipe ,
356335 childSide: Bool ,
357336 parentSide: Bool ,
358337 attemptToTerminateSubProcess: Bool
@@ -384,25 +363,25 @@ extension Configuration {
384363
385364 if childSide {
386365 inputError = captureError {
387- try inputPipe. readFileDescriptor ? . safelyClose ( )
366+ try execution . inputPipe. readEnd ? . safelyClose ( )
388367 }
389368 outputError = captureError {
390- try outputPipe. writeFileDescriptor ? . safelyClose ( )
369+ try execution . outputPipe. writeEnd ? . safelyClose ( )
391370 }
392371 errorError = captureError {
393- try errorPipe. writeFileDescriptor ? . safelyClose ( )
372+ try execution . errorPipe. writeEnd ? . safelyClose ( )
394373 }
395374 }
396375
397376 if parentSide {
398377 inputError = captureError {
399- try inputPipe. writeFileDescriptor ? . safelyClose ( )
378+ try execution . inputPipe. writeEnd ? . safelyClose ( )
400379 }
401380 outputError = captureError {
402- try outputPipe. readFileDescriptor ? . safelyClose ( )
381+ try execution . outputPipe. readEnd ? . safelyClose ( )
403382 }
404383 errorError = captureError {
405- try errorPipe. readFileDescriptor ? . safelyClose ( )
384+ try execution . errorPipe. readEnd ? . safelyClose ( )
406385 }
407386 }
408387
@@ -822,17 +801,17 @@ internal enum StringOrRawBytes: Sendable, Hashable {
822801 }
823802}
824803
825- /// A simple wrapper on `FileDescriptor` plus a flag indicating
826- /// whether it should be closed automactially when done.
827- internal struct TrackedFileDescriptor : Hashable {
804+ /// A wrapped `FileDescriptor` and whether it should be closed
805+ /// automactially when done.
806+ internal struct TrackedFileDescriptor {
828807 internal let closeWhenDone : Bool
829- internal let wrapped : FileDescriptor
808+ internal let fileDescriptor : FileDescriptor
830809
831810 internal init (
832- _ wrapped : FileDescriptor ,
811+ _ fileDescriptor : FileDescriptor ,
833812 closeWhenDone: Bool
834813 ) {
835- self . wrapped = wrapped
814+ self . fileDescriptor = fileDescriptor
836815 self . closeWhenDone = closeWhenDone
837816 }
838817
@@ -842,7 +821,7 @@ internal struct TrackedFileDescriptor: Hashable {
842821 }
843822
844823 do {
845- try self . wrapped . close ( )
824+ try fileDescriptor . close ( )
846825 } catch {
847826 guard let errno: Errno = error as? Errno else {
848827 throw error
@@ -854,25 +833,53 @@ internal struct TrackedFileDescriptor: Hashable {
854833 }
855834
856835 internal var platformDescriptor : PlatformFileDescriptor {
857- return self . wrapped. platformDescriptor
836+ return self . fileDescriptor. platformDescriptor
837+ }
838+ }
839+
840+ #if !os(Windows)
841+ /// A wrapped `DispatchIO` and whether it should be closed
842+ /// automactially when done.
843+ internal struct TrackedDispatchIO {
844+ internal let closeWhenDone : Bool
845+ internal let dispatchIO : DispatchIO
846+
847+ internal init (
848+ _ dispatchIO: DispatchIO ,
849+ closeWhenDone: Bool
850+ ) {
851+ self . dispatchIO = dispatchIO
852+ self . closeWhenDone = closeWhenDone
853+ }
854+
855+ internal func safelyClose( ) throws {
856+ guard self . closeWhenDone else {
857+ return
858+ }
859+
860+ dispatchIO. close ( )
861+ }
862+
863+ internal var platformDescriptor : PlatformFileDescriptor {
864+ return self . dispatchIO. fileDescriptor
858865 }
859866}
867+ #endif
860868
861869internal struct CreatedPipe {
862870 internal let readFileDescriptor : TrackedFileDescriptor ?
863871 internal let writeFileDescriptor : TrackedFileDescriptor ?
864872
865873 internal init (
866874 readFileDescriptor: TrackedFileDescriptor ? ,
867- writeFileDescriptor: TrackedFileDescriptor ?
875+ writeFileDescriptor: TrackedFileDescriptor ? ,
868876 ) {
869877 self . readFileDescriptor = readFileDescriptor
870878 self . writeFileDescriptor = writeFileDescriptor
871879 }
872880
873881 internal init ( closeWhenDone: Bool ) throws {
874882 let pipe = try FileDescriptor . ssp_pipe ( )
875-
876883 self . readFileDescriptor = . init(
877884 pipe. readEnd,
878885 closeWhenDone: closeWhenDone
0 commit comments