Article Directory
1. blocking IO model
This is the simplest I / O model, the general performance of processes or threads waiting for some condition, if the condition is not satisfied, then wait forever.
Until the kernel has finished copying the data reported, the application process will exit the blocked state.
This model is time consuming for low concurrency, aged less demanding situations.
2. The non-blocking IO model
We're waiting, can do something else, and by way of polling, from time to time to ask the kernel data is not ready.
If a poll that data is ready, then copy the data to the user space.
3. The drive signal IO model
If the kernel can automatically, after we finished copying the data reported to the notification of the application of it?
This is the signal to drive IO.
Application process, receive a signal to the kernel specified signal handler SIGIO
, the handler automatically.
So how do we deal with more than a few io
do? We can lower a model monitoring a plurality of descriptors.
4. IO multiplexing pattern
IO by multiplexing a plurality of descriptors may be monitored, once a descriptor ready (ready generally read or write-ready), the program can be notified accordingly read and write operations.
select()
Registration will listen to all good IO
.
- If all the data needed to monitor the IO are not ready,
select()
the calling process will block; - Description descriptor is ready to return the number of symbols is ready;
- No description ready within the timeout return 0;
- Return -1 on failure.
int select(
int maxfd,
fd_set *rdset,
fd_set *wrest,
fd_set *exset,
struct timeval *timeout);
Note that the IO
reuse model is not non-blocking, because the signal handler is not registered with the kernel.
5. Asynchronous IO model
In front of the four models are synchronized, because the data copy is synchronized, through recvfrom
a data copying operation.
The signal driver model, data preparation phase is considered to be asynchronous, data copy operations are synchronized.
To asynchronously, you must specify additional tasks to the kernel.
Initiates a user process aio_read()
after the operation, passing the kernel descriptor buffer pointer, the buffer size; kernel receives aio_read
after, will return immediately, and then waits for the kernel starts data preparation.
After the data is ready to directly copy the data to the user space, save recvfrom()
, and then this notification process IO
has been completed.
Asynchronous model is clearly the most easy, and consequently do not have control of.