• 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
NSTask, NSFileHandle, readInBackgroundAndNotify and avoiding polling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTask, NSFileHandle, readInBackgroundAndNotify and avoiding polling


  • Subject: NSTask, NSFileHandle, readInBackgroundAndNotify and avoiding polling
  • From: Jim Correia <email@hidden>
  • Date: Wed, 10 Jul 2002 23:41:21 -0400

I'm running a long lived sub-process via NSTask. I've wired out to the task's standard out with NSPipe and NSFileHandle in the usual way.

The nature of the sub-task is that it can produce output at any time, but usually sits blocked for a long time between spurts of output. I want to catch the output in a timely fashion, but don't want to waste effort polling the pipe for data when there isn't anything there.

So after launching the task, I do [standardOut readInBackgroundAndNotify]. As it happens, the test case (a perl script written for testing) generates output right away then goes to sleep, so I get the notification right away and read all the data. Then the notification handler does another [fileHandle readInBackgroundAndNotify]. It returns right away with no data, and we roll over on it again.

Is there any way to convince NSFileHandle to only notify me when data is actually available? (waitForDataInBackgroundAndNotify doesn't do the trick, and the docs seem to indicate that readInBackgroundAndNotify is implemented using it).

Or is my only choice to back off on the reading when I get no data, ramp up the frequency when I get some, and ramp it back down when I get none? (I would prefer not to do this since I spend time cycling through my read notifier even when there is nothing to do.) Does anyone have a good solution to this problem? I've missed something obvious?

Thanks,
Jim
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSTask, NSFileHandle, readInBackgroundAndNotify and avoiding polling
      • From: Andreas Mayer <email@hidden>
    • Re: NSTask, NSFileHandle, readInBackgroundAndNotify and avoiding polling
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: deallocating instances instantiated in IB
  • Next by Date: Re: Internet Config & Deleting FileMappings
  • Previous by thread: Re: [OT]: "Developer DVD" nearly unusable?
  • Next by thread: Re: NSTask, NSFileHandle, readInBackgroundAndNotify and avoiding polling
  • Index(es):
    • Date
    • Thread