Size check for message send functions

Hello,

I am just wondering why xQueueSend does not perform a size check for a message by taking a size_t variable and checking that size against the reception queue size.

If someone sends a message which is smaller than the reception queue, there is no error which indicates that, like for example in linux with the EMSGSIZE error:
MSG Size check

So one would just receive a “truncated” message. (if my testing was performed correctly)

I think this size check would be a nice feature. If I want to implement this size checking myself, I would need to keep a map which maps the reception queue to its maximum size (meaning I also have to cache that size). Is there a specific reason this was never implemented?

Kind Regards and thank you in advance!

Hi,

xQueueSend doesn’t take a size parameter because the size is defined when the queue is created with xQueueCreate.

If you’re sending data to a queue it is expected that you know the size of the elements to send.

Yes, we built a generic MessageQueue class around the FreeRTOS calls which just caches the size used for xQueueCreate. But now if someone uses this MessageQueue class to send a message to a queue which is too large for the reception queue, I would like some kind of debug or warning output or error code saying that the message is too large for the reception queue and currently, there is no indication for that.

I guess the only way is to implement the above mentioned mapping to perform this check myself before sending the message.

Remember Queues are FIXED sized queue, all messages in a given queue are the same size, and really really, should generally be always the same type of struct, or possible the fixed sized array of chars. It is a fundamental error to send a wrong sized message, so in one sense a ‘generic’ wrapper where the sender doesn’t know what queue they are sending to (or at least a group of queues that all handle the SAME type of messages) is broken and ill advised.

I have a C++ wrapper for the Queue that is a template, and FORCES the parameter to always be the right type structure, so you don’t have such an issue.

There ARE also StreamBuffers and MessageBuffers designed for variable sized messages.

1 Like