免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2272 | 回复: 2
打印 上一主题 下一主题

[Linux] Linux下的fd都是Pollable的吗? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-28 11:45 |只看该作者 |倒序浏览
10可用积分
例如,文件,socket,timer,pipe,mutex,semaphore,event,pthread,这些都是可以用来给poll或者epoll使用的吗?

还是说,有某些类型的fd不是Pollable的? 怎么区分呢?

谢谢。

最佳答案

查看完整内容

给你跟了一下内核代码, 调用链比较长, 给你个线索, 你可以自己探索:fs/eventpoll.c中的:SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, struct epoll_event __user *, event)有如下检查: /* Get the "struct file *" for the target file */ tfile = fget(fd); if (!tfile) goto error_fput; /* The target ...

论坛徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46处女座
日期:2013-10-24 14:25:01酉鸡
日期:2014-04-07 11:54:15
2 [报告]
发表于 2013-05-28 11:45 |只看该作者
给你跟了一下内核代码, 调用链比较长, 给你个线索, 你可以自己探索:

fs/eventpoll.c中的:
SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd,                                                                              
        struct epoll_event __user *, event)

有如下检查:
    /* Get the "struct file *" for the target file */
    tfile = fget(fd);
    if (!tfile)
        goto error_fput;

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


fget函数在fs/file_table.c中, 其中调用了:fcheck_files函数进行检查, 进一步到include/linux/fdtable.h , 自己跟.

论坛徽章:
4
白羊座
日期:2013-09-17 21:59:30技术图书徽章
日期:2013-10-12 22:16:03白羊座
日期:2013-10-14 11:01:40双子座
日期:2013-12-17 18:26:39
3 [报告]
发表于 2013-05-28 13:20 |只看该作者
你看man文档,一般都有说明。

对于poll,posix标准明确支持的有(man -s 3p poll):
  1. The poll() function shall support regular files, terminal and pseudo-terminal devices, FIFOs, pipes, sockets and  STREAMS-based files.  The behavior of poll() on elements of fds that refer to other types of file is unspecified.
复制代码
mutex,semaphore和pthread似乎与fd无关吧。

epoll: Linux-specific

timer(man timerfd_create): Linux-specific
  1. Operating on a timer file descriptor
  2. The file descriptor returned by timerfd_create() supports the following operations:
  3. poll(2), select(2) (and similar)
  4. The file descriptor also supports the other file-descriptor multiplexing APIs: pselect(2), ppoll(2), and epoll(7).
复制代码
event(man eventfd): Linux-specific
  1. As its return value, eventfd() returns a new file descriptor that can be used to refer to the eventfd object.  The following operations can be performed on the file descriptor:
  2. poll(2), select(2) (and similar)
  3. The returned file descriptor supports poll(2) (and analogously epoll(7)) and select(2)
  4. The eventfd file descriptor also supports the other file-descriptor multiplexing APIs: pselect(2), ppoll(2), and epoll(7)
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP