@@ -101,7 +101,7 @@ public struct Configuration: Sendable {
101101 // Body runs in the same isolation
102102 let result = try await body (
103103 execution,
104- . init( fileDescriptor : execution. inputPipe. writeFileDescriptor !)
104+ . init( diskIO : execution. inputPipe. writeEnd !)
105105 )
106106 return ExecutionResult (
107107 terminationStatus: try await waitingStatus,
@@ -165,7 +165,7 @@ public struct Configuration: Sendable {
165165 standardError
166166 ) = try await execution. captureIOs ( )
167167 // Write input in the same scope
168- guard let writeFd = execution. inputPipe. writeFileDescriptor else {
168+ guard let writeFd = execution. inputPipe. writeEnd else {
169169 fatalError ( " Trying to write to an input that has been closed " )
170170 }
171171 try await withCheckedThrowingContinuation { ( continuation: CheckedContinuation < Void , any Swift . Error > ) in
@@ -256,8 +256,8 @@ public struct Configuration: Sendable {
256256 returning: ExecutionResult . self
257257 ) { group in
258258 group. addTask {
259- if let writeFd = execution. inputPipe. writeFileDescriptor {
260- let writer = StandardInputWriter ( fileDescriptor : writeFd)
259+ if let writeFd = execution. inputPipe. writeEnd {
260+ let writer = StandardInputWriter ( diskIO : writeFd)
261261 try await input. write ( with: writer)
262262 try await writer. finish ( )
263263 }
@@ -363,25 +363,25 @@ extension Configuration {
363363
364364 if childSide {
365365 inputError = captureError {
366- try execution. inputPipe. readFileDescriptor ? . safelyClose ( )
366+ try execution. inputPipe. readEnd ? . safelyClose ( )
367367 }
368368 outputError = captureError {
369- try execution. outputPipe. writeFileDescriptor ? . safelyClose ( )
369+ try execution. outputPipe. writeEnd ? . safelyClose ( )
370370 }
371371 errorError = captureError {
372- try execution. errorPipe. writeFileDescriptor ? . safelyClose ( )
372+ try execution. errorPipe. writeEnd ? . safelyClose ( )
373373 }
374374 }
375375
376376 if parentSide {
377377 inputError = captureError {
378- try execution. inputPipe. writeFileDescriptor ? . safelyClose ( )
378+ try execution. inputPipe. writeEnd ? . safelyClose ( )
379379 }
380380 outputError = captureError {
381- try execution. outputPipe. readFileDescriptor ? . safelyClose ( )
381+ try execution. outputPipe. readEnd ? . safelyClose ( )
382382 }
383383 errorError = captureError {
384- try execution. errorPipe. readFileDescriptor ? . safelyClose ( )
384+ try execution. errorPipe. readEnd ? . safelyClose ( )
385385 }
386386 }
387387
@@ -801,51 +801,27 @@ internal enum StringOrRawBytes: Sendable, Hashable {
801801 }
802802}
803803
804- /// A wrapped `FileDescriptor` or `DispatchIO` and
805- /// whether it should beeddsw closed automactially when done.
806- internal struct DiskIO {
807- internal enum Storage {
808- case fileDescriptor( FileDescriptor )
809- #if !os(Windows) // Darwin and Linux
810- case dispatchIO( DispatchIO )
811- #endif
812- }
813-
804+ /// A wrapped `FileDescriptor` and whether it should be closed
805+ /// automactially when done.
806+ internal struct TrackedFileDescriptor {
814807 internal let closeWhenDone : Bool
815- internal let storage : Storage
808+ internal let fileDescriptor : FileDescriptor
816809
817810 internal init (
818811 _ fileDescriptor: FileDescriptor ,
819812 closeWhenDone: Bool
820813 ) {
821- self . storage = . fileDescriptor( fileDescriptor)
822- self . closeWhenDone = closeWhenDone
823- }
824-
825- #if !os(Windows)
826- internal init (
827- _ dispatchIO: DispatchIO ,
828- closeWhenDone: Bool
829- ) {
830- self . storage = . dispatchIO( dispatchIO)
814+ self . fileDescriptor = fileDescriptor
831815 self . closeWhenDone = closeWhenDone
832816 }
833- #endif
834817
835818 internal func safelyClose( ) throws {
836819 guard self . closeWhenDone else {
837820 return
838821 }
839822
840823 do {
841- switch self . storage {
842- case . fileDescriptor( let fileDescriptor) :
843- try fileDescriptor. close ( )
844- #if !os(Windows)
845- case . dispatchIO( let dispatchIO) :
846- dispatchIO. close ( )
847- #endif
848- }
824+ try fileDescriptor. close ( )
849825 } catch {
850826 guard let errno: Errno = error as? Errno else {
851827 throw error
@@ -857,38 +833,52 @@ internal struct DiskIO {
857833 }
858834
859835 internal var platformDescriptor : PlatformFileDescriptor {
860- switch self . storage {
861- case . fileDescriptor( let fileDescriptor) :
862- return fileDescriptor. platformDescriptor
863- #if !os(Windows)
864- case . dispatchIO( let dispatchIO) :
865- return dispatchIO. fileDescriptor
866- #endif // !os(Windows)
867- }
836+ return self . fileDescriptor. platformDescriptor
868837 }
869838}
870839
871- internal struct CreatedPipe {
872- internal enum PipeEnd {
873- case readEnd
874- case writeEnd
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
875853 }
876854
877- internal let readFileDescriptor : DiskIO ?
878- internal let writeFileDescriptor : DiskIO ?
879- internal let parentEnd : PipeEnd
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
865+ }
866+ }
867+ #endif
868+
869+ internal struct CreatedPipe {
870+ internal let readFileDescriptor : TrackedFileDescriptor ?
871+ internal let writeFileDescriptor : TrackedFileDescriptor ?
880872
881873 internal init (
882- readFileDescriptor: DiskIO ? ,
883- writeFileDescriptor: DiskIO ? ,
884- parentEnd: PipeEnd
874+ readFileDescriptor: TrackedFileDescriptor ? ,
875+ writeFileDescriptor: TrackedFileDescriptor ? ,
885876 ) {
886877 self . readFileDescriptor = readFileDescriptor
887878 self . writeFileDescriptor = writeFileDescriptor
888- self . parentEnd = parentEnd
889879 }
890880
891- internal init ( closeWhenDone: Bool , parentEnd : PipeEnd ) throws {
881+ internal init ( closeWhenDone: Bool ) throws {
892882 let pipe = try FileDescriptor . ssp_pipe ( )
893883 self . readFileDescriptor = . init(
894884 pipe. readEnd,
@@ -898,7 +888,6 @@ internal struct CreatedPipe {
898888 pipe. writeEnd,
899889 closeWhenDone: closeWhenDone
900890 )
901- self . parentEnd = parentEnd
902891 }
903892}
904893
0 commit comments