File updates
File updates
- Subject: File updates
- From: email@hidden (mikevannorsdel)
- Date: Sat, 17 Nov 2001 07:27:35 -0700
I'm using NSFileHandle's waitForDataInBackgroundAndNotify to watch a
file for new data. I implement it like this:
//Start watch
NSFileHandle * file=[NSFileHandle
fileHandleForReadingAtPath:filePath];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(readFileData:)
name:NSFileHandleDataAvailableNotification object:file];
[file waitForDataInBackgroundAndNotify];
//Method that processes data
- (void)readFileData:(NSNotification*)aNotification
{
...
...
//process new data
...
...
[[aNotification object] waitForDataInBackgroundAndNotify];
}
This works great, but it consumes a lot of CPU while waiting for data
(~65%). Does waitForDataInBackgroundAndNotify not block until data is
ready (like select()) and just constantly check the file? Did I
implement this incorrectly? Is there a better way?