Post

Replies

Boosts

Views

Activity

Reply to Allowing dynamic name registration in xpc_connection_create_mach_service
Thanks for the response! Your write-up provides a lot of great foundational understanding of XPC, and I appreciate the alternatives it provides. I'm not sure how "The Xcode Gotcha" section provides an answer to the question though. In fact, running xpc_connection_create_mach_service does not work in a debug environment since the provided name is not found within the bootstrap namespace. I'm in the kind-of-opposite scenario basically: The app-to-app communication works normally because the listener is a launchd service (with the appropriate names filled in the MachService section of its info.plist file to allow clients to connect to it). However, I'm attempting to debug it by writing up a small "demo" program where I can easily debug and run the XPC listener code. The code calls xpc_connection_create_mach_service, but doesn't have any MachService names to work with, and a subsequent call to xpc_connection_resume causes an irrecoverable failure.
Oct ’22
Reply to Allowing dynamic name registration in xpc_connection_create_mach_service
That’s interesting, but there are definitely circumstances where folks get mislead by Xcode’s behaviour. Agreed, and I definitely wouldn't be surprised if it was something weird with Xcode. Though in the same man page: If the service name for the connection is not present in your launchd.plist's MachServices dictionary, your listener connection's event handler will receive the XPC_ERROR_CONNECTION_INVALID error, as XPC disallows ad-hoc service name registrations. Which is the behavior I'm seeing. Though for some reason I also get an EXC_BAD_INSTRUCTION upon calling xpc_connection_resume. Are you trying to debug the XPC aspects of your code? If so, I recommend that you do this in a single process using an anonymous listener. See TN3113 Testing and debugging XPC code with an anonymous listener. At first, I wasn't sure how this would apply to me since you can't create anonymous listeners with xpc_connection_create_mach_service, but upon re-reading I realize that I could have replaced the listener connection with xpc_connection_create(NULL, ... following the techniques here, and that does the trick! Some refactoring is definitely in order. While this doesn't explain dynamic name registration, it does ultimately resolve the issue I'm having. Thanks as always, Quinn!
Oct ’22