Dealing with sendto failure for UDP socket

udp

If sendto fails according to the manpage

"On success, these calls return the number of characters sent. On error, -1 is returned, and errno is set appropriately."

I know that with TCP that is definately the case and you should really attempt to send the remaining data as pointed out in Beej's guide to network programming.

However, partially sending a UDP packet makes no sense to me, and this comment seems to imply it.

If the message is too long to pass atomically through the underlying protocol, the error EMSGSIZE is returned, and the message
is not transmitted.

Can someone confirm for me that if I call sendto (or send) with a UDP packet that if it actually doesn't fit in the outbound buffer then I'll get -1 returned with errno set to EMSGSIZE and no partial send as with a stream (TCP) socket?

Best Answer

There is no hidden meaning, the function just returns the count of bytes sent. It is a standard pattern for Unix APIs. Datagrams are all or nothing delivery, receipt is more complicated if the network caused fragmentation to occur but generally the stack hides all the details and presents each complete packet as it is reconstructed.

Related Topic