I am using CFMessagePort for interprocess communication in AppKit-based application and adding CFMessagePort source to the current run loop.
CFMessagePortRef local = CFMessagePortCreateLocal( kCFAllocatorDefault, daemonHostName,didReceiveDataFromOtherProcess, NULL,false);
if (local) {
CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(NULL, local, 0);
CFRunLoopRef rl = [[NSRunLoop mainRunLoop] getCFRunLoop];
CFRunLoopAddSource(rl, source, kCFRunLoopDefaultMode);
}
- Is this is right approach?
- Should i run runloop using
CFRunLoopRun()? - Is this will affect my main application operations(if client will
send message in every 1second)?
I don’t see anything wrong with it.
I take it from your comment that you are using the main run loop, which is run automatically, so the answer is No. If you did not create the run loop, you most definitely don’t need to run it.
One time per second is not a problem at all. However if
didReceiveDataFromOtherProcess()callback takes significant time to run, your interface will be less responsive. In that case, creating a secondary thread with its own run loop will help. If you’re not sure, dont worry about this problem until you have it.P.S. You should release the source after adding it, because it has been retained by the run loop.