Socket Working Mode

Source: Internet
Author: User

Blocking Mode

It is the default socket method and the most common method, that is, function blocking until the call is completed. See the previous example.

Possible blocking functions include connect (), accept (), read and write functions, select (), poll (), and gethostbyname.

 

Non-Blocking Mode

If a program calls a function that may cause blocking, the function returns-1 and sets errno to EAGAIN or EWOULDBLOCK. The program can continue to run down. If the task corresponding to a function that may be blocked is completed, 0 is returned when the function is called again, indicating that the operation has ended.

Non-blocking mode can avoid program deadlocks, but the program needs to constantly check the status of each function that may be blocked. When an application uses a non-blocking mode socket, it uses a loop to continuously test whether a file descriptor has data readable (called polling ). Applications constantly polling the kernel to check whether I/O operations are ready. This operation is a waste of CPU resources, so it cannot be applied in reality. Generally, the non-blocking mode is used together with the synchronous I/O mode.

For more information about how to enter the non-blocking mode, see function description.

 

I/O multiplexing (synchronous I/O mode)

Use functions such as select () and poll () to implement synchronous I/O operations on multiple sockets. It can wait for multiple socket descriptors at the same time, and any of these socket descriptors enters the read-ready/Write-ready/error state, the select () function can return. See function descriptions and programs

 

Signal-driven I/O

 

 

Asynchronous I/O


Address: http://www.aka.org.cn/Lectures/002/Lecture-2.1.8/Lecture-2.1.8/index.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.