-
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
Final PacketBufferHandle cleanup. #4364
Final PacketBufferHandle cleanup. #4364
Conversation
#### Problem Code should use `PacketBufferHandle` rather than `PacketBuffer *`. A few references and transitional interfaces remain. #### Summary of Changes - Promote `Release_ForNow()` to `UnsafeRelease()`. It's impractical to remove entirely since it's used conjunction with platform event queues. - Rename `GetLwIPpbuf()` to `UnsafeGetLwIPpbuf()` for consistency. - Privatize `AddRef()` and raw `SetDataLength()`. - Remove `AddToEnd_ForNow()`. - Remove various `using PacketBuffer` declarations. - Remove obsolete comments about `PacketBuffer *` ownership, and rephrase comments mentioning the `PacketBuffer` class by name. Fixes project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
* The ref-qualifier `&&` requires the caller to use `std::move` to emphasize that ownership is | ||
* moved out of this handle. | ||
*/ | ||
CHECK_RETURN_VALUE PacketBuffer * UnsafeRelease() && |
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.
This is currently only used to reference a PacketBuffer in events. In the case of CHIPoBLEWriteReceived
it's as a PacketBuffer*
, but in ChipSystemLayerEvent
it's as a uintptr_t
. An option would be to only Release as an opaque uintptr_t
to discourage any use of packet buffers through a PacketBuffer*
; it might then also be possible to make PacketBuffer
itself a private type inside PacketBufferHandle
.
src/system/SystemPacketBuffer.h
Outdated
@@ -592,9 +575,25 @@ class DLL_EXPORT PacketBufferHandle | |||
* | |||
* @note This should be used ONLY by low-level code interfacing with LwIP. | |||
*/ | |||
struct pbuf * GetLwIPpbuf() { return static_cast<struct pbuf *>(mBuffer); } | |||
struct pbuf * UnsafeGetLwIPpbuf() { return static_cast<struct pbuf *>(mBuffer); } |
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.
can we protect this method and make a list of friend classes allowed to call it? is that worth the work?
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.
Yes, the only uses are in Inet:…EndPoint, so that shouldn't be difficult. (The same isn't true of UnsafeRelease(), unfortunately, since it's mostly used under src/platform/, so hiding it would be a problem for out-of-tree platforms.)
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.
Done with a task-specific subclass to set a pattern for disjoint exposures. No increase in code size.
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.
nice work
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.
Nicely done!
src/inet/RawEndPoint.cpp
Outdated
#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5 | ||
if (PCB_ISIPV6(mRaw)) | ||
{ | ||
ip6_addr_t ipv6Addr = addr.ToIPv6(); | ||
|
||
lwipErr = raw_sendto_ip6(mRaw, msg.GetLwIPpbuf(), &ipv6Addr); | ||
lwipErr = raw_sendto_ip6(mRaw, msg.UnsafeGetLwIPpbuf(), &ipv6Addr); |
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.
Needs to use LwIPPacketBufferView
src/inet/RawEndPoint.cpp
Outdated
} | ||
#if INET_CONFIG_ENABLE_IPV4 | ||
else | ||
{ | ||
ip4_addr_t ipv4Addr = addr.ToIPv4(); | ||
|
||
lwipErr = raw_sendto(mRaw, msg.GetLwIPpbuf(), &ipv4Addr); | ||
lwipErr = raw_sendto(mRaw, msg.UnsafeGetLwIPpbuf(), &ipv4Addr); |
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.
Needs to use LwIPPacketBufferView
src/inet/UDPEndPoint.cpp
Outdated
@@ -600,9 +598,9 @@ INET_ERROR UDPEndPoint::SendMsg(const IPPacketInfo * pktInfo, System::PacketBuff | |||
} | |||
|
|||
if (intfId != INET_NULL_INTERFACEID) | |||
lwipErr = udp_sendto_if_ip6(mUDP, msg.GetLwIPpbuf(), &lwipDestAddr, destPort, intfId); | |||
lwipErr = udp_sendto_if_ip6(mUDP, msg.UnsafeGetLwIPpbuf(), &lwipDestAddr, destPort, intfId); |
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.
Needs to use LwIPPacketBufferView
src/inet/UDPEndPoint.cpp
Outdated
else | ||
lwipErr = udp_sendto_ip6(mUDP, msg.GetLwIPpbuf(), &lwipDestAddr, destPort); | ||
lwipErr = udp_sendto_ip6(mUDP, msg.UnsafeGetLwIPpbuf(), &lwipDestAddr, destPort); |
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.
Needs to use LwIPPacketBufferView
src/inet/UDPEndPoint.cpp
Outdated
@@ -619,9 +617,9 @@ INET_ERROR UDPEndPoint::SendMsg(const IPPacketInfo * pktInfo, System::PacketBuff | |||
} | |||
|
|||
if (intfId != INET_NULL_INTERFACEID) | |||
lwipErr = udp_sendto_if(mUDP, msg.GetLwIPpbuf(), &lwipDestAddr, destPort, intfId); | |||
lwipErr = udp_sendto_if(mUDP, msg.UnsafeGetLwIPpbuf(), &lwipDestAddr, destPort, intfId); |
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.
Needs to use LwIPPacketBufferView
src/inet/UDPEndPoint.cpp
Outdated
else | ||
lwipErr = udp_sendto(mUDP, msg.GetLwIPpbuf(), &lwipDestAddr, destPort); | ||
lwipErr = udp_sendto(mUDP, msg.UnsafeGetLwIPpbuf(), &lwipDestAddr, destPort); |
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.
Needs to use LwIPPacketBufferView
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.
Done and thanks for catching that. Looks like I rushed that change and stopped when the active builds worked.
@andy31415 @saurabhst @BroderickCarlin @hawk248 @jelderton ? Need a couple more partner reviews. |
Size increase report for "esp32-example-build" from fad6d05
Full report output
|
* Final PacketBufferHandle cleanup. #### Problem Code should use `PacketBufferHandle` rather than `PacketBuffer *`. A few references and transitional interfaces remain. #### Summary of Changes - Promote `Release_ForNow()` to `UnsafeRelease()`. It's impractical to remove entirely since it's used conjunction with platform event queues. - Rename `GetLwIPpbuf()` to `UnsafeGetLwIPpbuf()` for consistency. - Privatize `AddRef()` and raw `SetDataLength()`. - Remove `AddToEnd_ForNow()`. - Remove various `using PacketBuffer` declarations. - Remove obsolete comments about `PacketBuffer *` ownership, and rephrase comments mentioning the `PacketBuffer` class by name. Fixes project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
* Final PacketBufferHandle cleanup. #### Problem Code should use `PacketBufferHandle` rather than `PacketBuffer *`. A few references and transitional interfaces remain. #### Summary of Changes - Promote `Release_ForNow()` to `UnsafeRelease()`. It's impractical to remove entirely since it's used conjunction with platform event queues. - Rename `GetLwIPpbuf()` to `UnsafeGetLwIPpbuf()` for consistency. - Privatize `AddRef()` and raw `SetDataLength()`. - Remove `AddToEnd_ForNow()`. - Remove various `using PacketBuffer` declarations. - Remove obsolete comments about `PacketBuffer *` ownership, and rephrase comments mentioning the `PacketBuffer` class by name. Fixes project-chip#2707 - Figure out a way to express PacketBuffer ownership in the type system
Problem
Code should use
PacketBufferHandle
rather thanPacketBuffer *
.A few references and transitional interfaces remain.
Summary of Changes
Release_ForNow()
toUnsafeRelease()
. It's impracticalto remove entirely since it's used conjunction with platform event
queues.
GetLwIPpbuf()
withLwIPPacketBufferView::UnsafeGetLwIPpbuf()
,restricted to specific friend classes.
AddRef()
and rawSetDataLength()
.AddToEnd_ForNow()
.using PacketBuffer
declarations.PacketBuffer *
ownership, andrephrase comments mentioning the
PacketBuffer
class by name.Fixes #2707 - Figure out a way to express PacketBuffer ownership in the type system