The Linux kernel sees all external devices as a single file, and read and write to a file invokes the system commands provided by the kernel.
, returns a file descriptor (FD, filename descriptor). and read and write to a socket will have a corresponding descriptor, become SOCKETFD
(socket descriptor), a descriptor is a number that points to a struct in the kernel (file path, data area, and so on).
Based on the classification of the I/O model by UNIX programming, UNIX provides 5 I/O models, namely:
(1) Blocking I/O model: The most commonly used is the blocking I/O model, under the default conditions all file operations are blocked!!
(2) Non-blocking I/O model
(3) I/O multiplexing model
(4) Signal-driven I/O model
(5) asynchronous I/O model
For most programmers, there is no need to know the bottom-level details of network programming, and all we need is a concept that, for the operating system, the underlying
is to support asynchronous I/O communication, Java NiO Core class library multiplexer is based on epoll multiplexing technology implementation!!
During I/O programming, multi-threaded or I/O multiplexing techniques can be used to process multiple client access requests. / o
Multiplexing allows multiple I/O blocking to be multiplexed to the same select block, allowing the system to handle more than one single thread
Client requests. Compared with the traditional multi-threaded/multi-process model, the greatest advantage of I/O multiplexing is that the system overhead is small and the system does not need to create
New additional processes or threads, and do not need to maintain the operation of these threads and processes, reducing the maintenance workload of the system and saving system resources
, the main application scenarios for I/O multiplexing:
(1) The server needs to handle multiple sockets in the listening state or multiple connection states;
(2) The server needs to handle multiple network protocol sockets
Linux currently supports I/O multiplexing system calls with SELECT, Pselect, poll, Epoll
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Netty Learning (i) a brief introduction to the network IO model under--linux