Skip to content

Commit

Permalink
Inet: Split UDPEndPoint and TCPEndPoint (#11681)
Browse files Browse the repository at this point in the history
#### 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.
  • Loading branch information
kpschoedel authored and pull[bot] committed Jan 4, 2023
1 parent 986029c commit eb31427
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 286 deletions.
4 changes: 1 addition & 3 deletions src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ buildconfig_header("inet_buildconfig") {
defines +=
[ "INET_PLATFORM_CONFIG_INCLUDE=${chip_inet_platform_config_include}" ]
}

defines += [ "CHIP_INET_END_POINT_IMPL_CONFIG_FILE=<inet/EndPointBasisImpl${chip_system_config_inet}.h>" ]
}

source_set("inet_config_header") {
Expand All @@ -69,7 +67,7 @@ static_library("inet") {

sources = [
"EndPointBasis.h",
"EndPointBasisImpl${chip_system_config_inet}.h",
"EndPointState${chip_system_config_inet}.h",
"IANAConstants.h",
"IPAddress-StringFuncts.cpp",
"IPAddress.cpp",
Expand Down
7 changes: 0 additions & 7 deletions src/inet/EndPointBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class DLL_EXPORT EndPointBase
{
public:
EndPointBase(InetLayer & aInetLayer, void * aAppState = nullptr) : mAppState(aAppState), mInetLayer(aInetLayer) {}
virtual ~EndPointBase() = default;

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

} // namespace Inet
} // namespace chip

#ifdef CHIP_INET_END_POINT_IMPL_CONFIG_FILE
#include CHIP_INET_END_POINT_IMPL_CONFIG_FILE
#else // CHIP_INET_END_POINT_IMPL_CONFIG_FILE
#include <inet/EndPointBasisImplSockets.h>
#endif // CHIP_INET_END_POINT_IMPL_CONFIG_FILE
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

/**
* LwIP implementation of EndPointBase.
* Shared state for LwIP implementations of TCPEndPoint and UDPEndPoint.
*/

#pragma once
Expand All @@ -32,12 +32,10 @@ struct tcp_pcb;
namespace chip {
namespace Inet {

class DLL_EXPORT EndPointImplLwIP : public EndPointBase
class DLL_EXPORT EndPointStateLwIP
{
protected:
EndPointImplLwIP(InetLayer & inetLayer, void * appState = nullptr) :
EndPointBase(inetLayer, appState), mLwIPEndPointType(LwIPEndPointType::Unknown)
{}
EndPointStateLwIP() : mLwIPEndPointType(LwIPEndPointType::Unknown) {}

/** Encapsulated LwIP protocol control block */
union
Expand All @@ -59,7 +57,5 @@ class DLL_EXPORT EndPointImplLwIP : public EndPointBase
} mLwIPEndPointType;
};

using EndPointBasis = EndPointImplLwIP;

} // namespace Inet
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

/**
* Network Framework implementation of EndPointBase.
* Shared state for Network Framework implementations of TCPEndPoint and UDPEndPoint.
*/

#pragma once
Expand All @@ -31,16 +31,14 @@
namespace chip {
namespace Inet {

class DLL_EXPORT EndPointImplNetworkFramework : public EndPointBase
class DLL_EXPORT EndPointStateNetworkFramework
{
protected:
EndPointImplNetworkFramework(InetLayer & inetLayer, void * appState = nullptr) : EndPointBase(inetLayer, appState) {}
EndPointStateNetworkFramework() {}

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

using EndPointBasis = EndPointImplNetworkFramework;

} // namespace Inet
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

/**
* Sockets implementation of EndPointBase.
* Shared state for socket implementations of TCPEndPoint and UDPEndPoint.
*/

#pragma once
Expand All @@ -30,20 +30,16 @@
namespace chip {
namespace Inet {

class DLL_EXPORT EndPointImplSockets : public EndPointBase
class DLL_EXPORT EndPointStateSockets
{
protected:
EndPointImplSockets(InetLayer & inetLayer, void * appState = nullptr) :
EndPointBase(inetLayer, appState), mSocket(kInvalidSocketFd)
{}
EndPointStateSockets() : mSocket(kInvalidSocketFd) {}

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

using EndPointBasis = EndPointImplSockets;

} // namespace Inet
} // namespace chip
12 changes: 6 additions & 6 deletions src/inet/InetLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ CHIP_ERROR InetLayer::Shutdown()

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

#if INET_CONFIG_ENABLE_UDP_ENDPOINT
// Close all UDP endpoints owned by this instance.
UDPEndPoint::sPool.ForEachActiveObject([&](UDPEndPoint * lEndPoint) {
UDPEndPointImpl::sPool.ForEachActiveObject([&](UDPEndPoint * lEndPoint) {
if ((lEndPoint != nullptr) && &lEndPoint->Layer() == this)
{
lEndPoint->Close();
Expand Down Expand Up @@ -206,7 +206,7 @@ bool InetLayer::IsIdleTimerRunning()
bool timerRunning = false;

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

VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);

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

VerifyOrReturnError(mLayerState.IsInitialized(), CHIP_ERROR_INCORRECT_STATE);

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

TCPEndPoint::sPool.ForEachActiveObject([&](TCPEndPoint * lEndPoint) {
TCPEndPointImpl::sPool.ForEachActiveObject([&](TCPEndPoint * lEndPoint) {
if (&lEndPoint->Layer() != &lInetLayer)
return true;
if (!lEndPoint->IsConnected())
Expand Down
Loading

0 comments on commit eb31427

Please sign in to comment.