Skip to content

Add a hook function called on buffer release#1340

Open
fxrb wants to merge 1 commit into
FreeRTOS:mainfrom
fxrb:add-buffer-release-hook
Open

Add a hook function called on buffer release#1340
fxrb wants to merge 1 commit into
FreeRTOS:mainfrom
fxrb:add-buffer-release-hook

Conversation

@fxrb

@fxrb fxrb commented May 8, 2026

Copy link
Copy Markdown
Contributor

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

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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 htibosch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be desirable to make the same change in BufferAllocation_2.c as well to keep the interfaces equal.

@fxrb

fxrb commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Can you explain why the existing macro (ipconfigBUFFER_AND_DESCRIPTOR_RELEASE_HOOK) can not be used your purpose?

There is no such existing macro. My patch introduces it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants