• 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: NSPipe (NSFileHandle) writedata limit?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPipe (NSFileHandle) writedata limit?


  • Subject: Re: NSPipe (NSFileHandle) writedata limit?
  • From: "McLaughlin, Michael P." <email@hidden>
  • Date: Mon, 12 Apr 2010 09:27:50 -0400
  • Acceptlanguage: en-US
  • Thread-topic: NSPipe (NSFileHandle) writedata limit?

This is turning out to be a lot trickier than I had expected.  [I note that
there is currently another thread in this list with a similar concern but
I'm not sure if our problems are identical.]

In my case, I have a main app with an NSArray of subtasks (inheriting from
NSObject), initialized then set up as follows:

-(void)setName:(NSString*)name ID:(int)ident
{
   myID = [NSString stringWithFormat:@"%d ", ident];
   inPipe = [NSPipe pipe];     // i.e., input for subtask
   outPipe = [NSPipe pipe];
   sendEnd = [inPipe fileHandleForWriting]; // send TO subtask
   readEnd = [outPipe fileHandleForReading];

   aTask = [NSTask new];
   [aTask setLaunchPath: theExecutable];    // known by now
   [aTask setArguments:[NSArray arrayWithObject:myID]];
   [aTask setStandardInput:inPipe];
   [aTask setStandardOutput:outPipe];
   [aTask launch];
}

Thereafter, the main task and subtasks are *supposed to* communicate as
follows:

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.

The subtask, when it gets the CPU, reads in the data using the following
code.  [Granted, it might not get the CPU long enough to read all the data
but I hoped that the OS would handle that problem.]

-(NSData*)getDataSz:(NSUInteger)sz
{
   return [input readDataOfLength:sz];
}

The returned NSData is parsed in accordance with the aforementioned tag.

My intent was to do the reverse from subtask to main.

*** All of the above works perfectly PROVIDED that the data sent from main
is at most 65336 bytes. ***

[If I use availableData instead of readDataOfLength, then the limit is 4096
bytes.]  All this is under Leopard but SL shows the same problem.

Notes:
1) GC is supported and compiler is gcc 4.2.
2) sz is everywhere NSUInteger and should go up to about 4 Gb -- and NSData
should know this as well.  According to NSLog, sizeof(sz) is always 4 bytes.
3) I need to know when all subtasks have read and processed their data so
that I can proceed to the next phase of a large SIMD computation which MUST
be done in a fixed sequence with additional data known only to main.
4) FWIW, these subtasks must be persistent (not one-shot) since they will be
called repeatedly.  The main() portion of the subtask executable calls
[[NSRunLoop currentRunLoop] run];
5) There are only subtasks here, no threads.

*****

Clearly, there is some internal blockage, due to some hidden buffer of
limited size, that I am ignoring.

Is there a recommended (better) way of sending and receiving a known (large)
amount of data to and from a subtask?  Is there any sample code anywhere
similar to what I need?  I couldn't find anything close enough to work.

I could also not find anything like (BOOL)dataStillAvailable in NSFileHandle
or else I would have tried a while loop.

Thanks.

--
Mike McLaughlin

_______________________________________________

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

  • Prev by Date: Re: MPMoviePlayerController playhead position, setting markers to trigger events and notifications (MPMediaPlayback Protocol Reference)
  • Next by Date: Data managment
  • Previous by thread: Re: NSPipe (NSFileHandle) writedata limit?
  • Next by thread: Re: NSPipe (NSFileHandle) writedata limit?
  • Index(es):
    • Date
    • Thread