在Cocoa中没有特殊的方法.你基本上会创建fifo,一旦你拥有了它,你的进程就可以使用标准的Cocoa包装器读取/写入它NSFileHandle.你可以检查它的存在NSFileManager与否,但你仍然需要mkfifo(2)在某个时候调用来创建命名管道.
所以:
if( mkfifo("/tmp/my_named_pipe", 0644) == -1 ) {
// some error handling
abort();
}
// Open and use the fifo as you would any file in Cocoa, but remember that it's a FIFO
NSFileHandle* fifoIN = [NSFileHandle fileForReadingAtPath:@"/tmp/my_named_pipe"];
Run Code Online (Sandbox Code Playgroud)
就个人而言,我建议使用BSD或Unix套接字.对套接字有很多框架支持,有时双向通道也更有用,你不必担心读者或作者是否已经准备好了.