Re: Efficiently receiving data from an NSTask
Re: Efficiently receiving data from an NSTask
- Subject: Re: Efficiently receiving data from an NSTask
- From: Andrew Farmer <email@hidden>
- Date: Sun, 6 Jul 2008 23:36:37 -0700
On 06 Jul 08, at 23:24, Omar Qazi wrote:
On Jul 6, 2008, at 7:46 AM, Martin Hairer wrote:
This works like a treat and is faster by a factor 3 or so than using
the "Moriarity" implementation. However, it leaves me a bit concerned
about various warnings all over the place concerning the thread
(un)safety of NSTask and NSFileHandle. So my question is: is the kind
of approach that I am taking doable / reasonable? If not, is there an
alternative way of doing this which is more efficient than the
"Moriarty" code? Thanks a lot in advance for any help / hint,
NSFileHandle *msgHandle = [standardInput fileHandleForReading];
[msgHandle waitForDataInBackgroundAndNotify];
- (void)newMessage:(NSNotification *)notification {
NSString *strOutput = [[NSString alloc]initWithData:[msgHandle
availableData] encoding:NSUTF8StringEncoding];
//Process the data
[msgHandle waitForDataInBackgroundAndNotify];
}
I'd be very careful with reading string input like that. It's entirely
possible for a multi-byte character (é, for example, is represented as
C3 89) to be split across two separate data chunks, which'll make
NSString very confused and angry.
I'm not quite sure what the correct solution is here, though. There's
got to be some easier solution than checking for sequence completeness
by hand..._______________________________________________
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