Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

692 B
Raw Blame
#if os(macOS)
import Foundation
import Darwin

/// Blocking pipe input for the helper's dedicated reader queue. A short read
/// must return immediately: Foundation read(upToCount:) can wait for a full
/// buffer or EOF on macOS, deadlocking a request/reply pipe kept open by Main.
public enum CredentialPipeInput {
  public static func readChunk(from descriptor: Int32) throws -> Data? {
    var bytes = [UInt8](repeating: 0, count: 8192)
    while true {
      let count = Darwin.read(descriptor, &bytes, bytes.count)
      if count > 0 { return Data(bytes.prefix(count)) }
      if count == 0 { return nil }
      if errno != EINTR { throw CredentialError.unavailable }
    }
  }
}
#endif