如何判断Socket的发送缓冲区中有多少数据 [英] How to tell how much data is in a Socket's send buffer

查看:73
本文介绍了如何判断Socket的发送缓冲区中有多少数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过调用 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套接字没有发送缓冲区.UDP的 SO_SNDBUF 套接字选项的含义是对您可以发送的数据报的大小的限制.内核通常在每个NIC上都有一个数据包队列,但是对于所有协议来说,它都是组合在一起的,并且没有用户级API可以查询其大小.IP层,然后是硬件,可以静默丢弃数据包.TCP知道如何处理,而UDP则不知道.因此,除非.Net或任何其他Microsoft奇迹在用户土地库中具有这种缓冲功能,否则您将不走运.

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.

希望这会有所帮助.

这篇关于如何判断Socket的发送缓冲区中有多少数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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