Add a hook function called on buffer release#1340
Conversation
This patch adds a hook function to FreeRTOS-Plus-TCP to notify the network driver whenever a buffer is released. One could use iptraceNETWORK_BUFFER_RELEASED (what I did at first) but this is not what it was designed for. A network driver allocates a buffer to store incoming frames from the network. Once a frame has been received the buffer is passed to FreeRTOS-Plus-TCP which will consume it and then probably release it or not. For a zero-copy network driver using BufferAllocation_1.c it is helpful or even necessary to get a notification once FreeRTOS-Plus-TCP releases a buffer. The notification can be used for memory management, for instance to re-allocate a new buffer to receive further frames.
htibosch
left a comment
There was a problem hiding this comment.
Hi @fxrb, thanks for this proposal.
Can you explain why the existing macro (ipconfigBUFFER_AND_DESCRIPTOR_RELEASE_HOOK) can not be used your purpose? It doesn't have any particular purpose.
If we add an application hook, I like to see a short warning: the hook will run in the IP-task context and shall not call user APIs or use blocking functions.
I like to hear more about your plans to manage the network buffers, interesting.
| } | ||
|
|
||
| #if ( ipconfigBUFFER_AND_DESCRIPTOR_RELEASE_HOOK == 1 ) | ||
| vReleaseNetworkBufferAndDescriptorHook( pxNetworkBuffer ); |
There was a problem hiding this comment.
It would be desirable to make the same change in BufferAllocation_2.c as well to keep the interfaces equal.
There is no such existing macro. My patch introduces it. |
Description
This patch adds a hook function to FreeRTOS-Plus-TCP to notify the network driver whenever a buffer is released.
One could use iptraceNETWORK_BUFFER_RELEASED (what I did at first) but this is not what it was designed for.
A network driver allocates a buffer to store incoming frames from the network. Once a frame has been received the buffer is passed to FreeRTOS-Plus-TCP which will consume it and then probably release it or not. For a zero-copy network driver using BufferAllocation_1.c it is helpful or even necessary to get a notification once FreeRTOS-Plus-TCP releases a buffer. The notification can be used for memory management, for instance to re-allocate a new buffer to receive further frames.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.