[launchd-dev] The MachService key
Damien Sorresso
dsorresso at apple.com
Wed Nov 23 10:39:19 PST 2011
On Nov 23, 2011, at 10:28 AM, Damien Sorresso wrote:
> On Nov 22, 2011, at 10:07 PM, Jerry Krinock wrote:
>> // Set an Event Handler
>> xpc_connection_set_event_handler(listener, ^(xpc_object_t object) {
>> char* desc = xpc_copy_description(object);
>> NSLog(@"MachServiceDemo Server got connection: %s", desc) ;
>> xpc_connection_set_event_handler(listener, ^(xpc_object_t object) {
>> char* desc = xpc_copy_description(object);
>> NSLog(@"MachServiceDemo Server got message: %s", desc) ;
>> free(desc) ;
>> }) ;
>> }) ;
>> xpc_connection_resume(listener) ;
>
> That inner xpc_connection_set_event_handler(3) should target 'object' (the new incoming connection), not 'listener'.
Oh, and you also need to resume 'object'.
> xpc_connection_set_event_handler(listener, ^(xpc_object_t peer) {
> assert(xpc_get_type(peer) == XPC_TYPE_CONNECTION);
> xpc_connection_set_event_handler(peer, ^(xpc_object_t event) {
> if (event == XPC_ERROR_CONNECTION_INVALID) {
> // Peer has gone away.
> } else {
> assert(xpc_get_type(event) == XPC_TYPE_DICTIONARY);
> // Handle message.
> }
> });
> xpc_connection_resume(peer);
> });
Hope this helps. I highly recommend checking out the man pages.
$ man xpc
--
Damien Sorresso
dsorresso at apple.com
More information about the launchd-dev
mailing list