On Jul 26, 2011, at 11:22 PM, Scott Ribe wrote:

> On Jul 26, 2011, at 5:52 PM, Shane Stanley wrote:
> 
>> In Snow Leopard that worked fine; a notification would be sent when new data
>> was written to the file. In Lion, as soon as it's called it goes into a
>> loop; each time readInBackgroundAndNotify is sent, a new notification comes
>> straight back.
> 
> An actual file? I'm reading from a pipe, so that could be one difference.

Yes.  For a file (vnode), there's no such thing as non-blocking or asynchronous 
I/O through the typical BSD/POSIX APIs (ignoring aio).  All attempts to read or 
write will complete synchronously, blocking even if the file descriptor has 
been configured as non-blocking and the file system is mounted over a slow or 
broken network connection.  Attempts to test a vnode file descriptor's 
readability or writability using select() or poll() will always report that the 
file is readable or writable.

kqueue() is a bit weird for vnodes.  EVFILT_READ fires whenever the file 
pointer is not at the end of the file.  That means you'll be notified 
repeatedly until you read to the end of the file, but won't be notified when 
you're actually at the end of the file.  That is, you won't be told to read 
once more to receive the EOF indication (e.g. zero-length read).  After that, 
you won't be notified again unless and until the file is extended by something 
writing more data to it, past the current end, or if you seek to some other 
position.  Although this seems to be what Shane wants, for most programmers 
this is a surprising result and differs quite a lot from other types of file 
descriptors.  It also doesn't correspond to NSFileHandle's documented behavior, 
since that doesn't differ by descriptor type.

Kqueue's EVFILT_WRITE isn't supported at all for vnodes, as it doesn't make 
sense, since it would always fire immediately.  The caller should simply not 
use kqueue() and should just go ahead and write unconditionally, instead.

None of this applies for I/O through a pipe or socket.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to