@@ -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
@@ -802,50 +802,26 @@ internal enum StringOrRawBytes: Sendable, Hashable {
802802} 
803803
804804/// 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- 
805+ /// whether it should be closed 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,50 @@ 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+ internal struct  TrackedDispatchIO  { 
842+     internal  let  closeWhenDone :  Bool 
843+     internal  let  dispatchIO :  DispatchIO 
844+ 
845+     internal  init ( 
846+         _ dispatchIO:  DispatchIO , 
847+         closeWhenDone:  Bool 
848+     )  { 
849+         self . dispatchIO =  dispatchIO
850+         self . closeWhenDone =  closeWhenDone
875851    } 
876852
877-     internal  let  readFileDescriptor :  DiskIO ? 
878-     internal  let  writeFileDescriptor :  DiskIO ? 
879-     internal  let  parentEnd :  PipeEnd 
853+     internal  func  safelyClose( )  throws  { 
854+         guard  self . closeWhenDone else  { 
855+             return 
856+         } 
857+ 
858+         dispatchIO. close ( ) 
859+     } 
860+ 
861+     internal  var  platformDescriptor :  PlatformFileDescriptor  { 
862+         return  self . dispatchIO. fileDescriptor
863+     } 
864+ } 
865+ #endif 
866+ 
867+ internal struct  CreatedPipe  { 
868+     internal  let  readFileDescriptor :  TrackedFileDescriptor ? 
869+     internal  let  writeFileDescriptor :  TrackedFileDescriptor ? 
880870
881871    internal  init ( 
882-         readFileDescriptor:  DiskIO ? , 
883-         writeFileDescriptor:  DiskIO ? , 
884-         parentEnd:  PipeEnd 
872+         readFileDescriptor:  TrackedFileDescriptor ? , 
873+         writeFileDescriptor:  TrackedFileDescriptor ? , 
885874    )  { 
886875        self . readFileDescriptor =  readFileDescriptor
887876        self . writeFileDescriptor =  writeFileDescriptor
888-         self . parentEnd =  parentEnd
889877    } 
890878
891-     internal  init ( closeWhenDone:  Bool ,  parentEnd :   PipeEnd )  throws  { 
879+     internal  init ( closeWhenDone:  Bool )  throws  { 
892880        let  pipe  =  try   FileDescriptor . ssp_pipe ( ) 
893881        self . readFileDescriptor =  . init( 
894882            pipe. readEnd, 
@@ -898,7 +886,6 @@ internal struct CreatedPipe {
898886            pipe. writeEnd, 
899887            closeWhenDone:  closeWhenDone
900888        ) 
901-         self . parentEnd =  parentEnd
902889    } 
903890} 
904891
0 commit comments