这个问题在这里已经有了答案:
How do I get amount of queued data for UDP socket?
(2 个回答)
3年前关闭。
哪一个ioctl
的 FIONREAD
返回,下一个数据包的长度,还是缓冲区中所有数据的长度?
假设有一个 UDP
服务器从客户端 1 接收 2 个数据包,并在客户端 1 的数据包之后从客户端 2 接收另外 2 个数据包。
那么,ioctl
的值是多少?的 FIONREAD
,
什么是readfrom
在这种情况下返回?
客户端 1:v 两个数据包
++UDP 服务器得到 4 个数据包 <- FIONREAD?
客户端 2 : ^ 两个数据包
FIONREAD? (服务器)
最佳答案
man udp (7)状态:
FIONREAD (SIOCINQ) Gets a pointer to an integer as argument. Returns the size of the next pending datagram in the integer in bytes, or 0 when no datagram is pending. Warning: Using FIONREAD, it is impossible to distinguish the case where no datagram is pending from the case where the next pending datagram contains zero bytes of data. It is safer to use select(2), poll(2), or epoll(7) to distinguish these cases.
所以,你的问题的答案是: FIONREAD 返回下一个(第一个)待处理数据报的大小 .
关于networking - UDP(数据报)套接字的 FIONREAD 返回什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16995766/