tcp PUSH 标志的理解

The PSH Flag

To understand the function of the PSH flag, we first need to understand how TCP buffers data. TCP operates at layer four of the OSI model; it presents to upper layers a simple socket which can be read from and written to, masking the complexities of packet-based communications. To allow applications to read from and write to this socket at any time, buffers are implemented on both sides of a TCP connection in both directions.

The diagram below shows how data is buffered by the sender before sending, and by the receiver upon reception.

TCP_buffers.png

Buffers allow for more efficient transfer of data when sending more than one maximum segment size (MSS) worth of data (for example, transferring a large file). However, large buffers do more harm than good when dealing with real-time applications which require that data be transmitted as quickly as possible. Consider what would happen to a Telnet session, for instance, if TCP waited until there was enough data to fill a packet before it would send one: You would have to type over a thousand characters before the first packet would make it to the remote device. Not very useful.

This is where the PSH flag comes in. The socket that TCP makes available at the session level can be written to by the application with the option of "pushing" data out immediately, rather than waiting for additional data to enter the buffer. When this happens, the PSH flag in the outgoing TCP packet is set to 1 (on). Upon receiving a packet with the PSH flag set, the other side of the connection knows to immediately forward the segment up to the application. To summarize, TCP's push capability accomplishes two things:

  • The sending application informs TCP that data should be sent immediately.
  • The PSH flag in the TCP header informs the receiving host that the data should be pushed up to the receiving application immediately.


发送端 : TCP将数据包置上PUSH标志时,表示这个数据应该被立即发送,而不要等待额外的数据。

        接收端 : 接收端接受到带有PUSH标志的数据时,应该接接受缓存中收到的所有数据(包含当前带PUSH标示的数据包)应该立即提交到应用层。

        当前没有API通知TCP哪些数据需要被设置PUSH标示,完全由TCP自行判断决定。

         TCP是如何决策哪些数据需要被标示PUSH呢?

         TCP依据当前将要被发送的包是不是发送缓存中最后一个未被发送的包,如果是那么这个包将被标志PUSH,所以我们经常发现在文件的传输开始或末尾一般都会有带PUSH标志的数据包,尤其FIN包。

         有书上说设置PUSH标志条件是:由于发送该数据会清空发送缓存时包会被置上PUSH标记,试想如果某个数据的发送会引起发送缓存的清空,那么如果有数据丢失时还能够被恢复吗?

         为什么SYN 和 纯 ACK 不带PUSH标示,因为SYN 和纯 ACK 发送时不入队列。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值