Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

sockets

udp

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?

like image 399
che Avatar asked Feb 14 '12 14:02

che


People also ask

What happens when UDP socket buffer is full?

Once the socket buffer is full, new packets arriving is dropped.

What is buffer size in UDP?

The default send buffer size for UDP sockets is 65535 bytes. The default receive buffer size for UDP sockets is 2147483647 bytes.

How do UDP sockets work?

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.

Do UDP sockets listen?

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).


1 Answers

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.

like image 52
Seth Noble Avatar answered Oct 02 '22 09:10

Seth Noble