Named Pipes using mkfifo and Cocoa

I have a C++ application that uses named pipes by calling mkfifo and I would like to use them to connect to a Cocoa app. I have taken a look at NSPipe but there isn't an option to connect to a named pipe. Does anyone know how to connect NSPipes or something else I can tie into the NSNotificationCenter that can talk to named pipes?

Thank you for your time,

Tom

Mac Pro, Mac OS X (10.5.4)

Posted on Aug 21, 2008 6:32 PM

Reply
1 reply

Aug 22, 2008 2:21 PM in response to tdesrochers

-(void)SomeFunc
{
const char * path = "/tmp/tom21";
if(mkfifo(path, 0666) == -1 && errno !=EEXIST){
NSLog(@"Unable to open the named pipe %c", path);
}

NSFileHandle * filehandleForReading;
int fd = open(path, O_RDWR | O_NDELAY);
filehandleForReading = [[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc: YES];

NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self];
[nc addObserver:self
selector:@selector(dataReady:)
name:NSFileHandleReadCompletionNotification
object:filehandleForReading];
[filehandleForReading readInBackgroundAndNotify];
}

And then here is the func that gets called by the Notification server

- (void)dataReady:(NSNotification *)n
{
NSData *d;
d = [[n userInfo] valueForKey:NSFileHandleNotificationDataItem];


NSLog(@"dataReady:%d bytes", [d length]);

if ([d length]) {
[self appendData:d];
}

//Tell the fileHandler to asychronusly report back
[filehandleForReading readInBackgroundAndNotify];
}

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Named Pipes using mkfifo and Cocoa

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.