@@ -517,8 +517,7 @@ class _SignalHelperRunner {
517
517
let semaphore = DispatchSemaphore ( value: 0 )
518
518
519
519
private let outputPipe = Pipe ( )
520
- private let sQueue = DispatchQueue ( label: " io queue " )
521
- private let source : DispatchSourceRead
520
+ private let sQueue = DispatchQueue ( label: " signal queue " )
522
521
523
522
private var gotReady = false
524
523
private var bytesIn = Data ( )
@@ -534,17 +533,16 @@ class _SignalHelperRunner {
534
533
process. arguments = [ " --signal-test " ]
535
534
process. standardOutput = outputPipe. fileHandleForWriting
536
535
537
- source = DispatchSource . makeReadSource ( fileDescriptor: outputPipe. fileHandleForReading. fileDescriptor, queue: sQueue)
538
- let workItem = DispatchWorkItem ( block: { [ weak self] in
536
+ outputPipe. fileHandleForReading. readabilityHandler = { [ weak self] fh in
539
537
if let strongSelf = self {
540
538
let newLine = UInt8 ( ascii: " \n " )
541
539
542
- strongSelf. bytesIn. append ( strongSelf . outputPipe . fileHandleForReading . availableData)
540
+ strongSelf. bytesIn. append ( fh . availableData)
543
541
if strongSelf. bytesIn. isEmpty {
544
542
return
545
543
}
546
544
// Split the incoming data into lines.
547
- while let index = strongSelf. bytesIn. index ( of: newLine) {
545
+ while let index = strongSelf. bytesIn. firstIndex ( of: newLine) {
548
546
if index >= strongSelf. bytesIn. startIndex {
549
547
// dont include the newline when converting to string
550
548
let line = String ( data: strongSelf. bytesIn [ strongSelf. bytesIn. startIndex..< index] , encoding: String . Encoding. utf8) ?? " "
@@ -567,18 +565,15 @@ class _SignalHelperRunner {
567
565
}
568
566
}
569
567
}
570
- } )
571
- source. setEventHandler ( handler: workItem)
568
+ }
572
569
}
573
570
574
571
deinit {
575
- source. cancel ( )
576
572
process. terminate ( )
577
573
process. waitUntilExit ( )
578
574
}
579
575
580
576
func start( ) throws {
581
- source. resume ( )
582
577
try process. run ( )
583
578
}
584
579
0 commit comments