-[NSFileHandle readInBackgroundAndNotify] opens the file again
-[NSFileHandle readInBackgroundAndNotify] opens the file again
- Subject: -[NSFileHandle readInBackgroundAndNotify] opens the file again
- From: Rick Mann <email@hidden>
- Date: Fri, 13 Jul 2012 19:46:35 -0700
I'm using NSFileHandle in an ARC app on OS X Lion to read from a serial port.
Everything works fine 'till I go to close the port. I open the port with POSIX calls, set up some stuff, then instantiate an NSFileHandle with the file descriptor I got from open().
Then I call -readInBackgroundAndNotify, and a second file descriptor gets opened (I see this by using lsof).
That FD gets closed the moment some data comes in and a notification gets posted, but I just go right back and call -readInBackgroundAndNotify again to get the next data.
The problem is when I go to close the port. I still have a pending -readInBackgroundAndNotify, and so the port is opened twice. When I call -closeFile on the NSFileHandle, it closes the FD I initially opened, but leaves the second FD open.
I tried setting the NSFileHandle reference to nil so that ARC would release it, and hopefully call -dealloc on it, but either it's not doing that, or -dealloc doesn't close that second FD either.
In any case, when I go to open that port again, I get an error saying the resource is busy (if I quit my app, all FDs get closed).
This sure seems like a bug to me. Am I doing something wrong?
Thanks,
Rick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden