问题描述
FIONREAD
的ioctl
返回的是下一个数据包的长度,还是缓冲区中所有数据的长度?
假设有一个 UDP
服务器从客户端 1 接收 2 个数据包,并在客户端 1 的数据包之后从客户端 2 接收另外 2 个数据包.那么,FIONREAD
的ioctl
的值是多少,在这种情况下 readfrom
返回什么?
客户端 1:v 两个数据包
++UDP 服务器得到 4 个数据包 <- FIONREAD?
客户端 2 : ^ 两个数据包
FIONREAD?(服务器)
- 客户端 1 的第一个数据包的长度
- 客户端 1 的两个数据包的长度
- 客户端1的两个包+客户端2的两个包的长度
- 客户端1的第一个数据包长度+客户端2的第一个数据包
- 其他
man udp (7) 状态:
FIONREAD (SIOCINQ)获取一个指向整数的指针作为参数.返回大小以字节为单位的整数中的下一个待处理数据报,如果没有,则为0数据报未决.警告:使用 FIONREAD,这是不可能的区分没有数据报未决的情况下一个未决数据报包含零字节的情况数据.使用 select(2)、poll(2) 或 epoll(7) 更安全区分这些情况.
因此,您的问题的答案是:FIONREAD 返回下一个(第一个)待处理数据报的大小.
Which one does ioctl
of FIONREAD
return, the next packet's length, or the length of all data in the buffer?
Suppose there is a UDP
server that receives 2 packets from a client 1 and another 2 packets from client 2 after client 1's packet.Then, what is the value of ioctl
of FIONREAD
,and what does readfrom
return in that case?
Client 1 : v two packets
++UDP Server got 4 packets <- FIONREAD?
Client 2 : ^ two packets
FIONREAD? (server)
- length of client 1's first packet
- length of client 1's two packets
- length of client 1's two packets + client 2's two packets
- length of client 1's first packet + client 2's first packet
- other
man udp (7) states:
So, the answer to your question is: FIONREAD returns the size of the next (first) pending datagram.
这篇关于UDP(数据报)套接字的 FIONREAD 返回什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!