@@ -101,7 +101,7 @@ public struct Configuration: Sendable {
101
101
// Body runs in the same isolation
102
102
let result = try await body (
103
103
execution,
104
- . init( fileDescriptor : execution. inputPipe. writeFileDescriptor !)
104
+ . init( diskIO : execution. inputPipe. writeEnd !)
105
105
)
106
106
return ExecutionResult (
107
107
terminationStatus: try await waitingStatus,
@@ -165,7 +165,7 @@ public struct Configuration: Sendable {
165
165
standardError
166
166
) = try await execution. captureIOs ( )
167
167
// Write input in the same scope
168
- guard let writeFd = execution. inputPipe. writeFileDescriptor else {
168
+ guard let writeFd = execution. inputPipe. writeEnd else {
169
169
fatalError ( " Trying to write to an input that has been closed " )
170
170
}
171
171
try await withCheckedThrowingContinuation { ( continuation: CheckedContinuation < Void , any Swift . Error > ) in
@@ -256,8 +256,8 @@ public struct Configuration: Sendable {
256
256
returning: ExecutionResult . self
257
257
) { group in
258
258
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)
261
261
try await input. write ( with: writer)
262
262
try await writer. finish ( )
263
263
}
@@ -363,25 +363,25 @@ extension Configuration {
363
363
364
364
if childSide {
365
365
inputError = captureError {
366
- try execution. inputPipe. readFileDescriptor ? . safelyClose ( )
366
+ try execution. inputPipe. readEnd ? . safelyClose ( )
367
367
}
368
368
outputError = captureError {
369
- try execution. outputPipe. writeFileDescriptor ? . safelyClose ( )
369
+ try execution. outputPipe. writeEnd ? . safelyClose ( )
370
370
}
371
371
errorError = captureError {
372
- try execution. errorPipe. writeFileDescriptor ? . safelyClose ( )
372
+ try execution. errorPipe. writeEnd ? . safelyClose ( )
373
373
}
374
374
}
375
375
376
376
if parentSide {
377
377
inputError = captureError {
378
- try execution. inputPipe. writeFileDescriptor ? . safelyClose ( )
378
+ try execution. inputPipe. writeEnd ? . safelyClose ( )
379
379
}
380
380
outputError = captureError {
381
- try execution. outputPipe. readFileDescriptor ? . safelyClose ( )
381
+ try execution. outputPipe. readEnd ? . safelyClose ( )
382
382
}
383
383
errorError = captureError {
384
- try execution. errorPipe. readFileDescriptor ? . safelyClose ( )
384
+ try execution. errorPipe. readEnd ? . safelyClose ( )
385
385
}
386
386
}
387
387
@@ -801,51 +801,27 @@ internal enum StringOrRawBytes: Sendable, Hashable {
801
801
}
802
802
}
803
803
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 {
814
807
internal let closeWhenDone : Bool
815
- internal let storage : Storage
808
+ internal let fileDescriptor : FileDescriptor
816
809
817
810
internal init (
818
811
_ fileDescriptor: FileDescriptor ,
819
812
closeWhenDone: Bool
820
813
) {
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
831
815
self . closeWhenDone = closeWhenDone
832
816
}
833
- #endif
834
817
835
818
internal func safelyClose( ) throws {
836
819
guard self . closeWhenDone else {
837
820
return
838
821
}
839
822
840
823
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 ( )
849
825
} catch {
850
826
guard let errno: Errno = error as? Errno else {
851
827
throw error
@@ -857,38 +833,52 @@ internal struct DiskIO {
857
833
}
858
834
859
835
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
868
837
}
869
838
}
870
839
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
875
853
}
876
854
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 ?
880
872
881
873
internal init (
882
- readFileDescriptor: DiskIO ? ,
883
- writeFileDescriptor: DiskIO ? ,
884
- parentEnd: PipeEnd
874
+ readFileDescriptor: TrackedFileDescriptor ? ,
875
+ writeFileDescriptor: TrackedFileDescriptor ? ,
885
876
) {
886
877
self . readFileDescriptor = readFileDescriptor
887
878
self . writeFileDescriptor = writeFileDescriptor
888
- self . parentEnd = parentEnd
889
879
}
890
880
891
- internal init ( closeWhenDone: Bool , parentEnd : PipeEnd ) throws {
881
+ internal init ( closeWhenDone: Bool ) throws {
892
882
let pipe = try FileDescriptor . ssp_pipe ( )
893
883
self . readFileDescriptor = . init(
894
884
pipe. readEnd,
@@ -898,7 +888,6 @@ internal struct CreatedPipe {
898
888
pipe. writeEnd,
899
889
closeWhenDone: closeWhenDone
900
890
)
901
- self . parentEnd = parentEnd
902
891
}
903
892
}
904
893
0 commit comments