2
votes

We all know that TCP is a streaming protocol.

Unlike UDP, which guarantees that the whole client message will be delivered to server as a single datagram (we're talking about transport layer, so avoid MTU at the moment), TCP can fragment one "message" (data that was passed to the send function) into several smaller packets so we have to use our own delimiters as a messages' borders.

The question is -- how TCP chooses which data should be fragmented and by which size? Is there any common / standard methods that it uses?

1
@Robᵩ So there's no common rules or standard methods of fragmentation? - FrozenHeart
None that are observable from an application program. What problem are you trying to solve? - Robᵩ
@Robᵩ That's more theoretical question than the practical one actually. It's interesting to know about such things - FrozenHeart
"... from the application sending or receiving the data ..." - better? @pjcognetta - Robᵩ
@FrozenHeart - Here is some info: en.wikipedia.org/wiki/Maximum_segment_size and particularly the book it references : Comer, Douglas E. (2006). Internetworking with TCP/IP. Vol. 1 (5/E ed.). Upper Saddle River, NJ, USA: Prentice Hall. - Robᵩ

1 Answers

2
votes

TCP uses a parameter called 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.

If path MTU discovery is enabled, MSS is set to that minus TCP headers size.

On Linux TCP_MAXSEG socket option controls the parameter:

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.