4-day OS installed... Haha, a lot of GAINS.
Remember Master Steven S.
Best references:
1. Master from the Internet.
2. Linux man command: Man 7 signal, MAN 7 socket.
3. UNP V1 Chapter 1.
Article 1: Overview
Signal-driven Io, not asynchronous Io.
Signal-driven I/O refers to the process that notifies the kernel in advance so that when a socketfd has an events event, the kernel uses a signal to notify the relevant process.
Asynchronous Io refers to the process that executes an IO System Call (read/write) to notify the kernel to start an IO operation, and immediately returns to the process after the kernel starts the IO operation. Io operations are the service routines in the kernel. POSIX provides true asynchronous Io through the aio_xxx function (see man 7 AIO ).
Related signals defined in Linux 2.6.35:
# Definesigpollsigio/* pollable event occurred (System V ).*/
# Definesigio29/* I/O now possible (4.2 BSD ).*/
Article 2: System Signal-driven I/O.
System V asynchronous I/O
Apue Description: In System V, asynchronous I/O is part of the streams
System and works only with streams devices and streams pipes. The system
V asynchronous I/O signal isSigpoll. To enable asynchronous I/O for a streams device, we have to callIOCTLWith a second argument (request)I _setsig.
In System V, asynchronous Io is part of the streams mechanism, and she can only work on stream devices and stream channels. The asynchronous Io signal of System V is sigpoll. We can use I _setsig as the second parameter to call IOCTL to enable asynchronous Io on a device. Since Linux has abandoned the streams mechanism, we will not discuss it any more. Haha.
Article 3: BSD signal drives Io.
BSD asynchronous I/O
Apue Description: asynchronous I/O in BSD-derived systems is a combination of two signals:SigioAndSigurg.
The former is the general asynchronous I/O signal, and the latter is
Used only to handle y the process that out-of-band data has arrived on
Network connection.
The asynchronous Io mechanism based on the BSD system is implemented through the combination of sigio and sigurg signals. Sigio is used for general asynchronous Io, and sigurg (urgent) is only used to remind (ipvy) that there is out-of-band data arriving on the network connection of the process. What is out-of-band data is a byte of emergency data, it is used to tell the peer that an emergency occurs on our machine, for example, to crash.
(0) Enable the sigio signal-driven I/O function on the descriptorOnly three steps are required. You do not need to use the polling mechanism to consume CPU to receive data:
1. Call signal or sigaction to create a signal processing function for the signal sigio.
2. Set the owner of the set of interfaces. Call the fcntl f_setown command to set the process or process group that receives the sigio signal on the set interface.
3. Enable the signal-driven I/O on the set interface. Use the f_setfl command of fcntl to set o_async on the set interface.
(0.1) Note:
1. The fioasynx function of IOCTL can also implement step 1.
2. Referenced by fctl and IOCTL
The descriptor can only be a terminal or network socket.
Example:
Signal (sigio, & input_handler );
Fcntl (stdin_fileno, f_setown, getpid ());
Oflags = fcntl (stdin_fileno, f_getfl );
Fcntl (stdin_fileno, f_setfl, oflags | fasync );
(1) Enable the sigurg signal-driven I/O function on the descriptor. Only two steps are required.
1. Call signal or sigaction to create a signal processing function for the signal sigurg.
2. Set the owner of the set of interfaces. Call the fcntl f_setown command to set the process or group that receives the sigurg signal on the set interface.
(1.1) Note: The referenced descriptor can only be a socket descriptor that supports Network Connections of out-of-band data.
Article 4: Linux signal-driven I/O
Linux supports BSD signal-driven I/O.
(0) sigio signal on the UDP interface.
Sigio is the most suitable for UDP. The sigio on UDP interfaces is only generated in the following two types of events:
1. Data arrives at the set of interfaces.
2. When a UDP interface is connected, an asynchronous error occurs.
(1) sigio signal on TCP set Interface.
Sigio is almost useless on TCP because there are too many events that generate such signals. Steven s pointed out that we should consider using sigio only for the "Listen (adjective) tcpsocket" (descriptor), because the only condition for generating sigio for the "Listen tcpsocket" is that the new connection is complete.