Skip to content

Commit 1256631

Browse files
kpschoedelpull[bot]
authored andcommitted
Inet: Split UDPEndPoint and TCPEndPoint (#11681)
#### Problem This is a step toward #7715 _Virtualize System and Inet interfaces_. #### Change overview - The per-implementation subclasses (formerly `#if` sections) of `EndPointBase` didn't actually depend on `EndPointBase` at all, so they are split off into `EndPointState${IMPL}` classes, separately inherited by the leaf classes. - `UDPEndPoint` and `TCPEndPoint` are split into base classes and per-implementation subclasses. Transitionally, the implementation classes remain the main files, and are instantiated using a single concrete name by `#if`. #### Testing CI; no changes to functionality.
1 parent 0beaf14 commit 1256631

12 files changed

+463
-286
lines changed

src/inet/BUILD.gn

+1-3
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ buildconfig_header("inet_buildconfig") {
4949
defines +=
5050
[ "INET_PLATFORM_CONFIG_INCLUDE=${chip_inet_platform_config_include}" ]
5151
}
52-
53-
defines += [ "CHIP_INET_END_POINT_IMPL_CONFIG_FILE=<inet/EndPointBasisImpl${chip_system_config_inet}.h>" ]
5452
}
5553

5654
source_set("inet_config_header") {
@@ -69,7 +67,7 @@ static_library("inet") {
6967

7068
sources = [
7169
"EndPointBasis.h",
72-
"EndPointBasisImpl${chip_system_config_inet}.h",
70+
"EndPointState${chip_system_config_inet}.h",
7371
"IANAConstants.h",
7472
"IPAddress-StringFuncts.cpp",
7573
"IPAddress.cpp",

src/inet/EndPointBasis.h

-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class DLL_EXPORT EndPointBase
3939
{
4040
public:
4141
EndPointBase(InetLayer & aInetLayer, void * aAppState = nullptr) : mAppState(aAppState), mInetLayer(aInetLayer) {}
42-
virtual ~EndPointBase() = default;
4342

4443
/**
4544
* Returns a reference to the Inet layer object that owns this basis object.
@@ -54,9 +53,3 @@ class DLL_EXPORT EndPointBase
5453

5554
} // namespace Inet
5655
} // namespace chip
57-
58-
#ifdef CHIP_INET_END_POINT_IMPL_CONFIG_FILE
59-
#include CHIP_INET_END_POINT_IMPL_CONFIG_FILE
60-
#else // CHIP_INET_END_POINT_IMPL_CONFIG_FILE
61-
#include <inet/EndPointBasisImplSockets.h>
62-
#endif // CHIP_INET_END_POINT_IMPL_CONFIG_FILE

src/inet/EndPointBasisImplLwIP.h renamed to src/inet/EndPointStateLwIP.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
/**
20-
* LwIP implementation of EndPointBase.
20+
* Shared state for LwIP implementations of TCPEndPoint and UDPEndPoint.
2121
*/
2222

2323
#pragma once
@@ -32,12 +32,10 @@ struct tcp_pcb;
3232
namespace chip {
3333
namespace Inet {
3434

35-
class DLL_EXPORT EndPointImplLwIP : public EndPointBase
35+
class DLL_EXPORT EndPointStateLwIP
3636
{
3737
protected:
38-
EndPointImplLwIP(InetLayer & inetLayer, void * appState = nullptr) :
39-
EndPointBase(inetLayer, appState), mLwIPEndPointType(LwIPEndPointType::Unknown)
40-
{}
38+
EndPointStateLwIP() : mLwIPEndPointType(LwIPEndPointType::Unknown) {}
4139

4240
/** Encapsulated LwIP protocol control block */
4341
union
@@ -59,7 +57,5 @@ class DLL_EXPORT EndPointImplLwIP : public EndPointBase
5957
} mLwIPEndPointType;
6058
};
6159

62-
using EndPointBasis = EndPointImplLwIP;
63-
6460
} // namespace Inet
6561
} // namespace chip

src/inet/EndPointBasisImplNetworkFramework.h renamed to src/inet/EndPointStateNetworkFramework.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
/**
20-
* Network Framework implementation of EndPointBase.
20+
* Shared state for Network Framework implementations of TCPEndPoint and UDPEndPoint.
2121
*/
2222

2323
#pragma once
@@ -31,16 +31,14 @@
3131
namespace chip {
3232
namespace Inet {
3333

34-
class DLL_EXPORT EndPointImplNetworkFramework : public EndPointBase
34+
class DLL_EXPORT EndPointStateNetworkFramework
3535
{
3636
protected:
37-
EndPointImplNetworkFramework(InetLayer & inetLayer, void * appState = nullptr) : EndPointBase(inetLayer, appState) {}
37+
EndPointStateNetworkFramework() {}
3838

3939
nw_parameters_t mParameters;
4040
IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
4141
};
4242

43-
using EndPointBasis = EndPointImplNetworkFramework;
44-
4543
} // namespace Inet
4644
} // namespace chip

src/inet/EndPointBasisImplSockets.h renamed to src/inet/EndPointStateSockets.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
/**
20-
* Sockets implementation of EndPointBase.
20+
* Shared state for socket implementations of TCPEndPoint and UDPEndPoint.
2121
*/
2222

2323
#pragma once
@@ -30,20 +30,16 @@
3030
namespace chip {
3131
namespace Inet {
3232

33-
class DLL_EXPORT EndPointImplSockets : public EndPointBase
33+
class DLL_EXPORT EndPointStateSockets
3434
{
3535
protected:
36-
EndPointImplSockets(InetLayer & inetLayer, void * appState = nullptr) :
37-
EndPointBase(inetLayer, appState), mSocket(kInvalidSocketFd)
38-
{}
36+
EndPointStateSockets() : mSocket(kInvalidSocketFd) {}
3937

4038
static constexpr int kInvalidSocketFd = -1;
4139
int mSocket; /**< Encapsulated socket descriptor. */
4240
IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
4341
System::SocketWatchToken mWatch; /**< Socket event watcher */
4442
};
4543

46-
using EndPointBasis = EndPointImplSockets;
47-
4844
} // namespace Inet
4945
} // namespace chip

src/inet/InetLayer.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ CHIP_ERROR InetLayer::Shutdown()
150150

151151
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
152152
// Abort all TCP endpoints owned by this instance.
153-
TCPEndPoint::sPool.ForEachActiveObject([&](TCPEndPoint * lEndPoint) {
153+
TCPEndPointImpl::sPool.ForEachActiveObject([&](TCPEndPoint * lEndPoint) {
154154
if ((lEndPoint != nullptr) && &lEndPoint->Layer() == this)
155155
{
156156
lEndPoint->Abort();
@@ -161,7 +161,7 @@ CHIP_ERROR InetLayer::Shutdown()
161161

162162
#if INET_CONFIG_ENABLE_UDP_ENDPOINT
163163
// Close all UDP endpoints owned by this instance.
164-
UDPEndPoint::sPool.ForEachActiveObject([&](UDPEndPoint * lEndPoint) {
164+
UDPEndPointImpl::sPool.ForEachActiveObject([&](UDPEndPoint * lEndPoint) {
165165
if ((lEndPoint != nullptr) && &lEndPoint->Layer() == this)
166166
{
167167
lEndPoint->Close();
@@ -206,7 +206,7 @@ bool InetLayer::IsIdleTimerRunning()
206206
bool timerRunning = false;
207207

208208
// See if there are any TCP connections with the idle timer check in use.
209-
TCPEndPoint::sPool.ForEachActiveObject([&](TCPEndPoint * lEndPoint) {
209+
TCPEndPointImpl::sPool.ForEachActiveObject([&](TCPEndPoint * lEndPoint) {
210210
if ((lEndPoint != nullptr) && (lEndPoint->mIdleTimeout != 0))
211211
{
212212
timerRunning = true;
@@ -245,7 +245,7 @@ CHIP_ERROR InetLayer::NewTCPEndPoint(TCPEndPoint ** retEndPoint)
245245

246246
VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
247247

248-
*retEndPoint = TCPEndPoint::sPool.CreateObject(*this);
248+
*retEndPoint = TCPEndPointImpl::sPool.CreateObject(*this);
249249
if (*retEndPoint == nullptr)
250250
{
251251
ChipLogError(Inet, "%s endpoint pool FULL", "TCP");
@@ -284,7 +284,7 @@ CHIP_ERROR InetLayer::NewUDPEndPoint(UDPEndPoint ** retEndPoint)
284284

285285
VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);
286286

287-
*retEndPoint = UDPEndPoint::sPool.CreateObject(*this);
287+
*retEndPoint = UDPEndPointImpl::sPool.CreateObject(*this);
288288
if (*retEndPoint == nullptr)
289289
{
290290
ChipLogError(Inet, "%s endpoint pool FULL", "UDP");
@@ -303,7 +303,7 @@ void InetLayer::HandleTCPInactivityTimer(chip::System::Layer * aSystemLayer, voi
303303
InetLayer & lInetLayer = *reinterpret_cast<InetLayer *>(aAppState);
304304
bool lTimerRequired = lInetLayer.IsIdleTimerRunning();
305305

306-
TCPEndPoint::sPool.ForEachActiveObject([&](TCPEndPoint * lEndPoint) {
306+
TCPEndPointImpl::sPool.ForEachActiveObject([&](TCPEndPoint * lEndPoint) {
307307
if (&lEndPoint->Layer() != &lInetLayer)
308308
return true;
309309
if (!lEndPoint->IsConnected())

0 commit comments

Comments
 (0)