سؤال

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