一、用户空间I/O操作的两个阶段
1、等待数据准备阶段
此阶段主要是将数据先加载至内核空间(内存缓冲区)
2、数据从内核复制到进程的阶段
此阶段主要是将数据从内核空间(内存缓冲区)复制到用户空间中进程的内存中去
二、五种网络I/O模型
1、Blocking I/O,阻塞 I/O
2、Non-blocking I/O,非阻塞 I/O
3、I/O multiplexing,多路复用 I/O
4、Asynchronous I/O,异步 I/O
5、Single driven I/O,信号驱动 I/O
三、Blocking I/O,阻塞 I/O
process blocks in call to read
(用户空间) (内核空间)
wait for data : read (system call) --> no data ready --> data ready ==> blocking
(内核空间) (用户空间)
copy data from kernel to user : copy data --> copy complete (return ok) --> process data ==> blocking
四、Non-blocking I/O
process repeatedly calls read waiting for an OK (polling)
wait for data :
(用户空间) (内核空间)
read (system call) --> no data ready
read <-- (ewouldblock) # 如果数据没有准备好,则立即返回一个error
read (system call) -->
read <-- (ewouldblock)
read (system call) --> data ready ==> non-blocking
(内核空间) (用户空间)
copy data from kernel to user : copy data --> copy complete (return ok) --> process data ==> blocking
五、I/O multiplexing
原文地址:http://blog.51cto.com/cjexd0826/2117721