UNIX Network programming: TCP output and UDP output

Source: Internet
Author: User

TCP Output

Each TCP socket has a send buffer, and we can use the SO_SNDBUF socket option to change the size of the buffer. When a process calls write, the kernel copies all data from the application's buffer (either the application's buffer is larger than the socket's send buffer, or there are other data in the socket's send buffer), and the application process is put into sleep. This assumes that the socket is blocked, that he is the usual default setting and that the default key is not returned from the write system call.

Until all data in the application process buffer is copied to the socket send buffer. Therefore, a successful return from a write call that writes a TCP socket simply means that we can reuse the original application process buffer, and does not indicate that the TCP or application process on the end has received the data.

The TCP at this end extracts the data in the socket send buffer and sends it to the End-to-end TCP, which is based on all the rules of TCP data transfer. The End-to-end TCP must acknowledge the data received, along with the constant arrival of the ACK from the end, where TCP can then discard the acknowledged data from the socket send buffer. TCP must keep a copy of the sent data until it is acknowledged to the end.

UDP output

Here I use the dotted box to show the socket send buffer because it does not exist in the actual line. Any UDP socket has a send buffer, and we can use the SO_SNDBUF socket option to change the size of the buffer. However, it is only the maximum size of a UDP datagram that can be written to this socket. If

An application process writes a datagram that is larger than the socket send buffer size, and the kernel returns a emsgsize error for that process. Since UDP is unreliable, it does not have to save a copy of the data for the application process, so there is no need for a true send buffer. (When the data for the application process is passed down along the protocol stack, it is usually copied into a kernel buffer in a format, but when the data is sent, the copy is discarded by the data link layer).

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/unix/

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.