发送()函数的行为,当链路发生故障的TCP连接 [英] send() function behavior when link goes down in a TCP connection

查看:182
本文介绍了发送()函数的行为,当链路发生故障的TCP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是方案:

A< ------------------------->乙

A <-------------------------> B

我使用的A和B(基于Linux的计算机)非阻塞套接字。
A和B有一个TCP连接,突然连接它们的连接出现故障(该链接可能没有直接的联系)。
现在经过的链路down掉,当发送()函数被调用A侧一些数据发送给B,它返回成功(即它返回要发送的字节数)。

I am using non-blocking Sockets on both A and B (linux based machines). A and B have a TCP connection and suddenly the link connecting them goes down (The link may not be direct link). Now after the link is down, when send() function is called on side A to send some data to B , It returns successfully (i.e it returns the number of bytes that are to be sent).

什么是这种现象的原因,当我们知道了远程端将无法获得这些数据,当链路断开?

What is the reason for this behavior, when we know the remote side will not be able to receive this data, when the link is down?

推荐答案

这是正常的预期行为。

,当我们知道远程端将不能够接收该数据

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

好吧,也许的的知道,因为你是你拉的电缆之一,你是不是要插回了,但计算机(或,特别是TCP协议栈)不知道。

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.

第二个原因它不知道数据不会使它的是,它无法(至少在初期)告诉简直掉了包的链接和数据包之间的差异可能会通过时,它试图重新发送它,对已经很好,真正切断的电缆。即使是一个电缆剪,TCP将继续重传了一段时间,希望无论是(1)链接回来,或(2)路由器将收敛的作品另一个网络路径上。

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.

即使你可以立即知道当一个链路中断(尽管你可以在一些非常特殊的情况下,你不能在一般情况下,你必须等待超时想出解决办法),你不希望TCP来瞬间中断连接每次它发生的时间:它会太脆弱,如果TCP连接打破每一个数据包在网络中丢失时间

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.

这篇关于发送()函数的行为,当链路发生故障的TCP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆