On May 11, 2009, at 2:35 PM, Todd Heberlein wrote:

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;

Try reversing the order of the above two steps and observe the specific NSFileHandle object. It's possible that there are other NSFileHandles out there (created by the framework?) and, as things stand, your method would be called whenever those post their notifications, too.

[...] Should I not call waitForDataInBackgroundAndNotify in the callback function?

Actually, you must if you want to be notified again.

Does reading from the file descriptor via read() instead of through the NSFileHandle cause problems?

It might.  Have you tried using -availableData instead?

Alternatively, have you tried using -readInBackgroundAndNotify and the NSFileHandleReadCompletionNotification, getting the data from the notification's userInfo?


Any suggestions would be appreciated,

Make sure all of your memory management is correct. Retain the file handle object for as long as you need it to exist, etc.

Regards,
Ken

_______________________________________________

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]

Reply via email to