FreeRTOS-Kernel icon indicating copy to clipboard operation
FreeRTOS-Kernel copied to clipboard

[Feature Request] add ability to discard a message from a message buffer

Open galenseitz opened this issue 3 years ago • 1 comments

If a message sender writes a message that is longer than the receiver is expecting to handle, there is no way to discard the message other than to perform a message buffer reset. Of course, a message buffer reset will discard all messages, not just the message with the problematic length. For more robust error recovery, I think it would be useful to have a way to discard a message without requiring a buffer large enough to hold whatever message may be sent.

I suggest adding a new function like xMessageBufferDiscard(MessageBufferHandle_t xMessageBuffer, TickType_t xTicksToWait ). (I'm unsure whether a timeout param is appropriate here.) Alternatively, and perhaps better, would be to allow xMessageBufferReceive to discard a message if the pvRxData parameter is NULL.

For the time being, I will probably change my sending code to prevent messages that are too long. I will also issue a message buffer reset if a too long message is received.

See the forum discussion here

galenseitz avatar Mar 02 '21 23:03 galenseitz

Ran into the same issue when I tryed to implement a message fifo. There is no way to discard old messages to make space for new ones directly, in my situation available ram is not an issue but reading and copying the message just for discarding it seems wastefull when the solution seems pretty easy like passing null in pointer or implement a new "discard" function.

FedericoSoberanes avatar Apr 07 '21 16:04 FedericoSoberanes