Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a UDP sendto() block?

While using the default (blocking) behavior on an UDP socket, in which case will a call to sendto() block? I'm interested essentially in the Linux behavior.

For TCP I understand that congestion control makes the send() call blocking if the sending window is full, but what about UDP? Does it even block sometimes or just let packets getting discarded at lower layers?

like image 421
Jocelyn delalande Avatar asked Nov 12 '10 13:11

Jocelyn delalande


People also ask

Does UDP Sendto block?

The UDP Send block transmits an input data vector as a UDP packet to a remote IP network port. The remote IP port number to which the block sends the UDP packets is tunable in the generated code.

Can UDP be blocked?

All firewalls block traffic based on the port number, as well as the traffic type. There's a distinction between a Network firewall, and an endpoint (Windows, Linux,...) firewall. UDP can be blocked, by default, on many types of firewall, because it's (essentially) unsolicited network traffic.

What does Sendto return?

Return value. If no error occurs, sendto returns the total number of bytes sent, which can be less than the number indicated by len. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError. A successful WSAStartup call must occur before using this function.

Does Sendmsg block?

If there is not enough buffer space available to hold the socket data to be transmitted, and the socket is in blocking mode, sendmsg() blocks the caller until more buffer space becomes available.


2 Answers

This can happen if you filled up your socket buffer, but it is highly operating system dependent. Since UDP does not provide any guarantee your operating system can decide to do whatever it wants when your socket buffer is full: block or drop. You can try to increase SO_SNDBUF for temporary relief.

This can even depend on the fine tuning of your system, for instance it can also depend on the size of the TX ring in the driver of your network interface. There are a few discussions about this in the iperf mailing list, but you really want to discuss this with the developers of your operating system. Pay special attention to O_NONBLOCK and EAGAIN / EWOULDBLOCK.

like image 149
MarcH Avatar answered Oct 19 '22 21:10

MarcH


This may be because your operating system is attempting to perform an ARP request in order to get the hardware address of the remote host.

Basically whenever a packet goes out, the header requires the IP address of the remote host and the MAC address of the remote host (or the first gateway to reach it). 192.168.1.34 and AB:32:24:64:F3:21.

Your "block" behavior could be that ARP is working.

I've heard in older versions of Windows (2k I think), that the 1st packet would sometimes get discarded if the request is taking too long and you're sending out too much data. A service pack probably fixed that since then.

like image 32
mj_ Avatar answered Oct 19 '22 22:10

mj_