linux poll
poll的作用
- it waits for one of a set of file descriptors to become ready to perform I/O. 也就是poll的作用是等待一组文件描述符变得可执行;
- 假若刚进行监测时不可执行怎么处理呢?会根据timeout参数阻塞;
The timeout argument specifies the number of milliseconds that poll() should block waiting for a file descriptor to become ready.
总结
The call will block until either:
- a file descriptor becomes ready;
- the call is interrupted by a signal handler; or
- the timeout expires.
用户层使用
poll (struct pollfd *__fds, nfds_t __nfds, int __timeout)
- struct pollfd *__fds:是一个数组的指针,可以有多个struct pollfd;
- nfds:既然上面的指针是一个数组,那有多少个成员呢,通过该nfds指示;
- timeout:指示当描述符不可用时,应该等待多长;