UDP(数据报)套接字的FIONREAD返回什么?

min*_*avg 5 networking udp ioctl datagram

哪一个做ioctlFIONREAD回报,下一个数据包的长度,或缓冲区中的所有数据的长度?

假设UDP服务器在客户端1的数据包之后接收来自客户端1的2个数据包和来自客户端2的另外2个数据包.那么,什么是价值ioctlFIONREAD,又是什么readfrom在这种情况下返回?

客户端1:v两个数据包

++ UDP Server有4个包< - FIONREAD?

客户端2:^两个数据包

FIONREAD?(服务器)

  1. 客户端1的第一个数据包的长度
  2. 客户端1的两个数据包的长度
  3. 客户端1的两个数据包+客户端2的两个数据包的长度
  4. 客户端1的第一个数据包+客户端2的第一个数据包的长度
  5. 其他

Kol*_*nya 5

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.
Run Code Online (Sandbox Code Playgroud)

因此,您的问题的答案是:FIONREAD 返回下一个(第一个)待处理数据报的大小

  • @jinoh67 我刚刚检查过:在我的 Debian 7 上,`FIONREAD` 返回数据报中包含的数据大小(数据报消息大小)。 (3认同)