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

标签 networking udp datagram ioctl

这个问题在这里已经有了答案:





How do I get amount of queued data for UDP socket?

(2 个回答)


3年前关闭。




哪一个ioctlFIONREAD返回,下一个数据包的长度,还是缓冲区中所有数据的长度?

假设有一个 UDP服务器从客户端 1 接收 2 个数据包,并在客户端 1 的数据包之后从客户端 2 接收另外 2 个数据包。
那么,ioctl的值是多少?的 FIONREAD ,
什么是readfrom在这种情况下返回?

客户端 1:v 两个数据包

++UDP 服务器得到 4 个数据包 <- FIONREAD?

客户端 2 : ^ 两个数据包



FIONREAD? (服务器)

  • 客户端 1 的第一个数据包的长度
  • 客户端 1 的两个数据包的长度
  • 客户端1的两个包+客户端2的两个包的长度
  • 客户端1的第一个数据包+客户端2的第一个数据包的长度
  • 其他
  • 最佳答案

    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/

    相关文章:

    c - 原始套接字/BPF - 过滤完成一次还是多次?

    c++ - 如何在QT中接收正确的UDP数据包?

    c# - 在Unity3D中无法接收来自PLC的C#UDP消息,但在Wireshark中可见

    java - 如何通过数据报套接字发送对象

    c - 如何使用 SOCK_DGRAM 制作双向 unix 域套接字?

    c++ - 动态消息和TLV的数据序列化协议(protocol)?

    windows - 如何判断网络适配器在 Windows 上是否可移动

    networking - server.listen(port, '127.0.0.1') 无法访问容器化节点服务器

    c++ - UDP Tx 循环每次在正好 3970 个数据包时停止工作,在我 friend 的计算机上为 14386

    java - DatagramChannel 数据包监听器占用高 CPU 资源