Skip to content

Commit 0450bd9

Browse files
committed
Revert "Use SocketPair"
This reverts commit 5077225.
1 parent 07fea99 commit 0450bd9

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

Sources/ShellOut.swift

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,9 @@ private extension Process {
453453
self.environment = environment
454454
}
455455

456-
let outputPipe = SocketPair()
457-
let errorPipe = SocketPair()
458-
self.standardOutput = outputPipe.fileHandleForWriting
459-
self.standardError = errorPipe.fileHandleForWriting
456+
let outputPipe = Pipe(), errorPipe = Pipe()
457+
self.standardOutput = outputPipe
458+
self.standardError = errorPipe
460459

461460
// Because FileHandle's readabilityHandler might be called from a
462461
// different queue from the calling queue, avoid data races by
@@ -655,30 +654,3 @@ private extension String {
655654
self = appending(arguments: arguments)
656655
}
657656
}
658-
659-
660-
final class SocketPair {
661-
let fileHandleForReading: FileHandle
662-
let fileHandleForWriting: FileHandle
663-
664-
init() {
665-
let fds = UnsafeMutablePointer<Int32>.allocate(capacity: 2)
666-
defer { fds.deallocate() }
667-
668-
#if os(macOS)
669-
let ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds)
670-
#else
671-
let ret = socketpair(AF_UNIX, Int32(SOCK_STREAM.rawValue), 0, fds)
672-
#endif
673-
switch (ret, errno) {
674-
case (0, _):
675-
self.fileHandleForReading = FileHandle(fileDescriptor: fds.pointee, closeOnDealloc: true)
676-
self.fileHandleForWriting = FileHandle(fileDescriptor: fds.successor().pointee, closeOnDealloc: true)
677-
case (-1, EMFILE), (-1, ENFILE):
678-
self.fileHandleForReading = FileHandle(fileDescriptor: -1, closeOnDealloc: false)
679-
self.fileHandleForWriting = FileHandle(fileDescriptor: -1, closeOnDealloc: false)
680-
default:
681-
fatalError("Error calling socketpair(): \(errno)")
682-
}
683-
}
684-
}

0 commit comments

Comments
 (0)