Re: Very strange Xpc magic
Re: Very strange Xpc magic
- Subject: Re: Very strange Xpc magic
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Mon, 16 Sep 2013 22:16:28 +0700
On 16 Sep 2013, at 22:10, Charles Srstka <email@hidden> wrote:
> On Sep 16, 2013, at 3:22 AM, Gerriet M. Denkmann <email@hidden> wrote:
>
>> In a new app (not document based) I inserted:
>>
>> #import "ZipProtocol.h"
>>
>> // ZipProtocol.h:
>> @protocol ZipProtocol <NSObject>
>> - (void)command:(NSString *)command withReply: (void (^)( NSString *answerString ))reply;
>> @end
>>
>> #define MAGIC_BUG_REMOVAL // defined or not - makes a strange difference
>>
>> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
>> {
>> NSString *helperName = @"something.very.silly";
>>
>> NSXPCConnection *aCo = [[NSXPCConnection alloc] initWithMachServiceName: helperName
>> options: 0
>> ];
>> if ( aCo == nil) // error
>> {
>> NSLog(@"%s Error NSXPCConnection",__FUNCTION__);
>> return ;
>> };
>>
>> #ifdef MAGIC_BUG_REMOVAL
>> NSLog(@"%s will use magic - you will see MAGIC_ERROR",__FUNCTION__);
>> #else
>> NSLog(@"%s without magic - you will NOT see MAGIC_ERROR",__FUNCTION__);
>> #endif
>>
>> aCo.remoteObjectInterface = [ NSXPCInterface interfaceWithProtocol: @protocol(ZipProtocol) ];
>> [ aCo resume];
>>
>> // can do magic here
>>
>> id <ZipProtocol> ree;
>> ree = [ aCo remoteObjectProxyWithErrorHandler: ^(NSError *err)
>> {
>> // if helperName is not running (always the case) and
>> // MAGIC_BUG_REMOVAL is NOT defined, then the next line will never print:
>> NSLog(@"%s MAGIC_ERROR: %@",__FUNCTION__, err);
>> }
>> ];
>> if ( ree == nil) // error
>> {
>> NSLog(@"%s Error remoteObjectProxy",__FUNCTION__);
>> return;
>> };
>>
>> // can do magic here as well:
>>
>> #ifdef MAGIC_BUG_REMOVAL
>> NSLog(@"%s will use magic",__FUNCTION__);
>> #endif
>>
>> [ ree command: @"a command"
>> withReply: ^( NSString *answerString )
>> {
>> NSLog(@"%s the reply block %@",__FUNCTION__, answerString );
>> [ aCo invalidate];
>> }
>> ];
>>
>> NSLog(@"%s did send",__FUNCTION__);
>> }
>>
>>
>> The question: why does the fact whether MAGIC_BUG_REMOVAL is defined or not makes any difference?
>> Seems not to depend on optimisation - same for Debug and Release builds.
>>
>> Probably there is a very simple answer, but I just cannot see it.
>
> What's the error that logs in your error handler?
If (and only if) MAGIC_BUG_REMOVAL is defined, I see:
Error Domain=NSCocoaErrorDomain Code=4099 "Couldn’t communicate with a helper application."
Makes sense, as there just is no helper application named: "something.very.silly".
Kind regards,
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden