Hi all,
I have a problem reading periodic data from a file descriptor, and I
am wondering if I am using the methods wrong. The basic code is below,
but essentially I
(1) register my object to be called when an
NSFileHandleDataAvailableNotification is sent to the notification
center;
(2) create an NSFileHandle for the file descriptor and send it the
waitForDataInBackgroundAndNotify method;
(3) in the callback method, I read the data and then call
waitForDataInBackgroundAndNotify again so it can look for new data.
The callback method will be called sometimes just once but often
several times until eventually I get a EXC_BAD_ACCESS signal.
Is there something glaringly wrong with my code? Should I not call
waitForDataInBackgroundAndNotify in the callback function? Does
reading from the file descriptor via read() instead of through the
NSFileHandle cause problems?
Any suggestions would be appreciated,
Todd
// Register callback method when data is available
[nc addObserver:self
selector:@selector(dataAvailable:)
name:NSFileHandleDataAvailableNotification
object:nil];
// Use an NSFileHandle for the file descriptor
myFileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd];
[myFileHandle waitForDataInBackgroundAndNotify];
- (void) dataAvailable: (NSNotification*)notification
{
// read data directly from the fd
[myFileHandle waitForDataInBackgroundAndNotify];
}
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]