Learn TCP blocking/non-blocking

Source: Internet
Author: User
Tags socket blocking

Whether in blocking or non-blocking mode, the Data Length returned by send (...) only indicates the Data Length copied to the protocol stack buffer. It is not the actual data volume sent or the data volume received by the other party. For Recv (...), only the received data is obtained from the buffer zone. The sender first copies the data to the protocol stack buffer. TCP will ensure that the data in the buffer is sent to the receiver's buffer. As for how data can be reliably delivered, the underlying protocol has already done a lot of work for us, so upper-layer applications do not have to consider it.

Blocking and non-blocking are not much different from the underlying protocol (I think so now). In blocking mode, the data to be sent will be copied to the buffer during sending, if the Buffer Zone capacity cannot accommodate the data to be sent, wait for the data in the buffer zone to be sent until the buffer zone can accommodate the data and then return the method. In non-blocking mode, if the Buffer Zone capacity cannot accommodate the data to be sent, it first fills up the buffer zone and directly returns the Data Length filled in the buffer zone.


Some good articles:

Research on Non-blocking TCP for socket programming in Linux
Recv, Seng, read, and write return values in case of socket blocking or non-blocking
Differences between socket blocking and non-blocking


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.