Epoll on regular files

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

Can epoll (on Linux) be somehow useful for regular files? I know it's primarily used with sockets but just wonder.

回答1:

Not really. epoll only makes sense for file descriptors which would normally exhibit blocking behavior on read/write, like pipes and sockets. Normal file descriptors will always either return a result or end-of-file more or less immediately, so epoll wouldn't do anything useful for them.



回答2:

I think, it will fail at epoll_ctl with EPERM:

   EPERM  The target file fd does not support epoll. 

if the file has no poll() interface.

The actual code is http://lxr.linux.no/#linux+v3.1/fs/eventpoll.c#L1373

1373    /* The target file descriptor must support poll */ 1374        error = -EPERM; 1375        if (!tfile->f_op || !tfile->f_op->poll) 1376                goto error_tgt_fput; 1377 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!