remote proxy object somehow not correct
remote proxy object somehow not correct
- Subject: remote proxy object somehow not correct
- From: "William Zumwalt" <email@hidden>
- Date: Mon, 15 Jan 2007 18:31:31 -0600
I'm still trying to get this one fixed, but I can't see where I've
gone wrong. I have a problem in the code below where I try to set an
instance of the thread in my parent thread, but for some reason, it
won't get called. I feel like the workers proxy object is not working
correctly.
// My app makes this call ...
+ (NSConnection *)startNetworkThreadWithTag:(int)tag
forController:(id <NetworkController>)controller
conditionLock:threadLock
{
NSArray *portArray = nil;
serverLock = threadLock;
[serverLock lock];
NSPort *port1 = [NSPort port];
NSPort *port2 = [NSPort port];
NSConnection *connection = [[NSConnection alloc]
initWithReceivePort:port1 sendPort:port2];
[connection setRootObject:controller];
portArray = [NSArray arrayWithObjects:port2, port1,
[NSNumber numberWithInt:tag], nil];
[NSThread detachNewThreadSelector:@selector(_connectWithPorts:)
toTarget:self withObject:portArray];
return connection;
}
On the setServer: call is where my problem is. It won't get past that
and just seems to hang, or block. I think the proxy object is somehow
not correct, though if I do [serverConnection isValid], it returns
TRUE.
+ (void)_connectWithPorts:(NSArray *)portArray
{
NSAutoreleasePool *pool = nil;
NSConnection *serverConnection = nil;
NetworkServer *serverObject = nil;
pool = [[NSAutoreleasePool alloc] init];
serverConnection = [NSConnection
connectionWithReceivePort:[portArray objectAtIndex:0]
sendPort:[portArray objectAtIndex:1]];
int serverTag = [[portArray objectAtIndex:2] intValue];
serverObject = [[NetworkServer alloc] initWithTag:serverTag];
[serverConnection setRootObject:serverObject];
// This call seems to be blocking here. Just hangs.
[(id <NetworkController>)[serverConnection rootProxy]
setServer:serverObject tag:serverTag];
// Never gets to this line.
[serverLock unlockWithCondition:THREAD_SETUP_COMPLETE];
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
} while ([serverObject isRunning]);
[[serverConnection receivePort] invalidate];
[[serverConnection sendPort] invalidate];
[serverConnection release];
[serverObject release];
[pool release];
return;
}
This setServer: method is in the main app thread where the worker
thread gets set. But this never gets called (even though it's at this
line in the calling thread) and I can only guess there's something
wrong with the NSConnection in _connectWithPorts above, but I keep
going over it and it looks ok.
- (void)setServer:(id)anObject tag:(int)serverTag
{
[anObject setProtocolForProxy:@protocol(NetworkServer)];
if (serverTag == 0) {
[(id)server release];
server = (id <NetworkServer>)[anObject retain];
}
else if (serverTag > 0) {
NSLog(@"Error: This should not have happened, serverTag > 0.");
}
return;
}
Anyone see anything that might not be correct here. I'm now using the
examples in in the xcode docs ... Multithreading Programming Topics.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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