Skip to content
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

Increment used TCPEndPoint count during incoming connection. #29553

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/transport/raw/TCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ CHIP_ERROR TCPBase::ProcessSingleMessage(const PeerAddress & peerAddress, Active
return CHIP_NO_ERROR;
}

void TCPBase::ReleaseActiveConnection(Inet::TCPEndPoint * endPoint)
{
for (size_t i = 0; i < mActiveConnectionsSize; i++)
{
if (mActiveConnections[i].mEndPoint == endPoint)
{
mActiveConnections[i].Free();
mUsedEndPointCount--;
}
}
}

CHIP_ERROR TCPBase::OnTcpReceive(Inet::TCPEndPoint * endPoint, System::PacketBufferHandle && buffer)
{
Inet::IPAddress ipAddress;
Expand Down Expand Up @@ -425,15 +437,8 @@ void TCPBase::OnConnectionClosed(Inet::TCPEndPoint * endPoint, CHIP_ERROR err)

ChipLogProgress(Inet, "Connection closed.");

for (size_t i = 0; i < tcp->mActiveConnectionsSize; i++)
{
if (tcp->mActiveConnections[i].mEndPoint == endPoint)
{
ChipLogProgress(Inet, "Freeing closed connection.");
tcp->mActiveConnections[i].Free();
tcp->mUsedEndPointCount--;
}
}
ChipLogProgress(Inet, "Freeing closed connection.");
tcp->ReleaseActiveConnection(endPoint);
}

void TCPBase::OnConnectionReceived(Inet::TCPEndPoint * listenEndPoint, Inet::TCPEndPoint * endPoint,
Expand All @@ -449,6 +454,7 @@ void TCPBase::OnConnectionReceived(Inet::TCPEndPoint * listenEndPoint, Inet::TCP
if (!tcp->mActiveConnections[i].InUse())
{
tcp->mActiveConnections[i].Init(endPoint);
tcp->mUsedEndPointCount++;
break;
}
}
Expand Down Expand Up @@ -502,15 +508,9 @@ void TCPBase::OnPeerClosed(Inet::TCPEndPoint * endPoint)
{
TCPBase * tcp = reinterpret_cast<TCPBase *>(endPoint->mAppState);

for (size_t i = 0; i < tcp->mActiveConnectionsSize; i++)
{
if (tcp->mActiveConnections[i].mEndPoint == endPoint)
{
ChipLogProgress(Inet, "Freeing connection: connection closed by peer");
tcp->mActiveConnections[i].Free();
tcp->mUsedEndPointCount--;
}
}
ChipLogProgress(Inet, "Freeing connection: connection closed by peer");

tcp->ReleaseActiveConnection(endPoint);
}

bool TCPBase::HasActiveConnections() const
Expand Down
4 changes: 4 additions & 0 deletions src/transport/raw/TCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ class DLL_EXPORT TCPBase : public Base
*/
CHIP_ERROR ProcessSingleMessage(const PeerAddress & peerAddress, ActiveConnectionState * state, uint16_t messageSize);

// Release an active connection (corresponding to the passed TCPEndPoint)
// from the pool.
void ReleaseActiveConnection(Inet::TCPEndPoint * endPoint);

// Callback handler for TCPEndPoint. TCP message receive handler.
// @see TCPEndpoint::OnDataReceivedFunct
static CHIP_ERROR OnTcpReceive(Inet::TCPEndPoint * endPoint, System::PacketBufferHandle && buffer);
Expand Down
Loading