TCP 如何对其数据进行分段
How TCP fragment its data
我们都知道TCP是一种流式传输协议
与 UDP 不同,UDP 保证整个客户端消息将作为单个数据报传送到服务器(我们谈论的是传输层,因此目前避免使用 MTU),TCP 可以将一个数据报分段 "message" (传递给 send
函数的数据)分成几个较小的数据包,因此我们必须使用我们自己的定界符作为消息的边界。
问题是——TCP 如何选择应该将哪些数据分段以及按多大分段?它使用任何通用/标准方法吗?
TCP 使用一个名为 Maximum Segment Size:
的参数
The maximum segment size (MSS) is a parameter of the options field of the TCP header that specifies the largest amount of data, specified in bytes, that a computer or communications device can receive in a single TCP segment. It does not count the TCP header or the IP header. The IP datagram containing a TCP segment may be self-contained within a single packet, or it may be reconstructed from several fragmented pieces; either way, the MSS limit applies to the total amount of data contained in the final, reconstructed TCP segment.
The default TCP Maximum Segment Size is 536. Where a host wishes to set the maximum segment size to a value other than the default, the maximum segment size is specified as a TCP option, initially in the TCP SYN packet during the TCP handshake. The value cannot be changed after the connection is established.
如果启用 path MTU discovery,MSS 将设置为减去 TCP headers 大小。
On Linux TCP_MAXSEG
套接字选项控制参数:
if this option is set before connection establishment, it also changes the MSS value announced to the other end in the initial packet. Values greater than the (eventual) interface MTU have no effect. TCP will also impose its minimum and maximum bounds over the value provided.
我们都知道TCP是一种流式传输协议
与 UDP 不同,UDP 保证整个客户端消息将作为单个数据报传送到服务器(我们谈论的是传输层,因此目前避免使用 MTU),TCP 可以将一个数据报分段 "message" (传递给 send
函数的数据)分成几个较小的数据包,因此我们必须使用我们自己的定界符作为消息的边界。
问题是——TCP 如何选择应该将哪些数据分段以及按多大分段?它使用任何通用/标准方法吗?
TCP 使用一个名为 Maximum Segment Size:
的参数The maximum segment size (MSS) is a parameter of the options field of the TCP header that specifies the largest amount of data, specified in bytes, that a computer or communications device can receive in a single TCP segment. It does not count the TCP header or the IP header. The IP datagram containing a TCP segment may be self-contained within a single packet, or it may be reconstructed from several fragmented pieces; either way, the MSS limit applies to the total amount of data contained in the final, reconstructed TCP segment.
The default TCP Maximum Segment Size is 536. Where a host wishes to set the maximum segment size to a value other than the default, the maximum segment size is specified as a TCP option, initially in the TCP SYN packet during the TCP handshake. The value cannot be changed after the connection is established.
如果启用 path MTU discovery,MSS 将设置为减去 TCP headers 大小。
On Linux TCP_MAXSEG
套接字选项控制参数:
if this option is set before connection establishment, it also changes the MSS value announced to the other end in the initial packet. Values greater than the (eventual) interface MTU have no effect. TCP will also impose its minimum and maximum bounds over the value provided.