如何判断有多少数据是在一个套接字的发送缓冲区是在、缓冲区、有多少、如何判断

2023-09-03 17:17:23 作者:倔强诗人

我可以告诉有多少数据是在插座的接收缓冲区通过调用 Socket.IOControl(的IOControl code.DataToRead,空,outValue);

I can tell how much data is in a Socket's receive buffer by calling Socket.IOControl(IOControlCode.DataToRead, null, outValue);

有一种等效告诉多少数据是在一个套接字的发送缓冲区?

Is there an equivalent to tell how much data is in a Socket's send buffer?

我需要在带宽和时延限制的网络发送尽可能多的UDP数据包的可能,我遇到的情况是我四溢的发送缓冲区,所以我需要实现某种形式的限制的。

I need to send as many UDP packets as possible over a bandwidth and latency-constrained network, and I am running into a situation where I am overflowing the send buffer, and so I need to implement some form of throttling.

推荐答案

UDP套接字不具有发送缓冲区。在 SO_SNDBUF 的UDP套接字选项的意思是,你可以发送数据包的大小限制。内核通常不会有网卡每一个数据包队列,而​​是结合了所有的协议,而且也没有用户空间API查询它的大小。 IP层,然后是硬件,可以静静地丢弃数据包。 TCP知道如何处理这一说法,UDP没有。所以,除非.NET或任何其他微软的奇迹有这样的缓冲在用户层的库,你的运气了。

UDP socket does not have a send buffer. The meaning of the SO_SNDBUF socket option for UDP is the limit on the size of the datagram you can send. The kernel usually does have a packet queue per NIC, but that is combined for all protocols, and there's no user-land API to query its size. IP layer, and then the hardware, can drop packets silently. TCP knows how to deal with that, UDP doesn't. So unless .Net or whatever other Microsoft miracle has such buffering in user-land libraries, you are out of luck.

的追索权是接收器,以通知有关丢弃的数据包的发送者,要求重发,回落到TCP等,这也意味着有某种序列从发送者。

The recourse is for receivers to signal the sender about dropped packets, request resends, fall back to TCP, etc. This also implies having some sort of sequencing from the sender.

希望这有助于。