I'm just cleaning up some code we wrote a while back and noticed that for a udp socket, 0 is being treated as the connection closed.
I'm quite sure this was the result of porting the same recv loop from the equivalent tcp version. But it makes me wonder. Can recv return 0 for udp? on tcp it signals the other end has closed the connection. udp doesn't have the concept of a connection so can it return 0? and if it can, what is it's meaning?
Note: the man page in linux does not distinguish udp and tcp for a return code of zero which may be why we kept the check in the code.
It means a 0-length datagram was received. From the great UNP: