TCP — 在客户端关闭连接之前发送的数据包的传递

TCP — delivery of packets sent before client closes connection

假设客户端打开到服务器的 tcp 连接。

假设客户端发送 100 个数据包。

其中 10 个到达服务器并被应用程序选中。

其中 50 个已到达服务器但尚未被应用程序接收

40 还在客户端 套接字缓冲区,因为服务器接收 window 已满。

假设现在客户端关闭了连接。

问题 —

  1. 应用程序在被告知连接已关闭之前是否收到了 50 个数据包?
  2. 客户端内核在发送FIN数据包之前是否先将剩余的40个数据包发送给客户端?
  3. 现在更复杂的是,如果丢包很多,剩下的40个包和FIN怎么办。它会关闭它吗?

Does application get the 50 packets before it is told that the connection is closed?

确实如此。

Does the client kernel send the remaining 40 packets first to client before it sends the FIN packet?

确实如此。

Now to complicate matters, if there is lot of packet loss, what happens to the remaining 40 packets and the FIN. Does it close it?

内核将继续尝试发送未完成的数据。事实上,你 closed 套接字不会改变任何事情,除非你改变套接字选项来改变这种行为。