-
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
Miscellaneous src/inet cleanup #10450
Conversation
#### Problem Working toward project-chip#7715 Virtualize System and Inet interfaces #### Change overview - Convert some `enum` to `enum class`, and use `BitFlags` for flag sets. - Rename some class members with `m` preifx for consistency within `src/inet`. - Revise `IPAddress` construction. - Fix outdated `IPAddress` documentation. - Convert file-local functions from `static` to anonymous `namespace`. - Revise `IPEndPointBasis` to reduce duplication and remove dead code. - Remove unused flags argument from `SendTo()` and `SendMsg()`. - Replace various `sockaddr` unions with `SockAddr`. - Remove some `exit: return` and use `ReturnError…` more. - Move some comments from definition (.cpp) to declaration (.h). - Use `ObjectLifeCycle` for `InetLayer`. - Make some `TCPEndPoint` members `private` with `TCPTest` for tests. #### Testing CI; no changes to functionality intended.
@@ -90,7 +90,11 @@ CHIP_ERROR AsyncDNSResolverSockets::Shutdown() | |||
|
|||
AsyncMutexLock(); | |||
|
|||
mInet->State = InetLayer::kState_ShutdownInProgress; | |||
if (mInet->mLayerState.GetState() != ObjectLifeCycle::State::ShuttingDown) |
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.
Is the (Async)DNSResolver used/needed at all beyond tests? Or we're keeping it just in case?
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 honestly don't know. If someone can tell me definitively that AsyncDNSResolver
in particular is not used, I'll be very happy to get rid of it, since it's the only thing using threads internal to the SDK, and therefore an obstacle to simplification (cf #7725).
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 believe CHIP should only use mDNS and we have either platform or minmdns for those , nothing in inet.
Lets delete it. If I am wrong we can always add it back.
src/lib/support/ObjectLifeCycle.h
Outdated
} | ||
return false; | ||
} | ||
bool Initializing() { return Transition<State::Uninitialized, State::Initializing>(); } |
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.
nit: not sure if it's just me, but imho state.Initializing()
looks like a getter (is it in "Initializing" state). state.SetInitializing()
would be less ambiguous.
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.
OK. I'll rename them all in some consistent way.
@@ -185,7 +185,7 @@ struct DiscoveredNodeData | |||
for (int j = 0; j < numIPs; j++) | |||
{ | |||
#if CHIP_DETAIL_LOGGING | |||
char buf[Inet::kMaxIPAddressStringLength]; | |||
char buf[Inet::IPAddress::kMaxStringLength]; |
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.
Why are the lines above:
char addrBuffer[Inet::IPAddress::kMaxStringLength + 1];
mAddress.ToString(addrBuffer);
and here it's not +1. Why?
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.
Presumably one author didn't check whether kMaxStringLength
includes the terminating NUL (it does), since it isn't documented at the declaration (it will be).
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 stopped at the beginning of IPEndPointBasis.cpp. I just don't have a block of time of sufficient size to review something like this carefully... Might have been better as multiple smaller PRs.
resolver.mNumAddrs = 0; | ||
resolver.mDNSOptions = options; | ||
resolver.mAddrArray = addrArray; | ||
resolver.AppState = appState; |
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.
Why not mAppState here?
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.
It belongs to System::Object
, which I didn't want to add to this PR.
src/inet/DNSResolver.cpp
Outdated
// when the request completes. | ||
// | ||
// To ensure the right thing happens, we NULL the OnComplete pointer here, which signals the | ||
// To ensure the right thing happens, we nullptr the mOnComplete pointer here, which signals the |
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.
// To ensure the right thing happens, we nullptr the mOnComplete pointer here, which signals the | |
// To ensure the right thing happens, we null out the mOnComplete pointer here, which signals the |
"nullptr" is not a verb....
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.
Fixed and checked for other instances.
src/inet/DNSResolver.cpp
Outdated
@@ -186,7 +188,7 @@ void DNSResolver::HandleResolveComplete() | |||
* This method is called by LwIP network stack on success, failure, or timeout | |||
* of a DNS request. | |||
* | |||
* @param[in] name A pointer to a NULL-terminated C string | |||
* @param[in] name A pointer to a nullptr-terminated C string |
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.
No, it's not nullptr-terminated. It's terminated by '\0'
, presumably....
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.
Ditto
kUnused = 0, ///< Used to indicate that the DNSResolver object is not used. | ||
kActive = 2, ///< Used to indicate that a DNS resolution is being performed on the DNSResolver object. | ||
kComplete = 3, ///< Used to indicate that the DNS resolution on the DNSResolver object is complete. | ||
kCanceled = 4, ///< Used to indicate that the DNS resolution on the DNSResolver has been canceled. |
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.
kUnused = 0, ///< Used to indicate that the DNSResolver object is not used. | |
kActive = 2, ///< Used to indicate that a DNS resolution is being performed on the DNSResolver object. | |
kComplete = 3, ///< Used to indicate that the DNS resolution on the DNSResolver object is complete. | |
kCanceled = 4, ///< Used to indicate that the DNS resolution on the DNSResolver has been canceled. | |
Unused = 0, ///< Used to indicate that the DNSResolver object is not used. | |
Active = 2, ///< Used to indicate that a DNS resolution is being performed on the DNSResolver object. | |
Complete = 3, ///< Used to indicate that the DNS resolution on the DNSResolver object is complete. | |
Canceled = 4, ///< Used to indicate that the DNS resolution on the DNSResolver has been canceled. |
That "k" is just noise for enum class values....
kUnknown = 0, | ||
kRaw = 1, | ||
kUDP = 2, | ||
kUCP = 3, | ||
kTCP = 4 |
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.
Why this addition of "k"? We don't generally do that for enum classes, as far as I can tell, nor should we.
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.
That got requested in a previous review. Although I wouldn't choose it personally, existing code uses the k
prefix about 2/3 of the time in enum class
. https://gist.github.com/kpschoedel/dc99300e71e9292d95c0c26471101397
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.
We should come up with some clear guidelines for this. I've now seen people changing it to "no-k" and back to "with-k" in a tug-of-war, which is just wasting everyone's time. @woody-apple @andy31415
Again, my personal preference is to drop the k
; I've generally seen it appear as a result of mass-conversions to enum class that kept it because it was there for the non-enum-class version....
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 am on the use k
side of the fence. The logic being that I would like to trivially see when constants are used in the code. If I have:
class Foo {
public:
constexpr int kBar = 1;
}
enum class Baz {
kVal = 1;
}
then Foo::kBar
and Baz::kVal
seem trivially visible as constants regardless where they come from. Otherwise having Baz::Val
and Foo::kBar
seems inconsitent and switching everything to drop k would make Foo access constants as just Bar
which seems wrong.
kUnknown = 0, ///< Not used. | ||
kIPv4 = 1, ///< Internet protocol version 4. | ||
kIPv6 = 2, ///< Internet protocol version 6. | ||
kAny = 3 ///< The unspecified internet address (independent of protocol version). |
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.
Again, would be better without the "k" prefix, which is a holdover from non-scoped enums.
kTransient = 0x01, | ||
|
||
/** The multicast address is (1) based on a network prefix. */ | ||
kIPv6MulticastFlag_Prefix = 0x02 | ||
} IPv6MulticastFlag; | ||
kPrefix = 0x02 |
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.
And here, better without "k".
I'll see whether I can split off parts without introducing too much sequential dependency. |
#### Problem `Inet::IPAddress` has some redundancies and outdated comments. #### Change overview - Convert `IPAddress::From…()` functions that are semantically constructors into constructors. - Replace several identical `union`s with `IPAddress::SockAddr`. - Fix outdated documentation regarding IPv4-in-IPv6. - Fix a use of `IPAddress::kMaxStringLength` (from project-chip#10450 review). #### Testing CI; no changes to functionality intended.
#### Problem `Inet::IPAddress` has some redundancies and outdated comments. #### Change overview - Convert `IPAddress::From…()` functions that are semantically constructors into constructors. - Replace several identical `union`s with `IPAddress::SockAddr`. - Fix outdated documentation regarding IPv4-in-IPv6. - Fix a use of `IPAddress::kMaxStringLength` (from project-chip#10450 review). #### Testing CI; no changes to functionality intended.
* Revisions to Inet::IPAddress #### Problem `Inet::IPAddress` has some redundancies and outdated comments. #### Change overview - Convert `IPAddress::From…()` functions that are semantically constructors into constructors. - Replace several identical `union`s with `IPAddress::SockAddr`. - Fix outdated documentation regarding IPv4-in-IPv6. - Fix a use of `IPAddress::kMaxStringLength` (from #10450 review). #### Testing CI; no changes to functionality intended. * review
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Closed because most of this has now moved to other PRs. |
Problem
Working toward #7715 Virtualize System and Inet interfaces
Change overview
enum
toenum class
, and useBitFlags
for flag sets.m
preifx for consistency withinsrc/inet
.IPAddress
construction.IPAddress
documentation.static
to anonymousnamespace
.IPEndPointBasis
to reduce duplication and remove dead code.SendTo()
andSendMsg()
.sockaddr
unions withSockAddr
.exit: return
and useReturnError…
more.ObjectLifeCycle
forInetLayer
.TCPEndPoint
membersprivate
withTCPTest
for tests.Testing
CI; no changes to functionality intended.