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

A getsockopt call using SO_RCVBUF returns the allocated socket receive buffer size.

I am wondering if it is possible to query how many packets of datagrams (or bytes) are actually in the buffer before recv or recvfrom called? If this helps, I can agree on a specific Linux answer. This socket is UDP, but I suspect it does not matter for TCP.

The reason I ask is for testing and debugging only. I am trying to check if my call to setocktop (SO_RCVBUF) is of sufficient size. Knowing whether the receive buffer has ever been close to reaching its limit, it will check if a sufficient size has been set.

+4
source share
3 answers

On Windows, what you are looking for is available through ioctlsocket(FIONREAD) and WSAIoCtl(FIONREAD) , which return the full size of the filled buffered data, even if multiple datagram messages are buffered. However, there is no equivalent on Linux. There is ioctl(FIONREAD) that returns only the size of the next buffered message.

+2
source

use SIOCINQ ioctl () on the socket to find out the number of bytes in the queue.

Similarly there SIOCOUTQ to request a send buffer.

+2
source

A sufficient size for the socket receive buffer is specified by the bandwidth delay product for the link. Bandwidth c. Bytes / second time delay in seconds = buffer size in bytes. The idea is to advertise a TCP window large enough for the sender to "fill in the channel." You can calculate this in advance: you do not need to configure it at runtime. Sizes up to 64k are good.

0
source

Source: https://habr.com/ru/post/1479616/


All Articles