Re: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:])
Re: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:])
- Subject: Re: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:])
- From: Ken Thomases <email@hidden>
- Date: Sun, 20 Sep 2009 04:50:03 -0500
On Sep 20, 2009, at 1:38 AM, Jerry Krinock wrote:
Trying to find a way to "tickle" a run loop into returning in Mac OS
10.6, I wrote another little tool which, instead of spawning a short-
duration NSTask, sends a message to a mach port which has been added
to the current run loop. To my surprise, result is the same.
Running in Mac OS 10.5, when the message is received, the run loop
returns from runMode:beforeDate:. Running in Mac OS 10.6, it never
returns.
+ (void)sendMessage:(NSTimer*)timer {
NSPort* receivePort = [timer userInfo] ;
NSPort* sendPort = [NSMachPort port] ;
NSData* data = [@"Hello" dataUsingEncoding:NSUTF8StringEncoding] ;
NSPortMessage* message = [[NSPortMessage alloc]
initWithSendPort:sendPort
receivePort:receivePort
components:
[NSArray arrayWithObject:data]] ;
You've got the send port and receive port mixed up here. The send
port is the one you're sending to. The receive port is the one on
which you'd receive any reply, if there is one.
Since the timer user info contains the port which was added to the run
loop, you want to send to that one.
BOOL didSend = [message sendBeforeDate:[NSDate
dateWithTimeIntervalSinceNow:0.2]] ;
NSLog(@"Sent message; %@.", didSend ? @"succeeded" : @"failed") ;
[message release] ;
}
Regards,
Ken
_______________________________________________
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