Linux下的fd都是Pollable的吗?
例如,文件,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 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 , 自己跟. 你看man文档,一般都有说明。
对于poll,posix标准明确支持的有(man -s 3p poll):The poll() function shall support regular files, terminal and pseudo-terminal devices, FIFOs, pipes, sockets andSTREAMS-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-specificOperating on a timer file descriptor
The file descriptor returned by timerfd_create() supports the following operations:
poll(2), select(2) (and similar)
The file descriptor also supports the other file-descriptor multiplexing APIs: pselect(2), ppoll(2), and epoll(7).event(man eventfd): Linux-specificAs 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:
poll(2), select(2) (and similar)
The returned file descriptor supports poll(2) (and analogously epoll(7)) and select(2)
The eventfd file descriptor also supports the other file-descriptor multiplexing APIs: pselect(2), ppoll(2), and epoll(7)
页:
[1]