kqueue(在OS X上)对读写常规文件有用吗?我知道epoll 不是对Linux上的常规文件有用,所以我想知道是否同样适用于kqueue。
编辑:我不是说读/写文件,显然read()和write()是为了这个。我的意思是,"kqueue对于检测文件是否可读/可写真的有用吗?"
内核队列是"允许您拦截内核级事件以接收有关套接字、进程、文件系统和系统其他方面更改的通知"的机制。
我过去使用它们来检测什么时候操作发生在文件上(或在热文件夹中)。但是,我不相信它们可以用于"读"one_answers"写"文件。如果你愿意,你也可以使用MacOS本地函数或常规UN*X样式的"fopen
","fwrite
"one_answers"fread
"调用。
是的,kqueue可以用来监视文件的可读性。从手册页:
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"是普通文件)
由于常规文件总是可写的,所以对它们应用EVFILT_WRITE
是没有意义的。