如何获得UDP套接字的排队数据量? [英] How do I get amount of queued data for UDP socket?

查看:212
本文介绍了如何获得UDP套接字的排队数据量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要查看我在处理传入数据方面做得如何,我想测量TCP和UDP套接字上的队列长度.

To see how well I'm doing in processing incoming data, I'd like to measure the queue length at my TCP and UDP sockets.

我知道我可以通过SO_RCVBUF套接字选项获取队列大小,并且ioctl(<sockfd>, SIOCINQ, &<some_int>)告诉我有关TCP套接字的信息.但是对于UDP,SIOCINQ/FIONREAD ioctl仅返回下一个未决数据报的大小.有没有一种方法可以获取UDP的队列大小,而不必解析/proc/net/udp之类的系统表?

I know that I can get the queue size via SO_RCVBUF socket option, and that ioctl(<sockfd>, SIOCINQ, &<some_int>) tells me the information for TCP sockets. But for UDP the SIOCINQ/FIONREAD ioctl returns only the size of next pending datagram. Is there a way how to get queue size for UDP, without having to parse system tables such as /proc/net/udp?

推荐答案

如ldx所述,ioctl或getsockopt不支持它. 在我看来,SIOCINQ的当前实现旨在确定读取整个等待缓冲区需要多少缓冲区(但是我想它并没有那么大用,因为它可以在读取到实际缓冲区之间进行切换阅读).

As ldx mentioned, it is not supported through ioctl or getsockopt. It seems to me that the current implementation of SIOCINQ was aimed to determine how much buffer is needed to read the entire waiting buffer (but I guess it is not so useful for that, as it can change between the read of it to the actual buffer read).

尽管有许多其他遥测技术,但通过此类系统调用均不受支持,我想正常的生产使用中并没有真正的需求.

There are many other telemetries which are not supported though such system calls, I guess there is no real need in normal production usage.

您可以通过"netstat -su"检查丢失/错误,或者,如果您只想监视计算机状态,则可以使用SNMP(udpInErrors)更好.

You can check the drops/errors through "netstat -su" , or better using SNMP (udpInErrors) if you just want to monitor the machine state.

顺便说一句:您始终可以选择入侵内核代码并添加此值(或其他值).

BTW: You always have the option to hack in the Kernel code and add this value (or others).

这篇关于如何获得UDP套接字的排队数据量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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