How many packets or bytes are in the socket receive queue?

后端 未结 3 1590
灰色年华
灰色年华 2021-01-03 02:22

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

I am curious to know if it is possible to

相关标签:
3条回答
  • 2021-01-03 02:36

    use the SIOCINQ ioctl() on the socket to learn the amount of queued incoming bytes.

    Similarly there's SIOCOUTQ for querying the send buffer.

    0 讨论(0)
  • 2021-01-03 02:48

    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.

    0 讨论(0)
  • 2021-01-03 02:50

    The sufficient size for the socket receive buffer is given by the bandwidth-delay product for the link. Bandwidth in. Bytes/second times delay in seconds = buffer size in bytes. The idea is to advertise a TCP window large enough that the sender can 'fill the pipe'. You can calculate that in advance: you don't need to tune it at runtime. Sizes towards 64k are good.

    0 讨论(0)
提交回复
热议问题