I. Getting Started with I/O basics
Earlier versions prior to java1.4, Java's support for I/O was imperfect, and developers faced some great challenges and difficulties in developing high-performance I/O programs, the main issues being as follows.
1, useless data buffer, I/O performance problems;
2. There is no channel concept in C or C + +, only input and output streams;
3, synchronous blocking type I/O communication (BIO), usually causes the communication thread to be blocked for a long time;
4, support character set is limited, hardware portability is not good.
Ii. Introduction to the Linux network I/O model
The Linux kernel says that all external devices are treated as a file, and that reading and writing to a file invokes the kernel-supplied system commands, returning a file descriptor (FD, filename descriptor).
and read and write to a socket will also have a corresponding descriptor, called SOCKETFD (Socket descriptor), the descriptor is a number, it points to a structure in the kernel (file path, data area and other properties).
UNIX provides 5 I/O models based on UNIX network programming for the classification of I/O models.
1. Blocking IO Model: By default, all file operations are blocked. Call Recvfrom in process space, whose system call knows when the packet arrives and is copied to the buffer of the application process or if an error occurs.
During this period, the process is blocked for the entire period of time from call Recvfrom to its return, so it is called a blocking I/O model.
2, non-blocking IO Model: Recvfrom from the application layer to the kernel, if the buffer does not have data, it will return a ewouldblock error, generally the non-blocking IO model Polling check this state,
See if the kernel has data coming.
Introduction to the Linux network I/O model