Re: Very strange Xpc magic

2013-09-16 Thread Gerriet M. Denkmann

On 16 Sep 2013, at 22:10, Charles Srstka cocoa...@charlessoft.com wrote:

 On Sep 16, 2013, at 3:22 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Very strange Xpc magic

2013-09-16 Thread Charles Srstka
On Sep 16, 2013, at 3:22 AM, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:

 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);
   }
   ];

What is the error that gets logged here?

Charles

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Very strange Xpc magic

2013-09-16 Thread Keary Suska

On Sep 16, 2013, at 9:27 AM, Gerriet M. Denkmann wrote:

 
 On 16 Sep 2013, at 22:21, Charles Srstka cocoa...@charlessoft.com wrote:
 
 On Sep 16, 2013, at 10:16 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 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.
 
 Make sure you've got the Mach service name for your helper registered in 
 your helper's launchd plist. If it's set up correctly, your helper should 
 automatically launch when the client app tries to communicate with its Mach 
 service name.
 
 Maybe I was not very clear.
 The problem is NOT that the helper app does not start. There just is no 
 helper app, there is nothing which has a MachService called 
 something.very.silly.
 
 The problem is, that the error block, which prints MAGIC_ERROR, does only get 
 called when there is an NSLog right in front of it.
 This makes no sense (to me).


Unless I didn't understand, your original post indicated that the issue was 
with the macro define. Has this changed? If not, I would run the file manually 
through the preprocessor and examine the output.

Keary Suska
Esoteritech, Inc.
Demystifying technology for your home or business


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Very strange Xpc magic

2013-09-16 Thread Charles Srstka
On Sep 16, 2013, at 10:27 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
wrote:

 Maybe I was not very clear.
 The problem is NOT that the helper app does not start. There just is no 
 helper app, there is nothing which has a MachService called 
 something.very.silly.
 
 The problem is, that the error block, which prints MAGIC_ERROR, does only get 
 called when there is an NSLog right in front of it.
 This makes no sense (to me).

I just tried your code on my machine, and whether the error logs or not seems 
fairly random. Whether or not your define is present, I sometimes get the error 
log and sometimes not, and repeatedly running the app (or putting the code in 
an IBAction instead of applicationDidFinishLaunching: and repeatedly pressing a 
button to invoke it) results in a different outcome each time. There might be a 
race condition in the framework or something. Have you filed a Radar report on 
this yet?

Charles

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Very strange Xpc magic

2013-09-16 Thread Gerriet M. Denkmann

On 16 Sep 2013, at 22:13, Charles Srstka cocoa...@charlessoft.com wrote:

 On Sep 16, 2013, at 3:22 AM, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:
 
 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);
  }
  ];
 
 What is the error that gets logged here?

2013-09-16 22:13:33.946 XpcTest[31422:303] __48-[T1aAppDelegate 
applicationDidFinishLaunching:]_block_invoke MAGIC_ERROR: Error 
Domain=NSCocoaErrorDomain Code=4099 Couldn’t communicate with a helper 
application.

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Very strange Xpc magic

2013-09-16 Thread Charles Srstka
On Sep 16, 2013, at 10:16 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
wrote:

 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.

Make sure you've got the Mach service name for your helper registered in your 
helper's launchd plist. If it's set up correctly, your helper should 
automatically launch when the client app tries to communicate with its Mach 
service name.

Charles

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Very strange Xpc magic

2013-09-16 Thread Gerriet M. Denkmann

On 16 Sep 2013, at 22:21, Charles Srstka cocoa...@charlessoft.com wrote:

 On Sep 16, 2013, at 10:16 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 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.
 
 Make sure you've got the Mach service name for your helper registered in your 
 helper's launchd plist. If it's set up correctly, your helper should 
 automatically launch when the client app tries to communicate with its Mach 
 service name.

Maybe I was not very clear.
The problem is NOT that the helper app does not start. There just is no helper 
app, there is nothing which has a MachService called something.very.silly.

The problem is, that the error block, which prints MAGIC_ERROR, does only get 
called when there is an NSLog right in front of it.
This makes no sense (to me).

Kind regards,

Gerriet.




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Very strange Xpc magic

2013-09-16 Thread Gerriet M. Denkmann

On 16 Sep 2013, at 23:16, Charles Srstka cocoa...@charlessoft.com wrote:

 On Sep 16, 2013, at 10:27 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 Maybe I was not very clear.
 The problem is NOT that the helper app does not start. There just is no 
 helper app, there is nothing which has a MachService called 
 something.very.silly.
 
 The problem is, that the error block, which prints MAGIC_ERROR, does only 
 get called when there is an NSLog right in front of it.
 This makes no sense (to me).
 
 I just tried your code on my machine, and whether the error logs or not seems 
 fairly random. Whether or not your define is present, I sometimes get the 
 error log and sometimes not, and repeatedly running the app (or putting the 
 code in an IBAction instead of applicationDidFinishLaunching: and repeatedly 
 pressing a button to invoke it) results in a different outcome each time. 
 There might be a race condition in the framework or something.

I also did some more testing. The magic does not lie in the NSLog() but in the 
elapsed time.

On my machine the sending of a message to remoteObjectProxy must NOT be done 
earlier than ca. 180 μsec after [NSXPCConnection resume].

Without anything in between these are only 50 μsec apart. Not enough.

NSLog() adds a sufficient delay of almost 250 μsec.
But usleep(130) also does the trick. 

Code:
#includemach/mach_time.h   
...
aCo.remoteObjectInterface = [ NSXPCInterface interfaceWithProtocol: 
@protocol(ZipProtocol) ]; 
[ aCo resume];
uint64_t machTime1 = mach_absolute_time();

id ree =[ aCo remoteObjectProxyWithErrorHandler: ^(NSError 
*err)...
usleep(130);

uint64_t machTime2 = mach_absolute_time();
[ ree   command:...
uint64_t elapsed = machTime2 - machTime1;
double microSec = elapsed * 1e-3;

 Have you filed a Radar report on this yet?
Not yet. Will do tomorrow.

Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Very strange Xpc magic

2013-09-16 Thread Gerriet M. Denkmann

On 16 Sep 2013, at 23:13, Keary Suska cocoa-...@esoteritech.com wrote:

 
 On Sep 16, 2013, at 9:27 AM, Gerriet M. Denkmann wrote:
 
 
 On 16 Sep 2013, at 22:21, Charles Srstka cocoa...@charlessoft.com wrote:
 
 On Sep 16, 2013, at 10:16 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 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.
 
 Make sure you've got the Mach service name for your helper registered in 
 your helper's launchd plist. If it's set up correctly, your helper should 
 automatically launch when the client app tries to communicate with its Mach 
 service name.
 
 Maybe I was not very clear.
 The problem is NOT that the helper app does not start. There just is no 
 helper app, there is nothing which has a MachService called 
 something.very.silly.
 
 The problem is, that the error block, which prints MAGIC_ERROR, does only 
 get called when there is an NSLog right in front of it.
 This makes no sense (to me).
 
 
 Unless I didn't understand, your original post indicated that the issue was 
 with the macro define. Has this changed? If not, I would run the file 
 manually through the preprocessor and examine the output.

As I just explained in some reply in this thread: if MAGIC_BUG_REMOVAL is 
defined, then some sufficient delay is added by printing NSLog().

Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Very strange Xpc magic

2013-09-16 Thread Charles Srstka
On Sep 16, 2013, at 11:33 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
wrote:

 I also did some more testing. The magic does not lie in the NSLog() but in 
 the elapsed time.
 
 On my machine the sending of a message to remoteObjectProxy must NOT be done 
 earlier than ca. 180 μsec after [NSXPCConnection resume].
 
 Without anything in between these are only 50 μsec apart. Not enough.
 
 NSLog() adds a sufficient delay of almost 250 μsec.
 But usleep(130) also does the trick. 

Yep, sounds like a race condition for sure.

Charles

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com