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/