To see how well I'm doing in processing incoming data, I'd like to measure the queue length at my TCP and UDP sockets.
I know that I can get the queue size via SO_RCVBUF
socket option, and that ioctl(<sockfd>, SIOCINQ, &<some_int>)
tells me the information for TCP sockets. But for UDP the SIOCINQ
/FIONREAD
ioctl returns only the size of next pending datagram. Is there a way how to get queue size for UDP, without having to parse system tables such as /proc/net/udp
?
Once the socket buffer is full, new packets arriving is dropped.
The default send buffer size for UDP sockets is 65535 bytes. The default receive buffer size for UDP sockets is 2147483647 bytes.
UDP is a very simple protocol. Messages, so called datagrams, are sent to other hosts on an IP network without the need to set up special transmission channels or data paths beforehand. The UDP socket only needs to be opened for communication. It listens for incoming messages and sends outgoing messages on request.
UDP is connectionless. A server can immediately listen for messages once it has a socket. We use the recvfrom system call to wait for an incoming datagram on a specific transport address (IP address and port number).
FWIW, I did some experiments to map out the behavior of FIONREAD
on different platforms.
Platforms where FIONREAD
returns all the data pending in a SOCK_DGRAM
socket:
Mac OS X, NetBSD, FreeBSD, Solaris, HP-UX, AIX, Windows
Platforms where FIONREAD
returns only the bytes for the first pending datagram:
Linux
It might also be worth noting that some implementations include headers or other overhead bytes in the count, while others only count the payload bytes. Linux appears to return the payload size, not including IP headers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With