Kqueue on regular files

Is kqueue (on OS X) useful for reading / writing regular files? I know that epoll is not useful for regular files on Linux, so I wonder if this is true for kqueue.

EDIT: I don't mean reading / writing files, obviously read () and write () for this. I meant: "Is kqueue really useful for detecting when a file is read / write?"

+6
source share
2 answers

Yes, kqueue can be used to view files for readability. On the man page:

EVFILT_READ Takes a file descriptor as the identifier, and returns whenever there is data available to read. The behavior of the filter is slightly different depending on the descriptor type. [...] Vnodes Returns when the file pointer is not at the end of file. data contains the offset from current posi- tion to end of file, and may be negative. 

("vnodes" in this context are regular files.)

Since regular files are always writable, it makes no sense to apply EVFILT_WRITE to them.

+1
source

Kernel queues are mechanisms that "allow you to intercept kernel-level events to receive notifications of changes in sockets, processes, the file system, and other aspects of the system."

I used them in the past to detect when actions occur in a file (or in a hot folder). I do not believe that they can be used to "read" and "write" files. You can use MacOS native functions or the usual UN * X style " fopen ", " fwrite " and " fread " calls this if you want.

+1
source

All Articles