套接字接收队列中有多少数据包或字节? [英] How many packets or bytes are in the socket receive queue?

查看:16
本文介绍了套接字接收队列中有多少数据包或字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 SO_RCVBUF 调用 getsockopt 将返回套接字接收缓冲区的分配大小.

Calling getsockopt with SO_RCVBUF will return the allocated size of the socket receive buffer.

我很想知道在调用 recvrecvfrom 之前是否可以查询缓冲区中实际有多少数据报包(或字节)?如果有帮助,我可以接受 Linux 特定的答案.有问题的套接字是 UDP,但我怀疑它对 TCP 无关紧要.

I am curious to know if it is possible to query for how many datagram packets (or bytes) are actually in the buffer prior to calling recv or recvfrom? If it helps, I can settle for a Linux specific answer. The socket in question is UDP, but I suspect it wouldn't matter for TCP.

我问的原因只是为了测试和调试目的.我正在尝试验证我对 setsocktop(SO_RCVBUF) 的调用是否设置了足够的大小.知道接收缓冲区是否接近达到其限制将验证是否设置了足够的大小.

The reason why I ask is only for testing and debugging purposes. I'm trying to validate if my call to setsocktop(SO_RCVBUF) is setting a sufficient enough size. Knowing if the receive buffer was ever close to reaching its limit would validate if a sufficient size was set.

推荐答案

在 Windows 上,您要查找的内容可通过 ioctlsocket(FIONREAD)WSAIoCtl(FIONREAD),它们都返回完整缓冲数据的完整大小,即使在缓冲多个数据报消息时也是如此.但是,Linux 上没有等价物.有ioctl(FIONREAD),只返回下一条缓冲消息的大小.

On Windows, what you are looking for is available via ioctlsocket(FIONREAD) and WSAIoCtl(FIONREAD), which both return the full size of the complete buffered data, even when multiple datagram messages are buffered. However, there is no equivalent on Linux. There is ioctl(FIONREAD), which only returns the size of the next buffered message.

这篇关于套接字接收队列中有多少数据包或字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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