【发布时间】:2012-12-27 07:40:41
【问题描述】:
kqueue(在 OS X 上)对读/写常规文件有用吗?我知道 epoll 对 Linux 上的常规文件不有用,所以我想知道 kqueue 是否也是如此。
编辑:我不是说读/写文件,显然 read() 和 write() 就是为了这个。我的意思是,“kqueue 对于检测文件何时可读/可写真的有用吗?”
【问题讨论】:
标签: c macos sockets operating-system kqueue
kqueue(在 OS X 上)对读/写常规文件有用吗?我知道 epoll 对 Linux 上的常规文件不有用,所以我想知道 kqueue 是否也是如此。
编辑:我不是说读/写文件,显然 read() 和 write() 就是为了这个。我的意思是,“kqueue 对于检测文件何时可读/可写真的有用吗?”
【问题讨论】:
标签: c macos sockets operating-system kqueue
是的,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 是没有意义的。
【讨论】:
我过去曾将它们用于detect when when actions happen on a file(或在常用文件夹中)。不过,我不相信它们可以用于“读取”和“写入”文件。如果您愿意,您也可以使用 MacOS 原生函数或常规 UN*X 样式“fopen”、“fwrite”和“fread”调用。
【讨论】: