send() function behavior when link goes down in a TCP connection

試著忘記壹切 提交于 2019-12-04 18:04:40

This is normal and expected behaviour.

when we know the remote side will not be able to receive this data

Well, maybe you know, because you are the one you pulled the cable and you aren't about to plug it back in again, but the computer (or, in particular, the TCP stack) doesn't know.

The first reason why it doesn't know the data won't make it is that by the time the send() call completes, the data haven't gone on the wire yet: they've only been queued in a buffer.

The second reason why it doesn't know the data won't make it is that it can't (at least at first) tell the difference between a link that has simply dropped a packet and the packet may get through when it tries to retransmit it, versus a cable that has been well and truly cut. Even for a cable cut, TCP will keep retransmitting for a while, hoping that either (1) the link comes back, or (2) routers will converge on another network path that works.

Even if you could know instantly when a link is down (although you can in some very specific cases, you can't in general, you must wait for a timeout to figure this out), you wouldn't want TCP to instantly break connections every time it happened: it would be way too fragile if TCP connections broke every time a packet was lost in the network.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!