第6章 I/O复用 select和poll函数
由于pdf中文字不可复制,就截图居多
其他参考:
https://segmentfault.com/a/1190000003063859#articleHeader16
http://www.cnblogs.com/Anker/archive/2013/08/17/3263780.html
I/O模式



多线程中使用阻塞式I/O


select



看下面这个例子


函数返回值表示跨所有描述符集的已就绪的总位数

简单例子

- 被监控的fds需要从用户空间拷贝到内核空间
- 被监控的fds集合中,只要有一个有数据可读,整个socket集合就会被遍历一次调用sk的poll函数收集可读事件
-
select支持的文件描述符数量太小了,默认是1024
poll

epoll
- epoll事先通过epoll_ctl()来注册一 个文件描述符,一旦基于某个文件描述符就绪时,内核会采用类似callback的回调机制,迅速激活这个文件描述符,当进程调用epoll_wait() 时便得到通知
- IO的效率不会随着监视fd的数量的增长而下降。epoll不同于select和poll轮询的方式,而是通过每个fd定义的回调函数来实现的。只有就绪的fd才会执行回调函数。
网友评论