Blocking mode
Is the default method of socket, and the most common way, that is, the function is blocked until the call is completed. Refer to the previous example.
It is possible to cause blockage: connect (), Accept (), read and write functions, select (), poll (), gethostbyname (), etc.
Non-blocking mode
When a program call may cause a blocking function, if blocking occurs, these functions returns -1 and set errno to Eagain or Ewouldblock, and the program can continue to run down. The task that may block the function is completed, and the function is called again when the function is called again. 0 indicates the end of the run.
Non-blocking mode can avoid program dead locks, but the program is required to constantly check the status of each possible blocking function, when an application uses a socket of the non-blocking mode, it needs to use a loop to not listen to whether it is a file description There are data readable (called POLLING). The application constant polling kernel checks if the I / O operation is ready. This will be a very waste of CPU resources, so it is not practical. The general non-blocking mode is commonly used with the synchronous I / O mode.
For a way to enter a non-blocking mode, see Function Description
I / O multiplex (synchronous I / O mode) Use SELECT (), Poll () and other functions to implement synchronization I / O operations for multiple sockets. It can wait at the same time waiting for multiple Socket descriptors, and any of these Socket descriptors entering read ready / write ready / error status, the select () function can return. See Function Description and Programs
Signal driver I / O
Asynchronous I / O