Consider 100 bytes sent across a socket. With a TCP socket, if I call recv()
with a length of 50, I get the first 50 bytes, and if I call it again, I get the second 50 bytes. With a UDP socket, if I call recvfrom()
with a length of 50, I get the first 50 bytes, but then have no way of retrieving the second 50 — subsequent calls to recvfrom()
block until the next datagram is received.
Does this mean that, if I want to receive an entire UDP datagram, regardless of size, I have to allocate a 64k buffer (the maximum allowed by UDP)? If I connect()
my UDP socket, does this change the behavior? Or does a protocol operating over UDP generally entail a known maximum packet size that should be used for a buffer?
MSG_TRUNC
does not seem to be defined as an input flag on FreeBSD (freebsd.org/cgi/man.cgi?query=recv&sektion=2) – Turnbull