Under Unix, there are 5 I/O models:
- blocking I/O
- nonblocking I/O
- I/O multiplexing
- signal driven I/O
- asynchronous I/O
- POSIX aio_
Two phase for input operation:
graph LR; S(Data Source) K(Kernel Space) A(Application Space) S --1 Wait for data to be ready--> K K --2 Move data from kernel to application--> A
1. Blocking I/O Model
the most prevalentI/O model
By default, all sockets are
recvfromis implemented different on different platfrom.
- system call on BSD
- function on System V
- As to
system call, there is normally a
switchbetween userspace and kernel.
- With Blocking I/O, system call return when:
- data copied to application space
- interrupted by signal (most common)
blockedwhen calling these kind of system call.
2. NonBlocking I/O Model
- when set a socket to be nonblocking
- Instead block the process, system call would return error
[ ] blocking I/O is described detailed within Chapter 16
call system call
on nonblocking file descriptor
3. I/O Multiplexing Model
- block on these other system calls
in the actualI/O system call
wait for more than onedescripter to be ready
selectrequires two system call
- Another similar solution:
- multithreading with blocking I/O
4. Signal-Driven I/O Model
graph LR; A(Application) K(Kernal) A --1 Register signal handler--> K K --2. Generate SIGIO when data ready--> A A --3. Get data via system call--> K
- Application do not block while waiting for data
5. Asynchronous I/O Model
- Defined by POSIX specification
- reconcile different
- Similar with signal-driven I/O model, but the difference is:
- With asynchronous I/O, kernel notify application when data is ready
- With Signal-Driven I/O, after kernel's notification, application would have to fetch data via system call
- The first phase is the same for the first four I/O models.
- The first four I/O models are the same at the second phase.
- Asynchronous I/O models handle the first and the second phase.
- Referenc <[PEARSON] UNIX Network Programming (Volume 1 Third Edition)>