-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Begin SystemPacketBuffer.h cleanup #4096
Conversation
#### Problem Code should use `PacketBufferHandle` rather than `PacketBuffer *`. Some existing methods should be removed or made private so that code does not have unnecessary access to the raw pointer. #### Summary of Changes - Consolidated PacketBuffer and PacketBufferHeader method descriptions into the header; clarified which are in transition. - Most uses of Next(), which returns a raw pointer, only checked existence; added PacketBuffer::HasChainedBuffer() to replace these. - Removed DetachTail_ForNow(), as it has no remaining callers. - Converted TestSystemPacketBuffer to friended class, so that it can continue to use and test private methods. (Refactoring to focus on the PacketBufferHandle interface will follow.) Part of issue project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
Size increase report for "nrfconnect-example-build" from 2244db6
Full report output
|
Size increase report for "esp32-example-build" from 2244db6
Full report output
|
src/system/SystemPacketBuffer.h
Outdated
* Return the size of the allocation including the reserved and payload data spaces but not including space | ||
* allocated for the PacketBuffer structure. | ||
* | ||
* @note The allocation size is equal or greater than \c aAllocSize paramater to \c Create method). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @note The allocation size is equal or greater than \c aAllocSize paramater to \c Create method). | |
* @note The allocation size is equal to or greater than the \c aAllocSize parameter to the \c Create method). |
* @brief The caller's ownership is transferred to this. An existing owned buffer is freed. | ||
* | ||
* @note This should only be used in low-level code, e.g. to import buffers from LwIP or a similar stack. | ||
*/ | ||
void Adopt(PacketBuffer * buffer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of purging this, even internal to PacketBufferHandle
, because I've more than once made errors due to the asymmetry: it Free
s the old mBuffer
but does not AddRef
the new one.
src/system/SystemPacketBuffer.h
Outdated
* Return the size of the allocation including the reserved and payload data spaces but not including space | ||
* allocated for the PacketBuffer structure. | ||
* | ||
* @note The allocation size is equal or to greater than \c aAllocSize parameter to the \c Create method). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @note The allocation size is equal or to greater than \c aAllocSize parameter to the \c Create method). | |
* @note The allocation size is equal to or greater than the \c aAllocSize parameter to the \c Create method). |
Problem
Code should use
PacketBufferHandle
rather thanPacketBuffer *
.Some existing methods should be removed or made private so that code
does not have unnecessary access to the raw pointer.
Summary of Changes
PacketBuffer
andPacketBufferHeader
method descriptionsinto the header, and clarified which are in transition.
PacketBuffer
getters inline.Next()
, which returns a raw pointer, only checkedfor existence; added
HasChainedBuffer()
to replace these.DetachTail_ForNow()
, as it has no remaining callers.TestSystemPacketBuffer.cpp
to use a friend class, so thatit can continue to use and test private methods. (Refactoring to focus
on the
PacketBufferHandle
interface will follow.)Part of issue #2707 - Figure out a way to express PacketBuffer ownership in the type system