IO multiplexing and non-blocking network programming

Source: Internet
Author: User

Source: http://www.cnblogs.com/zhuyp1015/p/3560095.html

In network programming using I/O multipexing (Network-multiplexing (that is, multiple signals share a single network channel, resulting in network large I/O), it is generally necessary to use a non-blocking network programming style to prevent the server from blocking on a file descriptor when dealing with high-volume connections. For example, a socket has a large amount of data to write, but the kernel send buffer is filled, can not be sent in one write to the data sent out, the program will block the place, causing select/poll/epoll_wait () can not handle other incoming requests at this time, Also read or accept may be blocked, such as when the client initiates connect, then immediately close the link, before the server has not called accept before the connection is closed. When a subsequent service-side accept is called to complete the three-handshake connection that is not completed in the queue at this time, accept causes the process to sleep (see the description of the UNPv1 nonblocking accept for details). Therefore I/O multiplexing generally adopt the style of non-blocking network programming.

For Read/wirte operation, if the use of non-blocking programming needs to be equipped with an application layer buffer for each connection, the read side mainly prevent one come to the data too much, write mainly prevent blocking, you can send the data is not sent to the buffer, wait until the socket can be written and then continue to send. If, at the time of the new write request, there is data in the application-level write buffer that was not previously sent, the last data that was not written to the kernel should be written to the kernel buffer to ensure that it is sent to the order.

IO multiplexing and non-blocking network programming

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.