Conceptual help with CFMessagePort/NSMessagePort
Conceptual help with CFMessagePort/NSMessagePort
- Subject: Conceptual help with CFMessagePort/NSMessagePort
- From: James Bucanek <email@hidden>
- Date: Sun, 24 Apr 2005 15:54:53 -0700
I thought this was going to be easy, but apparently it isn't. Or it's really easy, and I'm just trying to make it hard. ;)
I was about to write a Cocoa application that communicates with a helper app (an SUID daemon, also written in Obj-C). I need to launch the daemon and establish a communications link, send it commands, and get back status. In some cases, I need to be able to quit the GUI app and let the daemon continue to run, then re-establish a communications link when the GUI is started again to check on progress.
I initially thought I would do this with Mach ports. But all of the documentation says, essentially, that Mach ports are too hard to use and prone to change from one OS to the next. One should use the higher-level CFPort/NSPort or CFMessagePort/NSMessagePort classes. Fair enough....
Now I'm stumped. All of the documentation for CFMessagePort/NSMessagePort says that to receive messages you have to add the port to an NSRunLoop. My only problem is, my daemon doesn't have an NSRunLoop. (At least, I don't think it does.) It is not an event driven application.
- Am I on the right track here, or is there some other API that I should be using? (NSSocketPorts didn't look promising either.)
- Is there some simple way of creating a port and receiving messages without using an NSRunLoop?
- The documentation for NSRunLoop says that a run loop object should exist for each thread. Assuming that the main thread of my daemon is wrapped in an NSThread, then I should already have an NSRunLoop object, correct? If so, is it safe to use this NSRunLoop object in a faceless, non-event driven daemon, that much of the time is running as root -- or am I opening up a whole can of worms?
- All of the code examples that I can find only show creating two NSMessagePorts and communicating between threads of the same process. Yet all of the documentation says that NSMessagePorts can also communicate between processes. How does one create NSMessagePorts that talk between processes? Are NSMessagePort names global? Can I open any NSMessagePort in the system if I know its name? Doesn't this create security problems (if anyone can open up the message port of a daemon and start talking to it)?
Questions, questions, questions, ...
--
James Bucanek <mailto:email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden