发送缓冲区空插槽的Linux呢? [英] Send buffer empty of Socket in Linux?

查看:173
本文介绍了发送缓冲区空插槽的Linux呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来检查一个TCP连接的发送缓冲区完全是空的?
我还没有发现任何东西到现在为止,只是要确保连接没有被我的服务器关闭,同时还有被传输到某个客户的数据。

Is there a way to check if the send buffer of an TCP Connection is completely empty? I haven't found anything until now and just want to make sure a connection is not closed by my server while there are still data being transmitted to a certain client.

我使用轮询来检查,如果我能够发送非阻塞套接字上的数据。但是,我不是能够找出如果一切缓冲区已发送,我是谁?

I'm using poll to check if I'm able to send data on a non-blocking socket. But by that I'm not able to find out if EVERYTHING has been sent in buffer, am I?

推荐答案

在Linux,你可以查询套接字的发送队列的ioctl(SD,SIOCOUTQ,&安培;字节)。参见男人的ioctl 了解详情。

In Linux, you can query a socket's send queue with ioctl(sd, SIOCOUTQ, &bytes). See man ioctl for details.

的信息不是在这个意义上完全可靠,这是可能的,该数据已经由远程主机接收,因为直到接收到ACK缓冲器不能排空。你可能不应该使用它来添加在TCP之上的流量控制的另一个层次。

The information is not completely reliable in the sense that it is possible that the data has been received by the remote host, since the buffer cannot be emptied until an ACK is received. You probably should not use it to add another level of flow-control on top of TCP.

如果远程主机实际上关闭连接(或半关闭它),那么插座变得不可写,而不管有多少数据可能已经在缓冲器中。您可以通过编写0字节到插座检测这种情况。

If the remote host actually closes the connection (or half-closes it), then the socket become unwriteable, regardless of how much data might have been in the buffer. You can detect this condition by writing 0 bytes to the socket.

越是困难的(而且往往更容易)的条件是远程主机不可达变得由于网络问题或者是因为它崩溃。在这种情况下,数据将在发送缓冲区堆放,但也有可能发生,因为远程主机的接收缓冲器满(可能是因为该过程读缓冲器没有足够的资源来处理其输入)。在网络路由问题的情况下,你可能会得到一个路由器的通知(ICMP差错),这应使插座不可写;不幸的是,有许多网络错误刚刚产生黑洞。

The more difficult (and often more likely) condition is the remote host becoming unreachable, because of network issues or because it crashes. In that case, data will pile up in the send buffer, but that can also happen because the remote host's receive buffer is full (perhaps because the process reading the buffer doesn't have enough resources to process its input). In the case of network routing issues, you might get a router notification (an ICMP error), which should make the socket unwritable; unfortunately, there are many network errors which just result in black holes.

这篇关于发送缓冲区空插槽的Linux呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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