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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top