• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: forwardInvocation: Works Locally but crashes with DO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: forwardInvocation: Works Locally but crashes with DO


  • Subject: Re: forwardInvocation: Works Locally but crashes with DO
  • From: Ondra Cada <email@hidden>
  • Date: Wed, 7 Aug 2002 17:54:58 +0200

On Wednesday, August 7, 2002, at 04:54 , Joe Lester wrote:

My app (let's call it App1) is using a lightweight object to forward unrecognized messages to its "surrogate" object. I do this by overriding "forwardInvocation :" and "methodSignatureForSelector:". It works great locally but when I try to access this object from my other app (App2) using a remote proxy, App1 crashes with a signal 10.

Your stack overflows, since...

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
if ([self respondsToSelector:aSelector])
{
return [self methodSignatureForSelector:aSelector];

...this starts an infinite recursion.

This way it works:

#import <Foundation/Foundation.h>

@protocol P
-(void)bar;
@end

@interface Embedded:NSObject @end
@implementation Embedded
-(void)bar {
NSLog(@"bar");
}
@end
@interface Server:NSObject {
@public
Embedded *embedded;
}
@end
@implementation Server
-(void)foo {
NSLog(@"foo");
}
-(NSMethodSignature*)methodSignatureForSelector:(SEL)sel {
NSMethodSignature *sig=[[self class] instanceMethodSignatureForSelector:
sel];
if (sig) return sig;
return [embedded methodSignatureForSelector:sel];
}
-(void)forwardInvocation:(NSInvocation*)inv {
[inv invokeWithTarget:embedded];
}
@end

int main() {
id p=[NSAutoreleasePool new];
id v=[NSConnection rootProxyForConnectionWithRegisteredName:@"SNAFU" host:nil];

if (v) {
NSLog(@"client mode");
[v setProtocolForProxy:@protocol(P)];
[v foo];
NSLog(@"foo sent");
[v bar];
NSLog(@"bar sent, done");
} else {
id conn=[NSConnection defaultConnection];
NSLog(@"server mode");
[conn setRootObject:v=[Server new]];
((Server*)v)->embedded=[Embedded new];
if ([conn registerName:@"SNAFU"]) {
[conn runInNewThread];
NSLog(@"enter 'q' to quit");
while (getchar()!='q');
}
}
[p release];
return 0;
}

Incidentally: without the protocol it does not. I regret to say I haven't a slightest idea why -- so far as I understand DO, it should (the client should send first methodSignatureForSelector:bar through proxy, and then it should send bar). Nevertheless, it does not happen: the proxy seems to "know" itself somehow very low-level that Server does not responds to bar,
and that's that. (Note: reimplementing respondsToSelector: the proper way does not help).
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >forwardInvocation: Works Locally but crashes with DO (From: Joe Lester <email@hidden>)

  • Prev by Date: mouse location
  • Next by Date: NSConnections etc.
  • Previous by thread: forwardInvocation: Works Locally but crashes with DO
  • Next by thread: Re: forwardInvocation: Works Locally but crashes with DO
  • Index(es):
    • Date
    • Thread