Refer to Http://www.cnblogs.com/Anker/p/3254269.html and network programming Volume 1 the 6th Chapter
Detailed analysis of the network IO model
Common IO models are blocking, non-blocking, Io multiplexing, and asynchronous. Illustrate these four concepts in a vivid example. I went shopping with my girlfriend at the weekend, I was hungry at noon, we were ready to go to dinner. Weekend people, eat need to queue, my girlfriend and I have the following options:
(1) My girlfriend and I after the meal, do not know when to do a good job, had to sit in the restaurant and so on, until the good, and then eat out before leaving.
My girlfriend would like to go shopping with me, but I do not know when the meal can be done, and I have to and I together in the restaurant and so on, and can not go shopping, until after eating dinner before going shopping, in the middle of waiting for the cooking time wasted. This is typical of blocking. The IO block in the network is as follows:
(2) My girlfriend is not willing to wait in vain, and want to go shopping malls, but also worried about the food good. So we stroll for a while, come back to ask the waiter meal good no, to go back and forth several times, the meal has not eaten is almost exhausted. This is non-blocking. Need constant questioning, are you ready? Network IO is non-blocking as shown in:
(3) similar to the second scheme, the restaurant installed an electronic screen to display the status of the order, so that my girlfriend and I go shopping for a while, come back without asking the waiter, directly to see the electronic screen on it. So that everyone's meal is good, all directly look at the electronic screen can be, this is the typical IO multiplexing, such as SELECT, poll, Epoll. (The advantage over the blocking model is that you can wait for multiple descriptors) as shown in the network IO specific model:
(4) The girlfriend does not want to go shopping, and the restaurant is too noisy, home a good rest. So we call takeout, make a phone call to order, and then my girlfriend and I can have a good rest at home, the food is good delivery staff to send to the home. This is the typical asynchronous, just need to make a phone call, and then can do their own things, the meal is ready to send. Linux provides an AIO library function for asynchronous implementations, but with little use. There are many open-source asynchronous IO libraries, such as Libevent, Libev, LIBUV, and so on. The asynchronous process looks like this:
4. Synchronous and asynchronous
In fact, synchronization and Asynchrony are for application-to-kernel interactions. During synchronization, the process triggers an IO operation and waits or polls to see if the IO operation is complete. After the process triggers the IO operation in the asynchronous process, it returns directly, does its own thing, IO gives the kernel to handle, and completes after the kernel notifies the process IO. Synchronous and asynchronous as shown:
5, blocking and non-blocking
Simply understood as the need to do one thing can immediately get a return response, if not immediately get back, need to wait, then blocked, otherwise it can be understood as non-blocking. The detailed differences are as follows:
IO model blocking, non-blocking, IO multiplexing, asynchronous