Question

What happens when you attempt to recv from a socket into a buffer that isn't big enough to store an entire datagram? Will as much of the datagram that can be stored be recv'd? Will the rest be lost? Or will it be returned on a subsequent call to recv?

Is there a way to ensure that entire datagrams are read regardless of their size?

Was it helpful?

Solution

Typically, (certianly on Windows/Linux), a datagram is truncated to fit into the passed buffer and the remaining data is lost permanently.

Is there a way to ensure that entire datagrams are read regardless of their size?

Use a 64K buffer. The UDP protocol ensures that datagrams cannot be larger than that, so all datagrams succesfully received will be read completely regardless of their size.

OTHER TIPS

It depends on the platform. Systems that adhere to the Single Unix Specification (e.g., Linux) will truncate the datagram to fit and discard the remainder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top