Epoll on regular files

前端 未结 2 1606
[愿得一人]
[愿得一人] 2020-12-25 11:49

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

相关标签:
2条回答
  • 2020-12-25 12:26

    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.

    0 讨论(0)
  • 2020-12-25 12:28

    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
    
    0 讨论(0)
提交回复
热议问题