• 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: Problem with loop in compression Step
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with loop in compression Step


  • Subject: Re: Problem with loop in compression Step
  • From: Ingvar Nedrebo <email@hidden>
  • Date: Sat, 23 Mar 2002 21:10:30 +0000

Well, as you found out you need to launch gzip before you can start writing data to it. What happened before was that your app would fill up the pipe buffer, and then block waiting for somebody to start listening on the other end.

But you're not out of the woods yet. Now your problem is that you are writing all the data to gzip before you start reading the output from gzip -- which means that gzip will fill up the output pipe buffer and then block and stop receiving data, which means you will also block in your write loop, and you have a classic deadlock situation.

NSFileHandle readInBackgroundAndNotify might solve your problem.

Have a look at Apple Moriarity example:
http://developer.apple.com/samplecode/Sample_Code/Cocoa/Moriarity

I.

On Saturday, March 23, 2002, at 03:46 , Erik J. Barzeski wrote:

Hi,

Possible solution, will test more, but it seems moving [gzip launch]; to
before the NS_DURING has solved the problem. Again, I'll do more testing,
but it seems to work fine currently:

2002-03-23 10:44:24.350 MeMail[12872] Data Length: 186645
2002-03-23 10:44:24.373 MeMail[12872] booya

P.S. The file size is pretty darn teeny.
941881 -rw-r--r-- 1 iacas wheel 1468 Mar 23 10:44 Untitled2.nodemap



Hi,

One of the features of an app I'm working on is compression before saving
the file. It's an AI type app with a bunch of nodes, vectors, etc. GZIP can
compress an 8 MB file to 190k, so, I figured why not do this within the app
itself?

The _decompression_ algorithm works (and is a fair amount shorter than
this).

The app GWOD's (Gay Wheel of Death's) during the [inHandle writeData:data];
line. An NSLog() after that line is called very rarely - and only when we
have a few nodes. Any more than a certain number (usually around 103) and
the thing GWODs on us.

I put a Data Length: NSLog() before the problem line, and "booya" after to
signify that it "made it past" that line. Here's the interesting output:

2002-03-23 09:43:27.662 MeMail[12794] Data Length: 8158
2002-03-23 09:43:27.662 MeMail[12794] booya
2002-03-23 09:43:29.595 MeMail[12794] Data Length: 8196
// GWOD occurs here.... No booya is reached

Please CC me off-list as I get the digest and won't see any replies for
awhile otherwise.

(those are bytes of course). Anything greater than

Here's the code:

{
NSMutableData *fileData = [NSMutableData data];
NSData *data = [NSArchiver archivedDataWithRootObject:ourRootObj];
NSTask *gzip = [[NSTask alloc] init];
NSPipe *inPipe = [NSPipe pipe];
NSPipe *outPipe = [NSPipe pipe];
NSFileHandle *inHandle = [inPipe fileHandleForWriting];
NSFileHandle *outHandle = [outPipe fileHandleForReading];


// set up NSTask params
[gzip setLaunchPath:[[NSBundle mainBundle] pathForResource:@"gzip"
ofType:nil]];
[gzip setArguments:[NSArray array]];
[gzip setStandardInput:inPipe];
[gzip setStandardOutput:outPipe];

// write data to stdin pipe

NS_DURING
// problem line right here:
[inHandle writeData:data];
[inHandle closeFile];
NS_HANDLER
NSLog( @"Exception occured: %@", [localException description] );
return nil;
NS_ENDHANDLER


// run gzip and return compressed data
[gzip launch];
while((data=[outHandle availableData]) && [data length])
{
[fileData appendData:data];
}
[gzip release];
return fileData;
}


--
Best wishes,
Erik J. Barzeski

Rules? We don't have rules. We're trying to accomplish something!
*******************************************************************
Email: erik@(anything below)
AIM: iacas ICQ: 8186546

http://barzeski.com/ http://weims.net/
http://techstra.net/ http://cocoadevcentral.com/
http://soundsetcentral.com/ http://applescriptcentral.com/
*******************************************************************
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Problem with loop in compression Step (From: "Erik J. Barzeski" <email@hidden>)

  • Prev by Date: CMSDA
  • Next by Date: Re: CADO: Cocoa Application Developers Organization?
  • Previous by thread: Problem with loop in compression Step
  • Next by thread: [Maybe a little OT] Launching a CFM executable through code
  • Index(es):
    • Date
    • Thread