Re: NSPipe (NSFileHandle) writedata limit?
Re: NSPipe (NSFileHandle) writedata limit?
- Subject: Re: NSPipe (NSFileHandle) writedata limit?
- From: Greg Guerin <email@hidden>
- Date: Mon, 12 Apr 2010 09:09:42 -0700
McLaughlin, Michael P. wrote:
main --> subtask (main send data)
-(void)sendData:(void*)data numBytes:(NSUInteger)sz taskTag:
(NSString*)tag
{
NSData *dataset = [NSData dataWithBytes:data length:sz];
NSNumber *num = [NSNumber numberWithUnsignedInteger:sz]; //
NSUInteger
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
num,
@"size", nil];
[sendEnd writeData:dataset]; // Do NOT close the fileHandle!
[[NSDistributedNotificationCenter defaultCenter]
postNotificationName:tag
object:myID userInfo:dict];
}
That is, main
1) sends (via FileHandle and pipe) a known quantity of data to the
subtask
and
2) tells it what sort of data are coming and how much.
All that stuff I just wrote? Uh, never mind.
There's your deadlock right there.
You must send the notification with size and such BEFORE writing to
the pipe. Otherwise the sender can become blocked, because the
receiver doesn't know it should be reading anything.
If you'd been sending the size over the pipe, it would have been
obvious. You have to tell the receiver how many bytes follow.
-- GG
_______________________________________________
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