select/poll/epoll事件驱动
来源:互联网 发布:python二维数组 编辑:程序博客网 时间:2024/06/07 01:55
一直用select, 没有使用poll和Epoll, 近来需要使用Epoll。以前面试时,有人问过我, 我也简单作答。
现在写一下我的理解。
三者区别:
select: 监听的文件描述符有限制,linux系统默认是1024
poll:和select差不多, 比select优越的地方是监听的文件描述符个数可以不限
epoll:
1) 监听的文件描述符个数不限
2) select/poll有事件时,会无差别遍历所有文件描述符,依次判断是否有数据,复杂度为O(n); 而epoll 会把哪个流发生了怎样的I/O事件通知我们,复杂度为O(1)。显然epoll优势明显。(具体用法google一下)
select/poll:while true { select/poll(streams[]) for i in streams[] { if i has data read / write until unavailable }}Epoll:while true { active_streams[] = epoll_wait(epollfd) for i in active_streams[] { read /write complete }}
3) epoll 包含 ET 和 LT两种模式。LT模式是默认的。
LT模式和select/poll一致, 判断FD是否readable/writeable。只要FD可读或可写,即触发事件
ET模式, 只有FD变化时,才触发事件。故数据要一次读/写完才行。
PS : select /poll 可用于阻塞/非阻塞IO
epoll : LT模式和 select/poll一致, 但ET模式只能用于非阻塞IO
相关资料:
http://yaocoder.blog.51cto.com/2668309/888374
http://blog.csdn.net/eroswang/article/details/4481521
- select/poll/epoll事件驱动
- select/poll/epoll事件驱动
- 理解事件驱动select,poll,epoll三种模型
- select、poll、epoll的比较-select轮询+sleep,epoll异步事件驱动高效
- 【网络】select/poll/epoll事件处理图示
- select、Poll、epoll比较。
- select,poll,epoll区别
- select,poll,epoll用法
- select, poll, epoll
- select、poll、epoll
- select,poll,epoll区别
- select、poll和epoll
- socket-select ,poll ,epoll
- select poll epoll区别
- select、poll和epoll
- select, poll, epoll
- select,epoll,poll比较
- poll, select, epoll
- 每日锻炼--2
- 批处理中for循环使用的一些误区
- iOS调用系统相册、相机 显示中文标题
- [转]linux shell 获取当前正在执行脚本的绝对路径
- 11-1-(1)-存储班长信息的学生类(protected)
- select/poll/epoll事件驱动
- IE10 dropdownlist 失效的处理方法
- Ultraedit的查找对话框一直悬浮
- Ubuntu10.0.4配置tftp
- Ubuntu 关闭系统服务详解
- Android ViewPager使用详解
- Linux流量控制
- scanf(),printf()和gets(),puts()在输入输出字符串时的区别
- 数据库语句 半天就学会