Linux網絡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
Linux網絡I/O模型