kqueue (在OS上)对读取/写入常规文件有用吗?我知道epoll对Linux上的常规文件没有用处,所以我想知道kqueue是否也是如此。
编辑:我并不是说读/写文件,很明显,read()和write()就是这样做的。我的意思是,“kqueue实际上在检测文件何时可读/可写时有用吗?”
发布于 2013-01-14 05:24:42
是的,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.(在这种情况下,“vnode”是常规文件。)
由于常规文件总是可写的,因此将EVFILT_WRITE应用于它们是没有意义的。
发布于 2013-01-13 02:24:47
内核队列是“允许您拦截内核级事件以接收有关套接字、进程、文件系统和系统其他方面的更改的通知。”的机制
我过去曾使用过它们来检测文件上的操作何时发生 (或者在热文件夹中)。不过,我不认为它们可以用来“阅读”和“写”文件。如果您愿意,也可以使用MacOS本机函数或常规UN*X样式的"fopen“、"fwrite”和"fread“。
https://stackoverflow.com/questions/14299928
复制相似问题